PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
gutenberg / lib / class-wp-rest-icon-collections-controller-gutenberg.php

class-wp-rest-icon-collections-controller-gutenberg.php in Gutenberg trunk, at lib/class-wp-rest-icon-collections-controller-gutenberg.php

62 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * REST API: Gutenberg icon collections controller.
4 *
5 * Changes to this class should be synced to the corresponding class
6 * in WordPress core: src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php.
7 *
8 * @package gutenberg
9 * @subpackage REST_API
10 */
11
12 /**
13 * Gutenberg Icon Collections REST API Controller.
14 *
15 * @since 7.2.0
16 */
17 class WP_REST_Icon_Collections_Controller_Gutenberg extends WP_REST_Icon_Collections_Controller {
18
19 /**
20 * Retrieves all public icon collections.
21 *
22 * @param WP_REST_Request $request Full details about the request.
23 * @return WP_REST_Response Response object.
24 */
25 public function get_items( $request ) {
26 $response = array();
27 $collections = WP_Icon_Collections_Registry::get_instance()->get_all_registered();
28 foreach ( $collections as $collection ) {
29 if ( ! $collection['public'] ) {
30 continue;
31 }
32 $prepared_collection = $this->prepare_item_for_response( $collection, $request );
33 $response[] = $this->prepare_response_for_collection( $prepared_collection );
34 }
35 return rest_ensure_response( $response );
36 }
37
38 /**
39 * Retrieves a specific public icon collection.
40 *
41 * @param WP_REST_Request $request Full details about the request.
42 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
43 */
44 public function get_item( $request ) {
45 $collection = WP_Icon_Collections_Registry::get_instance()->get_registered( $request['slug'] );
46
47 if ( null !== $collection && ! $collection['public'] ) {
48 return new WP_Error(
49 'rest_icon_collection_not_found',
50 sprintf(
51 /* translators: %s: Icon collection slug. */
52 __( 'Icon collection not found: "%s".', 'gutenberg' ),
53 $request['slug']
54 ),
55 array( 'status' => 404 )
56 );
57 }
58
59 return parent::get_item( $request );
60 }
61 }
62