'abdielmskef', 'tab' => 'kits' ], admin_url( 'admin.php' ) ); // --- 1. PROCESS ACTIONS (POST) --- if ( isset( $_POST['abdielmskef_action'] ) && check_admin_referer( 'abdielmskef_kits_action', 'abdielmskef_nonce' ) ) { $action = sanitize_key( wp_unslash( $_POST['abdielmskef_action'] ) ); $kit_id = isset( $_POST['kit_id'] ) ? (int) $_POST['kit_id'] : 0; if ( $action === 'set_global' ) { if ( $kit_id && abdielmskef_is_kit( $kit_id ) ) { abdielmskef_set_active_kit_id( $kit_id ); // Clear Elementor CSS cache if ( class_exists( 'Elementor\\Plugin' ) ) { try { $plugin = \Elementor\Plugin::instance(); if ( isset( $plugin->files_manager ) && method_exists( $plugin->files_manager, 'clear_cache' ) ) { $plugin->files_manager->clear_cache(); } } catch ( \Throwable $e ) {} } echo '

' . esc_html__( 'Kit global actualizado.', 'abdiel-multi-style-kits-for-elementor' ) . '

'; $active_global_id = $kit_id; } } elseif ( $action === 'clone' ) { if ( $kit_id && abdielmskef_is_kit( $kit_id ) ) { $new_id = abdielmskef_clone_kit( $kit_id ); if ( $new_id ) { abdielmskef_set_flash( 'success', __( 'Kit clonado.', 'abdiel-multi-style-kits-for-elementor' ) ); // CORRECCIÓN: JS Redirect echo ''; exit; } } } elseif ( $action === 'delete' ) { if ( $kit_id && abdielmskef_is_kit( $kit_id ) ) { $all_kits = abdielmskef_query_kits(); if ( count( $all_kits ) <= 1 ) { abdielmskef_set_flash( 'error', __( 'Cannot delete because it’s the only kit in the library. Elementor requires at least one active kit.', 'abdiel-multi-style-kits-for-elementor' ) ); echo ''; exit; } $out = []; $err = ''; if ( function_exists( 'abdielmskef_delete_kit_safely' ) && abdielmskef_delete_kit_safely( (int) $kit_id, $out, $err ) ) { abdielmskef_set_flash( 'success', __( 'Kit deleted.', 'abdiel-multi-style-kits-for-elementor' ) ); } else { $msg = $err ? $err : __( 'Could not delete the kit.', 'abdiel-multi-style-kits-for-elementor' ); abdielmskef_set_flash( 'error', $msg ); } // CORRECCIÓN: JS Redirect echo ''; exit; } } elseif ( $action === 'normalize' ) { if ( $kit_id && abdielmskef_is_kit( $kit_id ) ) { abdielmskef_normalize_kit_colors( $kit_id ); abdielmskef_set_flash( 'success', __( 'Standard formatting applied (missing colors were added).', 'abdiel-multi-style-kits-for-elementor' ) ); // CORRECCIÓN: JS Redirect echo ''; exit; } } elseif ( $action === 'bulk_apply' ) { $target = sanitize_key( $_POST['bulk_target'] ?? 'pages' ); $apply_to = sanitize_key( $_POST['apply_to'] ?? 'selected' ); $post_ids = []; if ( $apply_to === 'all' ) { $pt = ( $target === 'pages_posts' ) ? [ 'page', 'post' ] : [ 'page' ]; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query $q = new WP_Query( [ 'post_type' => $pt, 'posts_per_page' => -1, 'post_status' => [ 'publish', 'draft', 'private' ], 'fields' => 'ids', ] ); $post_ids = $q->posts ?: []; } else { // SANITIZACIÓN: sanitize_text_field explícito $raw_input = isset( $_POST['post_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['post_ids'] ) ) : ''; $post_ids = array_filter( array_map( 'intval', preg_split( '/\s*,\s*/', (string) $raw_input ) ) ); } if ( (int) $kit_id === -1 ) { $kit_id = 0; } if ( ( ( $kit_id === 0 ) || ( $kit_id && abdielmskef_is_kit( $kit_id ) ) ) && ! empty( $post_ids ) ) { foreach ( $post_ids as $pid ) { if ( function_exists( 'abdielmskef_set_page_elementor_kit' ) ) { abdielmskef_set_page_elementor_kit( (int) $pid, (int) $kit_id ); } else { update_post_meta( (int) $pid, ABDIELMSKEF_META_LOCAL_KIT_ID, (int) $kit_id ); } } abdielmskef_set_flash( 'success', __( 'Batch assignment applied.', 'abdiel-multi-style-kits-for-elementor' ) ); // CORRECCIÓN: JS Redirect (Esto soluciona la página en blanco) echo ''; exit; } } } // --- 2. LIST AND TABLE --- $kits = abdielmskef_query_kits(); $kit_total = is_array( $kits ) ? count( $kits ) : 0; echo '
'; echo '

' . esc_html__( 'Gestiona tus kits (Theme Style Kits) de Elementor.', 'abdiel-multi-style-kits-for-elementor' ) . '

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ( empty( $kits ) ) { echo ''; } else { foreach ( $kits as $kit_id ) { $title = get_the_title( $kit_id ); $edit_link = admin_url( 'post.php?post=' . $kit_id . '&action=edit' ); $is_active = ( $kit_id === $active_global_id ); echo ''; echo ''; echo ''; echo ''; echo ''; } } echo '
' . esc_html__( 'Kit', 'abdiel-multi-style-kits-for-elementor' ) . '' . esc_html__( 'Estado', 'abdiel-multi-style-kits-for-elementor' ) . '' . esc_html__( 'Acciones', 'abdiel-multi-style-kits-for-elementor' ) . '
' . esc_html__( 'No kits found.', 'abdiel-multi-style-kits-for-elementor' ) . '
' . esc_html( $title ) . '
#' . (int) $kit_id . '
' . ( $is_active ? '' . esc_html__( 'Global activo', 'abdiel-multi-style-kits-for-elementor' ) . '' : '' ) . ''; echo '' . esc_html__( 'Editar', 'abdiel-multi-style-kits-for-elementor' ) . ' '; echo '
'; wp_nonce_field( 'abdielmskef_kits_action', 'abdielmskef_nonce' ); echo ''; echo ''; echo ''; echo '
'; echo '
'; wp_nonce_field( 'abdielmskef_kits_action', 'abdielmskef_nonce' ); echo ''; echo ''; echo ''; echo '
'; $export_url = wp_nonce_url( admin_url( 'admin-post.php?action=abdielmskef_export_kit&kit_id=' . (int) $kit_id ), 'abdielmskef_export_kit' ); echo '' . esc_html__( 'Exportar', 'abdiel-multi-style-kits-for-elementor' ) . ' '; echo '
'; wp_nonce_field( 'abdielmskef_kits_action', 'abdielmskef_nonce' ); echo ''; echo ''; echo ''; echo '
'; $disable_delete = ( $kit_total <= 1 ); $delete_title_attr = $disable_delete ? esc_attr__( 'Cannot delete because it’s the only kit in the library. Elementor requires at least one active kit.', 'abdiel-multi-style-kits-for-elementor' ) : ''; if ( $disable_delete ) { echo ''; } else { echo ''; } echo '
'; // --- 3. MODAL --- ?> '; echo '

' . esc_html__( 'Asignar kit por lote', 'abdiel-multi-style-kits-for-elementor' ) . '

'; echo '

' . esc_html__( 'Save the assignment on each page/post (request override).', 'abdiel-multi-style-kits-for-elementor' ) . '

'; echo '
'; wp_nonce_field( 'abdielmskef_kits_action', 'abdielmskef_nonce' ); echo ''; echo '
'; echo ''; echo '


'; echo ''; echo '


'; echo ''; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '' . esc_html__( 'Seleccionadas:', 'abdiel-multi-style-kits-for-elementor' ) . ''; echo '
'; echo '
'; echo ''; echo '
'; echo '

'; echo '
'; echo '
'; }