Yoast\WP\SEO\Bulk_Editor\User_Interface
Posts_Route::get_posts
Returns a page of posts for the requested content type.
Метод класса: Posts_Route{}
Хуков нет.
Возвращает
WP_REST_Response|WP_Error. The posts, or an error when the content type is not editable.
Использование
$Posts_Route = new Posts_Route(); $Posts_Route->get_posts( $request );
- $request(WP_REST_Request) (обязательный)
- The request object.
Код Posts_Route::get_posts() Posts Route::get posts Yoast 28.9
public function get_posts( WP_REST_Request $request ) {
$content_type = $request->get_param( 'content_type' );
if ( ! $this->is_valid_content_type( $content_type ) ) {
return new WP_Error(
'rest_invalid_content_type',
'The requested content type is not editable.',
[ 'status' => 400 ],
);
}
// An empty selection (no status filter) means all statuses, never zero results.
$statuses = (array) $request->get_param( 'status' );
if ( empty( $statuses ) ) {
$statuses = Posts_Collector_Interface::STATUSES;
}
// Narrow the query to the user's own posts when they cannot edit other authors' posts. This keeps
// pagination cheap; the exact per-post edit permission is still enforced when collecting the page.
$author_id = null;
if ( ! $this->content_type_access_checker->can_edit_others( $content_type ) ) {
$author_id = $this->user_helper->get_current_user_id();
}
// The per-field scores only back the filter while SEO analysis is on globally and the content type
// shows Yoast's controls and assessments; otherwise they go stale and the filter falls back to the
// empty-field check.
$scores_enabled = $this->options_helper->get( 'keyword_analysis_active' ) === true
&& $this->post_type_helper->has_metabox( $content_type );
// The schema already coerces the items to positive integers; deduplicate on top of that.
$include = \array_values( \array_unique( \array_map( 'intval', (array) $request->get_param( 'include' ) ) ) );
$query = new Posts_Query(
$content_type,
(int) $request->get_param( 'page' ),
(int) $request->get_param( 'per_page' ),
(string) $request->get_param( 'search' ),
$statuses,
$author_id,
(array) $request->get_param( 'needs_improvement' ),
$scores_enabled,
$include,
);
// Posts the current user cannot edit are returned locked and without their SEO data; the per-post
// permission is resolved while collecting the page.
return new WP_REST_Response( $this->posts_repository->get_posts( $query )->to_array() );
}