Yoast\WP\SEO\Schema_Aggregator\User_Interface

Site_Schema_Aggregator_Route::aggregate_site_schemapublicYoast 1.0

Returns a JSON representation of a site.

Метод класса: Site_Schema_Aggregator_Route{}

Хуков нет.

Возвращает

WP_REST_Response|WP_Error. The success or failure response.

Использование

$Site_Schema_Aggregator_Route = new Site_Schema_Aggregator_Route();
$Site_Schema_Aggregator_Route->aggregate_site_schema( $request );
$request(WP_REST_Request) (обязательный)
The request object.

Код Site_Schema_Aggregator_Route::aggregate_site_schema() Yoast 27.7

public function aggregate_site_schema( WP_REST_Request $request ) {
	$post_type = $request->get_param( 'post_type' );

	if ( ! $this->post_type_helper->is_indexable( $post_type ) ) {
		return new WP_Error(
			'wpseo_post_type_not_indexable',
			\sprintf( 'The post type "%s" is excluded from search results.', $post_type ),
			[ 'status' => 404 ],
		);
	}

	$page = ( $request->get_param( 'page' ) ?? 1 );

	if ( ! $this->validate_page( (string) $page ) ) {
		return new WP_Error(
			'rest_invalid_param',
			\sprintf( 'Invalid parameter(s): %s', 'page' ),
			[ 'status' => 400 ],
		);
	}

	$per_page = $this->config->get_per_page( $post_type );

	$output = $this->cache_manager->get( $post_type, $page, $per_page );
	if ( $output === null ) {
		try {
			$output = $this->aggregate_site_schema_command_handler->handle( new Aggregate_Site_Schema_Command( $page, $per_page, $post_type ) );
			$this->cache_manager->set( $post_type, $page, $per_page, $output );

		} catch ( Exception $exception ) {
			return new WP_Error(
				'wpseo_aggregate_site_schema_error',
				$exception->getMessage(),
				(object) [],
			);
		}
	}
	$response = \rest_ensure_response( $output );

	$response->header( 'Cache-Control', 'public, max-age=300' );

	return $response;
}