Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/variable.../classes
File: rest-api.php
__( 'Invalid operation structure at index %d', 'elementor' ),
[500] Fix | Delete
$sanitized_index
[501] Fix | Delete
)
[502] Fix | Delete
);
[503] Fix | Delete
}
[504] Fix | Delete
[505] Fix | Delete
$allowed_types = [ 'create', 'update', 'delete', 'restore', 'reorder' ];
[506] Fix | Delete
[507] Fix | Delete
if ( ! in_array( $operation['type'], $allowed_types, true ) ) {
[508] Fix | Delete
$sanitized_index = absint( $index );
[509] Fix | Delete
return new WP_Error(
[510] Fix | Delete
'invalid_operation_type',
[511] Fix | Delete
sprintf(
[512] Fix | Delete
/* translators: %d: operation index */
[513] Fix | Delete
__( 'Invalid operation type at index %d', 'elementor' ),
[514] Fix | Delete
$sanitized_index
[515] Fix | Delete
)
[516] Fix | Delete
);
[517] Fix | Delete
}
[518] Fix | Delete
}
[519] Fix | Delete
[520] Fix | Delete
return true;
[521] Fix | Delete
}
[522] Fix | Delete
[523] Fix | Delete
public function process_batch( WP_REST_Request $request ) {
[524] Fix | Delete
try {
[525] Fix | Delete
return $this->process_batch_operations( $request );
[526] Fix | Delete
} catch ( Exception $e ) {
[527] Fix | Delete
return $this->batch_error_response( $e );
[528] Fix | Delete
}
[529] Fix | Delete
}
[530] Fix | Delete
[531] Fix | Delete
private function process_batch_operations( WP_REST_Request $request ) {
[532] Fix | Delete
$operations = $request->get_param( 'operations' );
[533] Fix | Delete
[534] Fix | Delete
$result = $this->service->process_batch( $operations );
[535] Fix | Delete
[536] Fix | Delete
$this->clear_cache();
[537] Fix | Delete
[538] Fix | Delete
return $this->success_response( $result );
[539] Fix | Delete
}
[540] Fix | Delete
[541] Fix | Delete
[542] Fix | Delete
private function batch_error_response( Exception $e ) {
[543] Fix | Delete
if ( $e instanceof BatchOperationFailed ) {
[544] Fix | Delete
$error_details = $e->getErrorDetails();
[545] Fix | Delete
$batch_error_context = $this->determine_batch_error_context( $error_details );
[546] Fix | Delete
[547] Fix | Delete
return new WP_REST_Response( [
[548] Fix | Delete
'success' => false,
[549] Fix | Delete
'code' => $batch_error_context['code'],
[550] Fix | Delete
'message' => $batch_error_context['message'],
[551] Fix | Delete
'data' => $batch_error_context['filtered_errors'],
[552] Fix | Delete
], self::HTTP_BAD_REQUEST );
[553] Fix | Delete
}
[554] Fix | Delete
[555] Fix | Delete
return $this->error_response( $e );
[556] Fix | Delete
}
[557] Fix | Delete
[558] Fix | Delete
private function determine_batch_error_context( array $error_details ) {
[559] Fix | Delete
$error_config = [
[560] Fix | Delete
'invalid_variable_limit_reached' => [
[561] Fix | Delete
'batch_code' => 'batch_variables_limit_reached',
[562] Fix | Delete
'batch_message' => __( 'Batch operation failed: Reached the maximum number of variables', 'elementor' ),
[563] Fix | Delete
'status' => self::HTTP_BAD_REQUEST,
[564] Fix | Delete
'message' => __( 'Reached the maximum number of variables', 'elementor' ),
[565] Fix | Delete
],
[566] Fix | Delete
'duplicated_label' => [
[567] Fix | Delete
'batch_code' => 'batch_duplicated_label',
[568] Fix | Delete
'batch_message' => __( 'Batch operation failed: Variable labels already exist', 'elementor' ),
[569] Fix | Delete
'status' => self::HTTP_BAD_REQUEST,
[570] Fix | Delete
'message' => __( 'Variable label already exists', 'elementor' ),
[571] Fix | Delete
],
[572] Fix | Delete
'variable_not_found' => [
[573] Fix | Delete
'batch_code' => 'batch_variables_not_found',
[574] Fix | Delete
'batch_message' => __( 'Batch operation failed: Variables not found', 'elementor' ),
[575] Fix | Delete
'status' => self::HTTP_NOT_FOUND,
[576] Fix | Delete
'message' => __( 'Variable not found', 'elementor' ),
[577] Fix | Delete
],
[578] Fix | Delete
];
[579] Fix | Delete
[580] Fix | Delete
$grouped_errors = [];
[581] Fix | Delete
[582] Fix | Delete
foreach ( $error_details as $id => $error_detail ) {
[583] Fix | Delete
$error_code = $error_detail['code'] ?? '';
[584] Fix | Delete
[585] Fix | Delete
if ( isset( $error_config[ $error_code ] ) ) {
[586] Fix | Delete
$config = $error_config[ $error_code ];
[587] Fix | Delete
$grouped_errors[ $error_code ][ $id ] = [
[588] Fix | Delete
'status' => $config['status'],
[589] Fix | Delete
'message' => $config['message'],
[590] Fix | Delete
];
[591] Fix | Delete
} else {
[592] Fix | Delete
$grouped_errors['unknown'][ $id ] = [
[593] Fix | Delete
'status' => self::HTTP_SERVER_ERROR,
[594] Fix | Delete
'message' => $error_detail['message'] ?? __( 'Unexpected error', 'elementor' ),
[595] Fix | Delete
];
[596] Fix | Delete
}
[597] Fix | Delete
}
[598] Fix | Delete
[599] Fix | Delete
foreach ( $error_config as $error_code => $config ) {
[600] Fix | Delete
if ( ! empty( $grouped_errors[ $error_code ] ) ) {
[601] Fix | Delete
return [
[602] Fix | Delete
'code' => $config['batch_code'],
[603] Fix | Delete
'message' => $config['batch_message'],
[604] Fix | Delete
'filtered_errors' => $grouped_errors[ $error_code ],
[605] Fix | Delete
];
[606] Fix | Delete
}
[607] Fix | Delete
}
[608] Fix | Delete
[609] Fix | Delete
return [
[610] Fix | Delete
'code' => 'batch_operation_failed',
[611] Fix | Delete
'message' => __( 'Batch operation failed', 'elementor' ),
[612] Fix | Delete
'filtered_errors' => $grouped_errors['unknown'] ?? [],
[613] Fix | Delete
];
[614] Fix | Delete
}
[615] Fix | Delete
}
[616] Fix | Delete
[617] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function