wppaste
WordPress

WP_REST_Font_Collections_Controller

Since
6.5.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php:17
Font Library Controller class.

Compatibility

WordPress
since 6.5.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 4

Every hook that fires from inside WP_REST_Font_Collections_Controller, in the order it appears in the class, grouped by the method that fires it.

Methods · 9

Source code

class WP_REST_Font_Collections_Controller extends WP_REST_Controller { 	/**	 * Constructor.	 *	 * @since 6.5.0	 */	public function __construct() {		$this->rest_base = 'font-collections';		$this->namespace = 'wp/v2';	} 	/**	 * Registers the routes for the objects of the controller.	 *	 * @since 6.5.0	 */	public function register_routes() {		register_rest_route(			$this->namespace,			'/' . $this->rest_base,			array(				array(					'methods'             => WP_REST_Server::READABLE,					'callback'            => array( $this, 'get_items' ),					'permission_callback' => array( $this, 'get_items_permissions_check' ),					'args'                => $this->get_collection_params(), 				),				'schema' => array( $this, 'get_public_item_schema' ),			)		); 		register_rest_route(			$this->namespace,			'/' . $this->rest_base . '/(?P<slug>[\/\w-]+)',			array(				array(					'methods'             => WP_REST_Server::READABLE,					'callback'            => array( $this, 'get_item' ),					'permission_callback' => array( $this, 'get_items_permissions_check' ),					'args'                => array(						'context' => $this->get_context_param( array( 'default' => 'view' ) ),					),				),				'schema' => array( $this, 'get_public_item_schema' ),			)		);	} 	/**	 * Gets the font collections available.	 *	 * @since 6.5.0	 *	 * @param WP_REST_Request $request Full details about the request.	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.	 */	public function get_items( $request ) {		$collections_all = WP_Font_Library::get_instance()->get_font_collections(); 		$page        = $request['page'];		$per_page    = $request['per_page'];		$total_items = count( $collections_all );		$max_pages   = (int) ceil( $total_items / $per_page ); 		if ( $page > $max_pages && $total_items > 0 ) {			return new WP_Error(				'rest_post_invalid_page_number',				__( 'The page number requested is larger than the number of pages available.' ),				array( 'status' => 400 )			);		} 		$collections_page = array_slice( $collections_all, ( $page - 1 ) * $per_page, $per_page ); 		$is_head_request = $request->is_method( 'HEAD' ); 		$items = array();		foreach ( $collections_page as $collection ) {

Changelog

Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.