WP_REST_Posts_Controller::handle_status_param() protected WP 4.7.0
Determines validity and normalizes the given status parameter.
{} Это метод класса: WP_REST_Posts_Controller{}
Хуков нет.
Возвращает
Строку/WP_Error
. Post status or WP_Error if lacking the proper permission.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->handle_status_param( $post_status, $post_type );
- $post_status(строка) (обязательный)
- Post status.
- $post_type(WP_Post_Type) (обязательный)
- Post type.
Список изменений
С версии 4.7.0 | Введена. |
Код WP_REST_Posts_Controller::handle_status_param() WP REST Posts Controller::handle status param WP 5.7.1
protected function handle_status_param( $post_status, $post_type ) {
switch ( $post_status ) {
case 'draft':
case 'pending':
break;
case 'private':
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
return new WP_Error(
'rest_cannot_publish',
__( 'Sorry, you are not allowed to create private posts in this post type.' ),
array( 'status' => rest_authorization_required_code() )
);
}
break;
case 'publish':
case 'future':
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
return new WP_Error(
'rest_cannot_publish',
__( 'Sorry, you are not allowed to publish posts in this post type.' ),
array( 'status' => rest_authorization_required_code() )
);
}
break;
default:
if ( ! get_post_status_object( $post_status ) ) {
$post_status = 'draft';
}
break;
}
return $post_status;
}