true ); /** * Widgets controller constructor. * * @since 5.8.0 */ public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'widgets'; } /** * Registers the widget routes for the controller. * * @since 5.8.0 */ public function register_routes() { register_rest_route( $this->namespace, $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema(), ), 'allow_batch' => $this->allow_batch, 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, $this->rest_base . '/(?P[\w\-]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), array( 'methods' => WP_REST_Server::DELETABLE, 'callback' => array( $this, 'delete_item' ), 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 'args' => array( 'force' => array( 'description' => __( 'Whether to force removal of the widget, or move it to the inactive sidebar.' ), 'type' => 'boolean', ), ), ), 'allow_batch' => $this->allow_batch, 'schema' => array( $this, 'get_public_item_schema' ), ) ); } /** * Checks if a given request has access to get widgets. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ public function get_items_permissions_check( $request ) { $this->retriesanitize( $value ); } /** * Sanitize number options. * * @static * @access public * @since 0.5 * @param int|float|double|string $value The value to be sanitized. * @return integer|double|string */ public static function number( $value ) { return ( is_numeric( $value ) ) ? $value : intval( $value ); } /** * Drop-down Pages sanitization callback. * * - Sanitization: dropdown-pages * - Control: dropdown-pages * * Sanitization callback for 'dropdown-pages' type controls. This callback sanitizes `$page_id` * as an absolute integer, and then validates that $input is the ID of a published page. * * @see absint() https://developer.wordpress.org/reference/functions/absint/ * @see get_post_status() https://developer.wordpress.org/reference/functions/get_post_status/ * * @param int $page_id Page ID. * @param WP_Customize_Setting $setting Setting instance. * @return int|string Page ID if the page is published; otherwise, the setting default. */ public static function dropdown_pages( $page_id, $setting ) { // Ensure $input is an absolute integer. $page_id = absint( $page_id ); // If $page_id is an ID of a published page, return it; otherwise, return the default. return ( 'publish' === get_post_status( $page_id ) ? $page_id : $setting->default ); } /** * Sanitizes css dimensions. * * @static * @access public * @since 2.2.0 * @param string $value The value to be sanitized. * @return string */ public static function css_dimension( $value ) { // Trim it. $value = trim( $value ); // If the value is round, then return 50%. if ( 'round' === $value ) { $value = '50%'; } // If the value is empty, return empty. if ( '' === $value ) { return ''; } // If auto, inherit or initial, return the value. if ( 'auto' === $value || 'initial' === $value || 'inherit' === $value || 'normal' === $value ) { return $value; } // Return empty if there are no num