wp/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   713 				$prepared['instance']['encoded'] = base64_encode( $serialized_instance );
   713 				$prepared['instance']['encoded'] = base64_encode( $serialized_instance );
   714 				$prepared['instance']['hash']    = wp_hash( $serialized_instance );
   714 				$prepared['instance']['hash']    = wp_hash( $serialized_instance );
   715 
   715 
   716 				if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
   716 				if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
   717 					// Use new stdClass so that JSON result is {} and not [].
   717 					// Use new stdClass so that JSON result is {} and not [].
   718 					$prepared['instance']['raw'] = empty( $instance ) ? new stdClass : $instance;
   718 					$prepared['instance']['raw'] = empty( $instance ) ? new stdClass() : $instance;
   719 				}
   719 				}
   720 			}
   720 			}
   721 		}
   721 		}
   722 
   722 
   723 		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
   723 		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
   724 		$prepared = $this->add_additional_fields_to_object( $prepared, $request );
   724 		$prepared = $this->add_additional_fields_to_object( $prepared, $request );
   725 		$prepared = $this->filter_response_by_context( $prepared, $context );
   725 		$prepared = $this->filter_response_by_context( $prepared, $context );
   726 
   726 
   727 		$response = rest_ensure_response( $prepared );
   727 		$response = rest_ensure_response( $prepared );
   728 
   728 
   729 		$response->add_links( $this->prepare_links( $prepared ) );
   729 		if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
       
   730 			$response->add_links( $this->prepare_links( $prepared ) );
       
   731 		}
   730 
   732 
   731 		/**
   733 		/**
   732 		 * Filters the REST API response for a widget.
   734 		 * Filters the REST API response for a widget.
   733 		 *
   735 		 *
   734 		 * @since 5.8.0
   736 		 * @since 5.8.0
   857 				'form_data'     => array(
   859 				'form_data'     => array(
   858 					'description' => __( 'URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.' ),
   860 					'description' => __( 'URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.' ),
   859 					'type'        => 'string',
   861 					'type'        => 'string',
   860 					'context'     => array(),
   862 					'context'     => array(),
   861 					'arg_options' => array(
   863 					'arg_options' => array(
   862 						'sanitize_callback' => static function( $string ) {
   864 						'sanitize_callback' => static function ( $form_data ) {
   863 							$array = array();
   865 							$array = array();
   864 							wp_parse_str( $string, $array );
   866 							wp_parse_str( $form_data, $array );
   865 							return $array;
   867 							return $array;
   866 						},
   868 						},
   867 					),
   869 					),
   868 				),
   870 				),
   869 			),
   871 			),