PluginProbe
Gutenberg / 14.7.0
Gutenberg v14.7.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 12.6.0 All 403 releases
gutenberg / lib / compat / wordpress-6.2 / rest-api.php

rest-api.php in Gutenberg 14.7.0, at lib/compat/wordpress-6.2/rest-api.php

86 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Overrides Core's wp-includes/rest-api.php and registers the new endpoint for WP 6.2.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers the block pattern categories REST API routes.
10 */
11 function gutenberg_register_rest_block_pattern_categories() {
12 $block_patterns = new Gutenberg_REST_Block_Pattern_Categories_Controller();
13 $block_patterns->register_routes();
14 }
15 add_action( 'rest_api_init', 'gutenberg_register_rest_block_pattern_categories' );
16
17 /**
18 * Registers the block pattern directory.
19 */
20 function gutenberg_register_rest_pattern_directory() {
21 $pattern_directory_controller = new Gutenberg_REST_Pattern_Directory_Controller_6_2();
22 $pattern_directory_controller->register_routes();
23 }
24 add_action( 'rest_api_init', 'gutenberg_register_rest_pattern_directory' );
25
26 /**
27 * Add extra collection params to pattern directory requests.
28 *
29 * @param array $query_params JSON Schema-formatted collection parameters.
30 * @return array Updated parameters.
31 */
32 function gutenberg_pattern_directory_collection_params_6_2( $query_params ) {
33 $query_params['page'] = array(
34 'description' => __( 'Current page of the collection.', 'gutenberg' ),
35 'type' => 'integer',
36 'default' => 1,
37 'sanitize_callback' => 'absint',
38 'validate_callback' => 'rest_validate_request_arg',
39 'minimum' => 1,
40 );
41
42 $query_params['per_page'] = array(
43 'description' => __( 'Maximum number of items to be returned in result set.', 'gutenberg' ),
44 'type' => 'integer',
45 'default' => 100,
46 'minimum' => 1,
47 'maximum' => 100,
48 'sanitize_callback' => 'absint',
49 'validate_callback' => 'rest_validate_request_arg',
50 );
51
52 $query_params['offset'] = array(
53 'description' => __( 'Offset the result set by a specific number of items.', 'gutenberg' ),
54 'type' => 'integer',
55 );
56
57 $query_params['order'] = array(
58 'description' => __( 'Order sort attribute ascending or descending.', 'gutenberg' ),
59 'type' => 'string',
60 'default' => 'desc',
61 'enum' => array( 'asc', 'desc' ),
62 );
63
64 $query_params['orderby'] = array(
65 'description' => __( 'Sort collection by post attribute.', 'gutenberg' ),
66 'type' => 'string',
67 'default' => 'date',
68 'enum' => array(
69 'author',
70 'date',
71 'id',
72 'include',
73 'modified',
74 'parent',
75 'relevance',
76 'slug',
77 'include_slugs',
78 'title',
79 'favorite_count',
80 ),
81 );
82
83 return $query_params;
84 }
85 add_filter( 'rest_pattern_directory_collection_params', 'gutenberg_pattern_directory_collection_params_6_2' );
86