Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/elemento.../modules/variable.../classes
File: rest-api.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Elementor\Modules\Variables\Classes;
[2] Fix | Delete
[3] Fix | Delete
use Elementor\Modules\Variables\Storage\Exceptions\Type_Mismatch;
[4] Fix | Delete
use WP_Error;
[5] Fix | Delete
use Exception;
[6] Fix | Delete
use WP_REST_Server;
[7] Fix | Delete
use WP_REST_Request;
[8] Fix | Delete
use Elementor\Plugin;
[9] Fix | Delete
use WP_REST_Response;
[10] Fix | Delete
use Elementor\Modules\Variables\Services\Variables_Service;
[11] Fix | Delete
use Elementor\Modules\Variables\Module as Variables_Module;
[12] Fix | Delete
use Elementor\Modules\Variables\Storage\Exceptions\VariablesLimitReached;
[13] Fix | Delete
use Elementor\Modules\Variables\Storage\Exceptions\RecordNotFound;
[14] Fix | Delete
use Elementor\Modules\Variables\Storage\Exceptions\DuplicatedLabel;
[15] Fix | Delete
use Elementor\Modules\Variables\Storage\Exceptions\BatchOperationFailed;
[16] Fix | Delete
[17] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[18] Fix | Delete
exit; // Exit if accessed directly.
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
class Rest_Api {
[22] Fix | Delete
const API_NAMESPACE = 'elementor/v1';
[23] Fix | Delete
const API_BASE = 'variables';
[24] Fix | Delete
const HTTP_OK = 200;
[25] Fix | Delete
const HTTP_CREATED = 201;
[26] Fix | Delete
const HTTP_BAD_REQUEST = 400;
[27] Fix | Delete
const HTTP_NOT_FOUND = 404;
[28] Fix | Delete
const HTTP_SERVER_ERROR = 500;
[29] Fix | Delete
const MAX_ID_LENGTH = 64;
[30] Fix | Delete
const MAX_LABEL_LENGTH = 50;
[31] Fix | Delete
const MAX_VALUE_LENGTH = 512;
[32] Fix | Delete
[33] Fix | Delete
private Variables_Service $service;
[34] Fix | Delete
[35] Fix | Delete
public function __construct( Variables_Service $service ) {
[36] Fix | Delete
$this->service = $service;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function enough_permissions_to_perform_ro_action() {
[40] Fix | Delete
return current_user_can( 'edit_posts' );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
public function enough_permissions_to_perform_rw_action() {
[44] Fix | Delete
return current_user_can( 'manage_options' );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
public function register_routes() {
[48] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/list', [
[49] Fix | Delete
'methods' => WP_REST_Server::READABLE,
[50] Fix | Delete
'callback' => [ $this, 'get_variables' ],
[51] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_ro_action' ],
[52] Fix | Delete
] );
[53] Fix | Delete
[54] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/create', [
[55] Fix | Delete
'methods' => WP_REST_Server::CREATABLE,
[56] Fix | Delete
'callback' => [ $this, 'create_variable' ],
[57] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_rw_action' ],
[58] Fix | Delete
'args' => [
[59] Fix | Delete
'type' => [
[60] Fix | Delete
'required' => true,
[61] Fix | Delete
'type' => 'string',
[62] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_type' ],
[63] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[64] Fix | Delete
],
[65] Fix | Delete
'label' => [
[66] Fix | Delete
'required' => true,
[67] Fix | Delete
'type' => 'string',
[68] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_label' ],
[69] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[70] Fix | Delete
],
[71] Fix | Delete
'value' => [
[72] Fix | Delete
'required' => true,
[73] Fix | Delete
'type' => 'string',
[74] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_value' ],
[75] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[76] Fix | Delete
],
[77] Fix | Delete
],
[78] Fix | Delete
] );
[79] Fix | Delete
[80] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/update', [
[81] Fix | Delete
'methods' => WP_REST_Server::EDITABLE,
[82] Fix | Delete
'callback' => [ $this, 'update_variable' ],
[83] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_rw_action' ],
[84] Fix | Delete
'args' => [
[85] Fix | Delete
'id' => [
[86] Fix | Delete
'required' => true,
[87] Fix | Delete
'type' => 'string',
[88] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_id' ],
[89] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[90] Fix | Delete
],
[91] Fix | Delete
'label' => [
[92] Fix | Delete
'required' => true,
[93] Fix | Delete
'type' => 'string',
[94] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_label' ],
[95] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[96] Fix | Delete
],
[97] Fix | Delete
'value' => [
[98] Fix | Delete
'required' => true,
[99] Fix | Delete
'type' => 'string',
[100] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_value' ],
[101] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[102] Fix | Delete
],
[103] Fix | Delete
'order' => [
[104] Fix | Delete
'required' => false,
[105] Fix | Delete
'type' => 'integer',
[106] Fix | Delete
'validate_callback' => [ $this, 'is_valid_order' ],
[107] Fix | Delete
],
[108] Fix | Delete
'type' => [
[109] Fix | Delete
'required' => false,
[110] Fix | Delete
'type' => 'string',
[111] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_type' ],
[112] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[113] Fix | Delete
],
[114] Fix | Delete
],
[115] Fix | Delete
] );
[116] Fix | Delete
[117] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/delete', [
[118] Fix | Delete
'methods' => WP_REST_Server::EDITABLE,
[119] Fix | Delete
'callback' => [ $this, 'delete_variable' ],
[120] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_rw_action' ],
[121] Fix | Delete
'args' => [
[122] Fix | Delete
'id' => [
[123] Fix | Delete
'required' => true,
[124] Fix | Delete
'type' => 'string',
[125] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_id' ],
[126] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[127] Fix | Delete
],
[128] Fix | Delete
],
[129] Fix | Delete
] );
[130] Fix | Delete
[131] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/restore', [
[132] Fix | Delete
'methods' => WP_REST_Server::EDITABLE,
[133] Fix | Delete
'callback' => [ $this, 'restore_variable' ],
[134] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_rw_action' ],
[135] Fix | Delete
'args' => [
[136] Fix | Delete
'id' => [
[137] Fix | Delete
'required' => true,
[138] Fix | Delete
'type' => 'string',
[139] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_id' ],
[140] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[141] Fix | Delete
],
[142] Fix | Delete
'label' => [
[143] Fix | Delete
'required' => false,
[144] Fix | Delete
'type' => 'string',
[145] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_label' ],
[146] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[147] Fix | Delete
],
[148] Fix | Delete
'value' => [
[149] Fix | Delete
'required' => false,
[150] Fix | Delete
'type' => 'string',
[151] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_value' ],
[152] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[153] Fix | Delete
],
[154] Fix | Delete
'type' => [
[155] Fix | Delete
'required' => false,
[156] Fix | Delete
'type' => 'string',
[157] Fix | Delete
'validate_callback' => [ $this, 'is_valid_variable_type' ],
[158] Fix | Delete
'sanitize_callback' => [ $this, 'trim_and_sanitize_text_field' ],
[159] Fix | Delete
],
[160] Fix | Delete
],
[161] Fix | Delete
] );
[162] Fix | Delete
[163] Fix | Delete
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/batch', [
[164] Fix | Delete
'methods' => WP_REST_Server::CREATABLE,
[165] Fix | Delete
'callback' => [ $this, 'process_batch' ],
[166] Fix | Delete
'permission_callback' => [ $this, 'enough_permissions_to_perform_rw_action' ],
[167] Fix | Delete
'args' => [
[168] Fix | Delete
'watermark' => [
[169] Fix | Delete
'required' => true,
[170] Fix | Delete
'type' => 'integer',
[171] Fix | Delete
'validate_callback' => [ $this, 'is_valid_watermark' ],
[172] Fix | Delete
],
[173] Fix | Delete
'operations' => [
[174] Fix | Delete
'required' => true,
[175] Fix | Delete
'type' => 'array',
[176] Fix | Delete
'validate_callback' => [ $this, 'is_valid_operations_array' ],
[177] Fix | Delete
],
[178] Fix | Delete
],
[179] Fix | Delete
] );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
public function trim_and_sanitize_text_field( $value ) {
[183] Fix | Delete
[184] Fix | Delete
return trim( sanitize_text_field( $value ) );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
public function is_valid_variable_id( $id ) {
[188] Fix | Delete
$id = trim( $id );
[189] Fix | Delete
[190] Fix | Delete
if ( empty( $id ) ) {
[191] Fix | Delete
return new WP_Error(
[192] Fix | Delete
'invalid_variable_id_empty',
[193] Fix | Delete
__( 'ID cannot be empty', 'elementor' )
[194] Fix | Delete
);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( self::MAX_ID_LENGTH < strlen( $id ) ) {
[198] Fix | Delete
return new WP_Error( 'invalid_variable_id_length', sprintf(
[199] Fix | Delete
/* translators: %d: Maximum ID length. */
[200] Fix | Delete
__( 'ID cannot exceed %d characters', 'elementor' ),
[201] Fix | Delete
self::MAX_ID_LENGTH
[202] Fix | Delete
) );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
return true;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
public function is_valid_variable_type( $type ) {
[209] Fix | Delete
$allowed_types = array_keys( Variables_Module::instance()->get_variable_types_registry()->all() );
[210] Fix | Delete
[211] Fix | Delete
return in_array( $type, $allowed_types, true );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
public function is_valid_variable_label( $label ) {
[215] Fix | Delete
$label = trim( $label );
[216] Fix | Delete
[217] Fix | Delete
if ( empty( $label ) ) {
[218] Fix | Delete
return new WP_Error(
[219] Fix | Delete
'invalid_variable_label_empty',
[220] Fix | Delete
__( 'Label cannot be empty', 'elementor' )
[221] Fix | Delete
);
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
if ( self::MAX_LABEL_LENGTH < strlen( $label ) ) {
[225] Fix | Delete
return new WP_Error( 'invalid_variable_label_length', sprintf(
[226] Fix | Delete
/* translators: %d: Maximum label length. */
[227] Fix | Delete
__( 'Label cannot exceed %d characters', 'elementor' ),
[228] Fix | Delete
self::MAX_LABEL_LENGTH
[229] Fix | Delete
) );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
return true;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
public function is_valid_order( $order ) {
[236] Fix | Delete
if ( ! is_numeric( $order ) || $order < 0 ) {
[237] Fix | Delete
return new WP_Error(
[238] Fix | Delete
'invalid_order',
[239] Fix | Delete
__( 'Order must be a non-negative integer', 'elementor' )
[240] Fix | Delete
);
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return true;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
public function is_valid_variable_value( $value ) {
[247] Fix | Delete
$value = trim( $value );
[248] Fix | Delete
[249] Fix | Delete
if ( empty( $value ) ) {
[250] Fix | Delete
return new WP_Error(
[251] Fix | Delete
'invalid_variable_value_empty',
[252] Fix | Delete
__( 'Value cannot be empty', 'elementor' )
[253] Fix | Delete
);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
if ( self::MAX_VALUE_LENGTH < strlen( $value ) ) {
[257] Fix | Delete
return new WP_Error( 'invalid_variable_value_length', sprintf(
[258] Fix | Delete
/* translators: %d: Maximum value length. */
[259] Fix | Delete
__( 'Value cannot exceed %d characters', 'elementor' ),
[260] Fix | Delete
self::MAX_VALUE_LENGTH
[261] Fix | Delete
) );
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
return true;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
public function create_variable( WP_REST_Request $request ) {
[268] Fix | Delete
try {
[269] Fix | Delete
return $this->create_new_variable( $request );
[270] Fix | Delete
} catch ( Exception $e ) {
[271] Fix | Delete
return $this->error_response( $e );
[272] Fix | Delete
}
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
protected function clear_cache() {
[276] Fix | Delete
Plugin::$instance->files_manager->clear_cache();
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
private function create_new_variable( WP_REST_Request $request ) {
[280] Fix | Delete
$type = $request->get_param( 'type' );
[281] Fix | Delete
$label = $request->get_param( 'label' );
[282] Fix | Delete
$value = $request->get_param( 'value' );
[283] Fix | Delete
[284] Fix | Delete
$result = $this->service->create( [
[285] Fix | Delete
'type' => $type,
[286] Fix | Delete
'label' => $label,
[287] Fix | Delete
'value' => $value,
[288] Fix | Delete
] );
[289] Fix | Delete
[290] Fix | Delete
$this->clear_cache();
[291] Fix | Delete
[292] Fix | Delete
return $this->success_response( [
[293] Fix | Delete
'variable' => $result['variable'],
[294] Fix | Delete
'watermark' => $result['watermark'],
[295] Fix | Delete
], self::HTTP_CREATED );
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
public function update_variable( WP_REST_Request $request ) {
[299] Fix | Delete
try {
[300] Fix | Delete
return $this->update_existing_variable( $request );
[301] Fix | Delete
} catch ( Exception $e ) {
[302] Fix | Delete
return $this->error_response( $e );
[303] Fix | Delete
}
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
private function update_existing_variable( WP_REST_Request $request ) {
[307] Fix | Delete
$id = $request->get_param( 'id' );
[308] Fix | Delete
$label = $request->get_param( 'label' );
[309] Fix | Delete
$value = $request->get_param( 'value' );
[310] Fix | Delete
$order = $request->get_param( 'order' );
[311] Fix | Delete
$type = $request->get_param( 'type' );
[312] Fix | Delete
[313] Fix | Delete
$update_data = [
[314] Fix | Delete
'label' => $label,
[315] Fix | Delete
'value' => $value,
[316] Fix | Delete
];
[317] Fix | Delete
[318] Fix | Delete
if ( $type ) {
[319] Fix | Delete
$update_data['type'] = $type;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
if ( null !== $order ) {
[323] Fix | Delete
$update_data['order'] = $order;
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
$result = $this->service->update( $id, $update_data );
[327] Fix | Delete
[328] Fix | Delete
$this->clear_cache();
[329] Fix | Delete
[330] Fix | Delete
return $this->success_response( [
[331] Fix | Delete
'variable' => $result['variable'],
[332] Fix | Delete
'watermark' => $result['watermark'],
[333] Fix | Delete
] );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
public function delete_variable( WP_REST_Request $request ) {
[337] Fix | Delete
try {
[338] Fix | Delete
return $this->delete_existing_variable( $request );
[339] Fix | Delete
} catch ( Exception $e ) {
[340] Fix | Delete
return $this->error_response( $e );
[341] Fix | Delete
}
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
private function delete_existing_variable( WP_REST_Request $request ) {
[345] Fix | Delete
$id = $request->get_param( 'id' );
[346] Fix | Delete
[347] Fix | Delete
$result = $this->service->delete( $id );
[348] Fix | Delete
[349] Fix | Delete
$this->clear_cache();
[350] Fix | Delete
[351] Fix | Delete
return $this->success_response( [
[352] Fix | Delete
'variable' => $result['variable'],
[353] Fix | Delete
'watermark' => $result['watermark'],
[354] Fix | Delete
] );
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
public function restore_variable( WP_REST_Request $request ) {
[358] Fix | Delete
try {
[359] Fix | Delete
return $this->restore_existing_variable( $request );
[360] Fix | Delete
} catch ( Exception $e ) {
[361] Fix | Delete
return $this->error_response( $e );
[362] Fix | Delete
}
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
private function restore_existing_variable( WP_REST_Request $request ) {
[366] Fix | Delete
$id = $request->get_param( 'id' );
[367] Fix | Delete
[368] Fix | Delete
$overrides = [];
[369] Fix | Delete
[370] Fix | Delete
$label = $request->get_param( 'label' );
[371] Fix | Delete
[372] Fix | Delete
if ( $label ) {
[373] Fix | Delete
$overrides['label'] = $label;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
$value = $request->get_param( 'value' );
[377] Fix | Delete
[378] Fix | Delete
if ( $value ) {
[379] Fix | Delete
$overrides['value'] = $value;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
$type = $request->get_param( 'type' );
[383] Fix | Delete
[384] Fix | Delete
if ( $type ) {
[385] Fix | Delete
$overrides['type'] = $type;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
$result = $this->service->restore( $id, $overrides );
[389] Fix | Delete
[390] Fix | Delete
$this->clear_cache();
[391] Fix | Delete
[392] Fix | Delete
return $this->success_response( [
[393] Fix | Delete
'variable' => $result['variable'],
[394] Fix | Delete
'watermark' => $result['watermark'],
[395] Fix | Delete
] );
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
public function get_variables() {
[399] Fix | Delete
try {
[400] Fix | Delete
return $this->list_of_variables();
[401] Fix | Delete
} catch ( Exception $e ) {
[402] Fix | Delete
return $this->error_response( $e );
[403] Fix | Delete
}
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
private function list_of_variables() {
[407] Fix | Delete
$db_record = $this->service->load();
[408] Fix | Delete
[409] Fix | Delete
return $this->success_response( [
[410] Fix | Delete
'variables' => $db_record['data'] ?? [],
[411] Fix | Delete
'total' => count( $db_record['data'] ),
[412] Fix | Delete
'watermark' => $db_record['watermark'],
[413] Fix | Delete
] );
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
private function success_response( $payload, $status_code = null ) {
[417] Fix | Delete
return new WP_REST_Response( [
[418] Fix | Delete
'success' => true,
[419] Fix | Delete
'data' => $payload,
[420] Fix | Delete
], $status_code ?? self::HTTP_OK );
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
private function error_response( Exception $e ) {
[424] Fix | Delete
if ( $e instanceof VariablesLimitReached ) {
[425] Fix | Delete
return $this->prepare_error_response(
[426] Fix | Delete
self::HTTP_BAD_REQUEST,
[427] Fix | Delete
'invalid_variable_limit_reached',
[428] Fix | Delete
__( 'Reached the maximum number of variables', 'elementor' )
[429] Fix | Delete
);
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
if ( $e instanceof DuplicatedLabel ) {
[433] Fix | Delete
return $this->prepare_error_response(
[434] Fix | Delete
self::HTTP_BAD_REQUEST,
[435] Fix | Delete
'duplicated_label',
[436] Fix | Delete
__( 'Variable label already exists', 'elementor' )
[437] Fix | Delete
);
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
if ( $e instanceof RecordNotFound ) {
[441] Fix | Delete
return $this->prepare_error_response(
[442] Fix | Delete
self::HTTP_NOT_FOUND,
[443] Fix | Delete
'variable_not_found',
[444] Fix | Delete
__( 'Variable not found', 'elementor' )
[445] Fix | Delete
);
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
if ( $e instanceof Type_Mismatch ) {
[449] Fix | Delete
return $this->prepare_error_response(
[450] Fix | Delete
self::HTTP_BAD_REQUEST,
[451] Fix | Delete
'type_mismatch',
[452] Fix | Delete
$e->getMessage()
[453] Fix | Delete
);
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
return $this->prepare_error_response(
[457] Fix | Delete
self::HTTP_SERVER_ERROR,
[458] Fix | Delete
'unexpected_server_error',
[459] Fix | Delete
__( 'Unexpected server error', 'elementor' )
[460] Fix | Delete
);
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
private function prepare_error_response( $status_code, $error, $message ) {
[464] Fix | Delete
return new WP_REST_Response( [
[465] Fix | Delete
'code' => $error,
[466] Fix | Delete
'message' => $message,
[467] Fix | Delete
'data' => [
[468] Fix | Delete
'status' => $status_code,
[469] Fix | Delete
],
[470] Fix | Delete
], $status_code );
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
public function is_valid_watermark( $watermark ) {
[474] Fix | Delete
if ( ! is_numeric( $watermark ) || $watermark < 0 ) {
[475] Fix | Delete
return new WP_Error(
[476] Fix | Delete
'invalid_watermark',
[477] Fix | Delete
__( 'Watermark must be a non-negative integer', 'elementor' )
[478] Fix | Delete
);
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
return true;
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
public function is_valid_operations_array( $operations ) {
[485] Fix | Delete
if ( ! is_array( $operations ) || empty( $operations ) ) {
[486] Fix | Delete
return new WP_Error(
[487] Fix | Delete
'invalid_operations_empty',
[488] Fix | Delete
__( 'Operations array cannot be empty', 'elementor' )
[489] Fix | Delete
);
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
foreach ( $operations as $index => $operation ) {
[493] Fix | Delete
if ( ! is_array( $operation ) || ! isset( $operation['type'] ) ) {
[494] Fix | Delete
$sanitized_index = absint( $index );
[495] Fix | Delete
return new WP_Error(
[496] Fix | Delete
'invalid_operation_structure',
[497] Fix | Delete
sprintf(
[498] Fix | Delete
/* translators: %d: operation index */
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function