$response; } private function handle_bulk( array $operations ) { $results = new Bulk_Operations_Result(); $batch_operations = []; $index_map = []; $pro_message_reported = false; foreach ( $operations as $index => $operation ) { if ( ! is_array( $operation ) ) { $results->add_error( $index, '', 'invalid_input', __( 'Invalid operation.', 'elementor' ) ); continue; } $translated = $this->translate_operation( $operation ); if ( is_wp_error( $translated ) ) { $message = $translated->get_error_message(); if ( Pro_Features_Discovery::ERROR_CODE === $translated->get_error_code() ) { $message = $pro_message_reported ? Variables_Pro_Features_Discovery::get_repeated_message() : $message; $pro_message_reported = true; } $results->add_error( $index, $operation['action'] ?? '', $translated->get_error_code(), $message ); continue; } $index_map[ count( $batch_operations ) ] = $index; $batch_operations[] = $translated; } $watermark = null; if ( ! empty( $batch_operations ) ) { try { $batch_result = $this->get_service()->process_batch( $batch_operations, true ); $watermark = $batch_result['watermark'] ?? null; $this->merge_batch_results( $batch_result['results'], $index_map, $results ); $this->emit_variable_events( $batch_result['results'] ); } catch ( FatalError $e ) { return new \WP_Error( 'unexpected_server_error', __( 'Unexpected server error', 'elementor' ), [ 'status' => \WP_Http::INTERNAL_SERVER_ERROR ] ); } $this->clear_cache(); } $response = $results->to_array(); if ( null !== $watermark ) { $response['watermark'] = $watermark; } return $response; } private function translate_operation( array $operation ) { $action = $operation['action'] ?? ''; switch ( $action ) { case 'create': $type = $operation['type'] ?? ''; $label = $operation['label'] ?? ''; $value = $operation['value'] ?? ''; if ( '' === $type || '' === $label || '' === $value ) { return $this->bad_request( __( 'Create requires type, label, and value.', 'elementor' ) ); } if ( $this->is_size_type( $type ) && ! $this->can_manage_size_variables() ) { return Variables_Pro_Features_Discovery::for_size_variables(); } return [ 'type' => 'create', 'variable' => [ 'type' => $type, 'label' => $label, 'value' => $value, ], ]; case 'update': $id = $operation['id'] ?? ''; $label = $operation['label'] ?? ''; $value = $operation['value'] ?? ''; if ( '' === $id || '' === $label || '' === $value ) { return $this->bad_request( __( 'Update requires id, label, and value.', 'elementor' ) ); } if ( ! $this->can_manage_size_variables() && $this->is_size_variable( $id ) ) { return Variables_Pro_Features_Discovery::for_size_variables(); } return [ 'type' => 'update', 'id' => $id, 'variable' => [ 'label' => $label, 'value' => $value, ], ]; case 'delete': $id = $operation['id'] ?? ''; if ( '' === $id ) { return $this->bad_request( __( 'Delete requires id.', 'elementor' ) ); } return [ 'type' => 'delete', 'id' => $id, ]; default: return $this->bad_request( sprintf( /* translators: %s: action name */ __( 'Unknown action: %s.', 'elementor' ), $action ) ); } } private function merge_batch_results( array $batch_results, array $index_map, Bulk_Operations_Result $results ): void { foreach ( $batch_results as $batch_index => $result ) { $original_index = $index_map[ $batch_index ]; if ( 'ok' === ( $result['status'] ?? '' ) ) { $extra = array_diff_key( $result, array_flip( [ 'index', 'status' ] ) ); $results->add_success( $original_index, $result['action'] ?? '', $extra ); } else { $results->add_error( $original_index, $result['action'] ?? '', $result['code'] ?? 'unknown_error', $result['message'] ?? '' ); } } } private function bad_request( string $message ): \WP_Error { return new \WP_Error( 'invalid_input', $message, [ 'status' => \WP_Http::BAD_REQUEST ] ); } private function is_size_type( $type ): bool { return in_array( $type, [ self::TYPE_SIZE, self::TYPE_CUSTOM_SIZE ], true ); } private function is_size_variable( $id ): bool { return is_string( $id ) && $this->is_size_type( $this->get_service()->find_type( $id ) ); } private function can_manage_size_variables(): bool { return Utils::is_license_active(); } private function get_description(): string { return __( 'Manage V4 global variables (color, font, size, custom-size). Bulk create, update, or delete on the active kit (up to 50 operations).', 'elementor' ); } private function clear_cache(): void { if ( ! class_exists( Plugin::class ) || ! isset( Plugin::$instance ) ) { return; } Plugin::$instance->files_manager->clear_cache(); $this->flush_runtime_cache(); } private function flush_runtime_cache(): void { if ( function_exists( 'wp_cache_flush_runtime' ) ) { wp_cache_flush_runtime(); } } private function get_service(): Variables_Service { if ( $this->service ) { return $this->service; } $kit = Plugin::$instance->kits_manager->get_active_kit(); return new Variables_Service( new Variables_Repository( $kit ), new Batch_Processor() ); } private function emit_variable_events( array $batch_results ): void { $event_by_action = [ 'create' => 'variable_created', 'update' => 'variable_updated', ]; $var_type_labels = [ self::TYPE_COLOR => 'color', self::TYPE_FONT => 'font', self::TYPE_SIZE => 'size', self::TYPE_CUSTOM_SIZE => 'size', ]; foreach ( $batch_results as $result ) { if ( 'ok' !== ( $result['status'] ?? '' ) ) { continue; } $action = $result['action'] ?? ''; if ( ! isset( $event_by_action[ $action ] ) ) { continue; } $raw_type = $result['type'] ?? ''; $var_type = $var_type_labels[ $raw_type ] ?? $raw_type; Mcp_Event_Dispatcher::emit( $event_by_action[ $action ], [ 'id' => $result['id'] ?? '', 'name' => $result['label'] ?? '', 'var_type' => $var_type, ] ); } } private function emit_mcp_manage_global_variable_executed( int $started_at, array $operations, ?\WP_Error $top_level_error = null, array $response = [] ): void { $duration_ms = Tool_Performance_Metrics::duration_ms_since( $started_at ); [ 'status' => $status, 'error_code' => $error_code ] = Tool_Performance_Metrics::resolve_status( $response, $top_level_error ); $failed_results = array_filter( $response['results'] ?? [], fn( $r ) => 'error' === ( $r['status'] ?? '' ) ); $failed_count = count( $failed_results ); $failed_codes = array_values( array_unique( array_column( $failed_results, 'code' ) ) ); $ops_count = count( $operations ); $by_action = []; $variable_types = []; foreach ( $operations as $op ) { $action = $op['action'] ?? ''; if ( is_string( $action ) && '' !== $action ) { $by_action[ $action ] = ( $by_action[ $action ] ?? 0 ) + 1; } } $ok_results = array_filter( $response['results'] ?? [], fn( $r ) => 'ok' === ( $r['status'] ?? '' ) ); foreach ( $ok_results as $row ) { $type = $row['type'] ?? ''; if ( is_string( $type ) && '' !== $type ) { $variable_types[ $type ] = ( $variable_types[ $type ] ?? 0 ) + 1; } } $dominant_action = ''; if ( ! empty( $by_action ) ) { arsort( $by_action ); $dominant_action = (string) array_key_first( $by_action ); } $payload = [ 'tool_name' => $this->get_ability_id(), 'status' => $status, 'duration_ms' => $duration_ms, 'action' => $dominant_action, 'operations_count' => $ops_count, 'operations_by_type' => $by_action, 'variable_types' => $variable_types, 'failed_operations_count' => $failed_count, 'failed_operation_codes' => $failed_codes, 'warning_count' => 0, 'warning_types' => [], ]; if ( null !== $error_code ) { $payload['error_code'] = $error_code; } Mcp_Event_Dispatcher::emit( 'mcp_manage_global_variable_executed', $payload ); } }
Fatal error: Uncaught Error: Class "Elementor\Modules\Mcp\Abilities\Manage_Variable_Ability" not found in /htdocs/wp-content/plugins/elementor/modules/mcp/module.php:286 Stack trace: #0 /htdocs/wp-content/plugins/elementor/modules/mcp/module.php(243): Elementor\Modules\Mcp\Module::get_core_abilities(Object(Elementor\Modules\Mcp\Registry\Ability_Registry)) #1 /htdocs/wp-content/plugins/elementor/modules/mcp/module.php(161): Elementor\Modules\Mcp\Module::build_core_registry() #2 /htdocs/wp-content/plugins/elementor/core/base/module.php(86): Elementor\Modules\Mcp\Module->__construct() #3 /htdocs/wp-content/plugins/elementor/core/modules-manager.php(64): Elementor\Core\Base\Module::instance() #4 /htdocs/wp-content/plugins/elementor/includes/plugin.php(708): Elementor\Core\Modules_Manager->__construct() #5 /htdocs/wp-content/plugins/elementor/includes/plugin.php(626): Elementor\Plugin->init_components() #6 /htdocs/wp-includes/class-wp-hook.php(353): Elementor\Plugin->init('') #7 /htdocs/wp-includes/class-wp-hook.php(377): WP_Hook->apply_filters(NULL, Array) #8 /htdocs/wp-includes/plugin.php(523): WP_Hook->do_action(Array) #9 /htdocs/wp-settings.php(779): do_action('init') #10 /htdocs/wp-config.php(106): require_once('/htdocs/wp-sett...') #11 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #12 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #13 /htdocs/index.php(17): require('/htdocs/wp-blog...') #14 {main} thrown in /htdocs/wp-content/plugins/elementor/modules/mcp/module.php on line 286