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.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3).

Hooks and filters fired · 2

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	 *	 * @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 ); 		$items = array();		foreach ( $collections_page as $collection ) {			$item = $this->prepare_item_for_response( $collection, $request ); 			// If there's an error loading a collection, skip it and continue loading valid collections.

Changelog

Introduced in 6.5.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

About this page

Parsed data
Generated from the wordpress-develop 6.7.10 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.