PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.4.2
Jetpack – WP Security, Backup, Speed, & Growth v12.4.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / _inc / lib / core-api / wpcom-endpoints / gutenberg-available-extensions.php
gutenberg-available-extensions.php
88 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Interact with the list of available block editor extensions (blocks, plugins)
4 * made available by the Jetpack plugin.
5 *
6 * @package automattic/jetpack
7 */
8
9 /**
10 * Gutenberg: List Available Gutenberg Extensions (Blocks and Plugins)
11 *
12 * [
13 * { # Availabilty Object. See schema for more detail.
14 * available: (boolean) Whether the extension is available
15 * unavailable_reason: (string) Reason for the extension not being available
16 * },
17 * ...
18 * ]
19 *
20 * @since 6.9
21 */
22 class WPCOM_REST_API_V2_Endpoint_Gutenberg_Available_Extensions extends WP_REST_Controller {
23 /**
24 * Constructor.
25 */
26 public function __construct() {
27 $this->namespace = 'wpcom/v2';
28 $this->rest_base = 'gutenberg';
29 $this->wpcom_is_site_specific_endpoint = true;
30
31 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
32 }
33
34 /**
35 * Register the endpoint route.
36 */
37 public function register_routes() {
38 register_rest_route(
39 $this->namespace,
40 $this->rest_base . '/available-extensions',
41 array(
42 array(
43 'methods' => WP_REST_Server::READABLE,
44 'callback' => array( 'Jetpack_Gutenberg', 'get_availability' ),
45 'permission_callback' => array( $this, 'get_items_permission_check' ),
46 ),
47 'schema' => array( $this, 'get_item_schema' ),
48 )
49 );
50 }
51
52 /**
53 * Return the available Gutenberg extensions schema
54 *
55 * @return array Available Gutenberg extensions schema
56 */
57 public function get_public_item_schema() {
58 $schema = array(
59 '$schema' => 'http://json-schema.org/draft-04/schema#',
60 'title' => 'gutenberg-available-extensions',
61 'type' => 'object',
62 'properties' => array(
63 'available' => array(
64 'description' => __( 'Whether the extension is available', 'jetpack' ),
65 'type' => 'boolean',
66 ),
67 'unavailable_reason' => array(
68 'description' => __( 'Reason for the extension not being available', 'jetpack' ),
69 'type' => 'string',
70 ),
71 ),
72 );
73
74 return $this->add_additional_fields_schema( $schema );
75 }
76
77 /**
78 * Ensure the user has proper permissions
79 *
80 * @return boolean
81 */
82 public function get_items_permission_check() {
83 return current_user_can( 'edit_posts' );
84 }
85 }
86
87 wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Gutenberg_Available_Extensions' );
88