ID ); } /** * The post, when it exists and is a kind of content Blaze manages: a * public post type shown in the REST API, other than attachments. * * @param int $id Post id. * @return \WP_Post|\WP_Error */ public static function supported( $id ) { $post = get_post( $id ); if ( ! $post || 'revision' === $post->post_type ) { return new \WP_Error( 'searchsmith_not_found', __( 'No such post.', 'searchsmith' ), array( 'status' => 404 ) ); } $type = get_post_type_object( $post->post_type ); if ( ! $type || 'attachment' === $post->post_type || ! $type->public || ! $type->show_in_rest ) { return new \WP_Error( 'searchsmith_unsupported_type', __( 'This kind of post is not managed by Blaze.', 'searchsmith' ), array( 'status' => 400 ) ); } return $post; } /** * The response for a write's result, or its refusal. * * @param array|\WP_Error $result The write's result. * @return \WP_REST_Response|\WP_Error */ public static function respond( $result ) { return is_wp_error( $result ) ? $result : rest_ensure_response( $result ); } }