← All changes
|
inc/rest-api/v1/frontend/class-lp-rest-widgets-controller.php
+4
-11
4.1.6.9.3
→
4.4.9
View file →
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | |
| 27 | 27 | parent::register_routes(); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function get_content_widgets( WP_REST_Request $request ) { | |
| 30 | + public function get_content_widgets( WP_REST_Request $request ): LP_REST_Response { | |
| 31 | 31 | global $wp_widget_factory; |
| 32 | 32 | |
| 33 | 33 | $response = new LP_REST_Response(); |
| 34 | 34 | $response->data = ''; |
| @@ -36,11 +36,10 @@ | ||
| 36 | 36 | try { |
| 37 | 37 | $params = $request->get_params(); |
| 38 | 38 | $widget_id = $params['widget'] ?? false; // LP_Widget. |
| 39 | 39 | $instance = $params['instance'] ?? false; |
| 40 | - $hash = $params['hash'] ?? false; | |
| 41 | 40 | |
| 42 | - if ( empty( $widget_id ) || empty( $instance ) || empty( $hash ) ) { | |
| 41 | + if ( empty( $widget_id ) || empty( $instance ) ) { | |
| 43 | 42 | throw new Exception( 'Error: No params!' ); |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | $widget_object = $wp_widget_factory->get_widget_object( $widget_id ); |
| @@ -48,16 +47,10 @@ | ||
| 48 | 47 | if ( ! method_exists( $widget_object, 'lp_rest_api_content' ) ) { |
| 49 | 48 | throw new Exception( 'Error: No method lp_rest_api_content!' ); |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | - $serialized_instance = base64_decode( $instance ); | |
| 51 | + $instance = json_decode( $instance, true ); | |
| 53 | 52 | |
| 54 | - if ( ! hash_equals( wp_hash( $serialized_instance ), $hash ) ) { | |
| 55 | - throw new Exception( 'The provided instance is malformed.' ); | |
| 56 | - } | |
| 57 | - | |
| 58 | - $instance = unserialize( $serialized_instance ); | |
| 59 | - | |
| 60 | 53 | unset( $params['instance'] ); |
| 61 | 54 | unset( $params['hash'] ); |
| 62 | 55 | |
| 63 | 56 | $data = $widget_object->lp_rest_api_content( $instance, $params ); // LP_Widget->lp_rest_api_content. |
| @@ -72,7 +65,7 @@ | ||
| 72 | 65 | $response->status = 'error'; |
| 73 | 66 | $response->message = $th->getMessage(); |
| 74 | 67 | } |
| 75 | 68 | |
| 76 | - return rest_ensure_response( $response ); | |
| 69 | + return $response; | |
| 77 | 70 | } |
| 78 | 71 | } |