PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.1 16.2 16.2-beta 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 All 503 releases
jetpack / _inc / lib / core-api / class.jetpack-core-api-widgets-endpoints.php

class.jetpack-core-api-widgets-endpoints.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at _inc/lib/core-api/class.jetpack-core-api-widgets-endpoints.php

65 lines 1.6 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 a specific widget via the REST API.
4 * Currently only supports the Milestone widget.
5 *
6 * @package automattic/jetpack
7 */
8
9 /**
10 * Widget information getter endpoint.
11 */
12 class Jetpack_Core_API_Widget_Endpoint {
13
14 /**
15 * Get information about a widget that is supported by this endpoint.
16 *
17 * @since 5.5.0
18 *
19 * @param WP_REST_Request $request {
20 * Array of parameters received by request.
21 *
22 * @type string $id Widget id.
23 * }
24 *
25 * @return WP_REST_Response|WP_Error A REST response if the request was served successfully, otherwise an error.
26 */
27 public function process( $request ) {
28 $widget_base = _get_widget_id_base( $request['id'] );
29 $widget_id = (int) substr( $request['id'], strlen( $widget_base ) + 1 );
30
31 switch ( $widget_base ) {
32 case 'milestone_widget':
33 $instances = get_option( 'widget_milestone_widget', array() );
34
35 if (
36 class_exists( 'Milestone_Widget' )
37 && is_active_widget( false, $widget_base . '-' . $widget_id, $widget_base )
38 && isset( $instances[ $widget_id ] )
39 ) {
40 $instance = $instances[ $widget_id ];
41 $widget = new Milestone_Widget();
42 return $widget->get_widget_data( $instance );
43 }
44 }
45
46 return new WP_Error(
47 'not_found',
48 esc_html__( 'The requested widget was not found.', 'jetpack' ),
49 array( 'status' => 404 )
50 );
51 }
52
53 /**
54 * Check that the current user has permissions to view widget information.
55 * For the currently supported widget there are no permissions required.
56 *
57 * @since 5.5.0
58 *
59 * @return bool
60 */
61 public function can_request() {
62 return true;
63 }
64 }
65