image-optimization
/
vendor
/
elementor
/
wp-one-package
/
src
/
Admin
/
Controllers
/
ManageDashboardWidget.php
ManageDashboardWidget.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.6, at vendor/elementor/wp-one-package/src/Admin/Controllers/ManageDashboardWidget.php
| 1 | <?php |
| 2 | |
| 3 | namespace ElementorOne\Admin\Controllers; |
| 4 | |
| 5 | use ElementorOne\Admin\Config; |
| 6 | use ElementorOne\Admin\Services\ManageWidgetState; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | class ManageDashboardWidget extends \WP_REST_Controller { |
| 13 | |
| 14 | public function __construct() { |
| 15 | $this->namespace = Config::APP_REST_NAMESPACE; |
| 16 | $this->rest_base = 'manage-dashboard-widget'; |
| 17 | |
| 18 | add_action( 'rest_api_init', [ $this, 'register_routes' ] ); |
| 19 | } |
| 20 | |
| 21 | public function register_routes() { |
| 22 | register_rest_route( |
| 23 | $this->namespace, |
| 24 | '/' . $this->rest_base . '/state', |
| 25 | [ |
| 26 | [ |
| 27 | 'methods' => \WP_REST_Server::READABLE, |
| 28 | 'callback' => [ $this, 'get_state' ], |
| 29 | 'permission_callback' => [ $this, 'get_state_permissions_check' ], |
| 30 | ], |
| 31 | ] |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | public function get_state( \WP_REST_Request $request ) { |
| 36 | $resolved = ManageWidgetState::resolve_with_meta(); |
| 37 | |
| 38 | return new \WP_REST_Response( [ |
| 39 | 'state' => $resolved['state'], |
| 40 | 'isWidgetDelegated' => $resolved['isWidgetDelegated'], |
| 41 | ] ); |
| 42 | } |
| 43 | |
| 44 | public function get_state_permissions_check( $request ) { |
| 45 | return current_user_can( 'manage_options' ); |
| 46 | } |
| 47 | } |
| 48 |