LLMS_REST_Posts_Controller::handle_status_param( string $status )

Determines validity and normalizes the given status parameter.


Description Description

Heavily based on WP_REST_Posts_Controller::handle_status_param().


Top ↑

Parameters Parameters

$status

(string) (Required) Status.


Top ↑

Return Return

(string|WP_Error) Status or WP_Error if lacking the proper permission.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php

	protected function handle_status_param( $status ) {

		$post_type_object = get_post_type_object( $this->post_type );
		$post_type_name   = $post_type_object->labels->name;

		switch ( $status ) {
			case 'draft':
			case 'pending':
				break;
			case 'private':
				if ( ! current_user_can( $post_type_object->cap->publish_posts ) ) {
					// Translators: %s = The post type name.
					return llms_rest_authorization_required_error( sprintf( __( 'Sorry, you are not allowed to create private %s.', 'lifterlms' ), $post_type_name ) );
				}
				break;
			case 'publish':
			case 'future':
				if ( ! current_user_can( $post_type_object->cap->publish_posts ) ) {
					// Translators: $s = The post type name.
					return llms_rest_authorization_required_error( sprintf( __( 'Sorry, you are not allowed to publish %s.', 'lifterlms' ), $post_type_name ) );
				}
				break;
			default:
				if ( ! get_post_status_object( $status ) ) {
					$status = 'draft';
				}
				break;
		}

		return $status;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.18 Use plural post type name.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.