Recent

REST_APIclass

REST_API

REST API class.

Namespace: WebberZone\Contextual_Related_Posts\Frontend
Since: 3.5.0
Source: includes/frontend/class-rest-api.php line 20 Extends: WP_REST_Controller

Methods

__construct()

Main constructor.

Since: 3.5.0
Line: 36

public function __construct(  );

register_routes()

Initialises the Contextual Related Posts REST API adding the necessary routes.

Since: 3.5.0
Line: 46

public function register_routes(  );

permissions_check()

Check if a given request has access to get items

Line: 76

public function permissions_check( $request ): \WP_Error|bool;
Type Name Description
\WP_REST_Request $request Full data about the request.

Returns: \WP_Error|bool

get_items()

Get related posts.

Since: 3.5.0
Line: 106

public function get_items( $request ): mixed|\WP_REST_Response;
Type Name Description
\WP_REST_Request $request WP Rest request.

Returns: mixed|\WP_REST_Response — Array of post objects or post IDs.

prepare_item()

Get a popular post by ID. Also includes the number of views.

Since: 3.5.0
Line: 158

public function prepare_item( $related_post, $request ): array|mixed;
Type Name Description
\WP_Post $related_post Popular Post object.
\WP_REST_Request $request WP Rest request.

Returns: array|mixed — The formatted Popular Post object.

get_item_params()

Get the arguments for fetching the related posts.

Since: 3.5.0
Line: 174

public function get_item_params(  ): array;

Returns: array — Contextual Related Posts REST API related posts arguments.

sanitize_limit()

Sanitize the REST limit, enforcing a hard maximum.

Since: 4.4.0
Line: 226

public function sanitize_limit( $value ): int;
Type Name Description
mixed $value Requested limit.

Returns: int

check_read_permission()

Checks if a post can be read.

Correctly handles posts with the inherit status.

Since: 3.5.0
Line: 296

public function check_read_permission( $post, $request = ... ): bool;
Type Name Description
\WP_Post $post Post object.
\WP_REST_Request|null $request Request context.

Returns: bool — Whether the post can be read.