| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\Variables\Classes; |
| 4 | 4 | |
| 5 | -use Elementor\Modules\Variables\Storage\Exceptions\Type_Mismatch; | |
| 6 | 5 | use WP_Error; |
| 7 | 6 | use Exception; |
| 8 | 7 | use WP_REST_Server; |
| 9 | 8 | use WP_REST_Request; |
| @@ -106,14 +105,8 @@ | ||
| 106 | 105 | 'required' => false, |
| 107 | 106 | 'type' => 'integer', |
| 108 | 107 | 'validate_callback' => [ $this, 'is_valid_order' ], |
| 109 | 108 | ], |
| 110 | - 'type' => [ | |
| 111 | - 'required' => false, | |
| 112 | - 'type' => 'string', | |
| 113 | - 'validate_callback' => [ $this, 'is_valid_variable_type' ], | |
| 114 | - 'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ], | |
| 115 | - ], | |
| 116 | 109 | ], |
| 117 | 110 | ] ); |
| 118 | 111 | |
| 119 | 112 | register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/delete', [ |
| @@ -152,14 +145,8 @@ | ||
| 152 | 145 | 'type' => 'string', |
| 153 | 146 | 'validate_callback' => [ $this, 'is_valid_variable_value' ], |
| 154 | 147 | 'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ], |
| 155 | 148 | ], |
| 156 | - 'type' => [ | |
| 157 | - 'required' => false, | |
| 158 | - 'type' => 'string', | |
| 159 | - 'validate_callback' => [ $this, 'is_valid_variable_type' ], | |
| 160 | - 'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ], | |
| 161 | - ], | |
| 162 | 149 | ], |
| 163 | 150 | ] ); |
| 164 | 151 | |
| 165 | 152 | register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/batch', [ |
| @@ -181,9 +168,8 @@ | ||
| 181 | 168 | ] ); |
| 182 | 169 | } |
| 183 | 170 | |
| 184 | 171 | public function trim_and_sanitize_text_field( $value ) { |
| 185 | - | |
| 186 | 172 | return trim( sanitize_text_field( $value ) ); |
| 187 | 173 | } |
| 188 | 174 | |
| 189 | 175 | public function is_valid_variable_id( $id ) { |
| @@ -309,9 +295,8 @@ | ||
| 309 | 295 | $id = $request->get_param( 'id' ); |
| 310 | 296 | $label = $request->get_param( 'label' ); |
| 311 | 297 | $value = $request->get_param( 'value' ); |
| 312 | 298 | $order = $request->get_param( 'order' ); |
| 313 | - $type = $request->get_param( 'type' ); | |
| 314 | 299 | |
| 315 | 300 | $update_data = [ |
| 316 | 301 | 'label' => $label, |
| 317 | 302 | 'value' => $value, |
| @@ -316,12 +301,8 @@ | ||
| 316 | 301 | 'label' => $label, |
| 317 | 302 | 'value' => $value, |
| 318 | 303 | ]; |
| 319 | 304 | |
| 320 | - if ( $type ) { | |
| 321 | - $update_data['type'] = $type; | |
| 322 | - } | |
| 323 | - | |
| 324 | 305 | if ( null !== $order ) { |
| 325 | 306 | $update_data['order'] = $order; |
| 326 | 307 | } |
| 327 | 308 | |
| @@ -380,14 +361,8 @@ | ||
| 380 | 361 | if ( $value ) { |
| 381 | 362 | $overrides['value'] = $value; |
| 382 | 363 | } |
| 383 | 364 | |
| 384 | - $type = $request->get_param( 'type' ); | |
| 385 | - | |
| 386 | - if ( $type ) { | |
| 387 | - $overrides['type'] = $type; | |
| 388 | - } | |
| 389 | - | |
| 390 | 365 | $result = $this->service->restore( $id, $overrides ); |
| 391 | 366 | |
| 392 | 367 | $this->clear_cache(); |
| 393 | 368 | |
| @@ -446,16 +421,8 @@ | ||
| 446 | 421 | __( 'Variable not found', 'elementor' ) |
| 447 | 422 | ); |
| 448 | 423 | } |
| 449 | 424 | |
| 450 | - if ( $e instanceof Type_Mismatch ) { | |
| 451 | - return $this->prepare_error_response( | |
| 452 | - self::HTTP_BAD_REQUEST, | |
| 453 | - 'type_mismatch', | |
| 454 | - $e->getMessage() | |
| 455 | - ); | |
| 456 | - } | |
| 457 | - | |
| 458 | 425 | return $this->prepare_error_response( |
| 459 | 426 | self::HTTP_SERVER_ERROR, |
| 460 | 427 | 'unexpected_server_error', |
| 461 | 428 | __( 'Unexpected server error', 'elementor' ) |
| @@ -481,8 +448,9 @@ | ||
| 481 | 448 | } |
| 482 | 449 | |
| 483 | 450 | return true; |
| 484 | 451 | } |
| 452 | + | |
| 485 | 453 | |
| 486 | 454 | public function is_valid_operations_array( $operations ) { |
| 487 | 455 | if ( ! is_array( $operations ) || empty( $operations ) ) { |
| 488 | 456 | return new WP_Error( |