From 7b4ed34315dcb5d8d501f03014c9bdcff7a77287 Mon Sep 17 00:00:00 2001 From: Jorge Date: Wed, 1 May 2019 15:31:51 +0100 Subject: [PATCH] Added is_callback_widget to the controller arguments; Added required flag for the identifier. --- ...lass-wp-rest-widget-updater-controller.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/class-wp-rest-widget-updater-controller.php b/lib/class-wp-rest-widget-updater-controller.php index 658dcdf15be47d..d1696b79a77aef 100644 --- a/lib/class-wp-rest-widget-updater-controller.php +++ b/lib/class-wp-rest-widget-updater-controller.php @@ -37,9 +37,15 @@ public function register_routes() { '/' . $this->rest_base . '/(?P[\w-_]+)/', array( 'args' => array( - 'identifier' => array( + 'identifier' => array( 'description' => __( 'Class name of the widget.', 'gutenberg' ), 'type' => 'string', + 'required' => true, + ), + 'is_callback_widget' => array( + 'description' => __( 'Flag indicating if the widget is registered using register_sidebar_widget or is a subclass of WP_Widget.', 'gutenberg' ), + 'type' => 'boolean', + 'default' => false, ), ), array( @@ -81,12 +87,9 @@ public function compute_new_widget_permissions_check() { * @param string $identifier Widget id for callback widgets or widget class name for class widgets. * @param boolean $is_callback_widget If true the widget is a back widget if false the widget is a class widget. * - * @return boolean True if widget being referenced exists and false otherwise. + * @return boolean True if the widget being referenced exists and false otherwise. */ private function is_valid_widget( $identifier, $is_callback_widget ) { - if ( null === $identifier ) { - return false; - } if ( $is_callback_widget ) { global $wp_registered_widgets; return isset( $wp_registered_widgets[ $identifier ] ); @@ -99,12 +102,12 @@ private function is_valid_widget( $identifier, $is_callback_widget ) { /** * Computes an array with instance changes cleaned of widget specific prefixes and sufixes. * - * @since 5.2.0 + * @since 5.7.0 * @param string $id_base Widget ID Base. * @param string $id Widget instance identifier. * @param array $instance_changes Array with the form values being being changed. * - * @return array An array based on $instance_changes but whose keys have the widget specific sufixes and prefixes removed. + * @return array An array based on $instance_changes whose keys have the widget specific sufixes and prefixes removed. */ private function parse_instance_changes( $id_base, $id, $instance_changes ) { $instance_changes_parsed = array(); @@ -119,7 +122,7 @@ private function parse_instance_changes( $id_base, $id, $instance_changes ) { /** * Returns the bew callback widget form. * - * @since 5.2.0 + * @since 5.7.0 * @param string $identifier Widget id for callback widgets or widget class name for class widgets. * @param array $instance_changes Array with the form values being being changed. * @@ -152,7 +155,7 @@ private function compute_new_widget_handle_callback_widgets( $identifier, $insta /** * Returns the new class widget instance and the form that represents it. * - * @since 5.2.0 + * @since 5.7.0 * @access public * * @param string $identifier Widget id for callback widgets or widget class name for class widgets. @@ -240,7 +243,7 @@ private function compute_new_widget_handle_class_widgets( $identifier, $instance /** * Returns the new widget instance and the form that represents it. * - * @since 5.2.0 + * @since 5.7.0 * @access public * * @param WP_REST_Request $request Full details about the request. @@ -249,9 +252,6 @@ private function compute_new_widget_handle_class_widgets( $identifier, $instance public function compute_new_widget( $request ) { $identifier = $request->get_param( 'identifier' ); $is_callback_widget = $request->get_param( 'is_callback_widget' ); - if ( null === $is_callback_widget ) { - $is_callback_widget = false; - } if ( ! $this->is_valid_widget( $identifier, $is_callback_widget ) ) { return new WP_Error(