'alba_board', 'post_title' => __('Project Alpha (Demo)', 'alba-board'), 'post_status' => 'publish', 'post_author' => get_current_user_id(), ]); if ($board_id && !is_wp_error($board_id)) { // 2. Crear las Listas $lists_names = [__('To Do', 'alba-board'), __('In Progress', 'alba-board'), __('Done', 'alba-board')]; $list_ids = []; $menu_order = 0; foreach ($lists_names as $list_title) { $list_ids[] = wp_insert_post([ 'post_type' => 'alba_list', 'post_title' => $list_title, 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'menu_order' => $menu_order++, 'meta_input' => ['alba_board_parent' => $board_id], ]); } // 3. Crear Tarjetas de Ejemplo if (count($list_ids) >= 3) { $cards_data = [ [ 'title' => __('👋 Welcome to Alba Board!', 'alba-board'), 'content' => __('This is your first card. Click me to edit the description, assign a user, or add comments.', 'alba-board'), 'list_id' => $list_ids[0], 'order' => 0 ], [ 'title' => __('🖱️ Drag and Drop me', 'alba-board'), 'content' => __('Try dragging this card to the "In Progress" list.', 'alba-board'), 'list_id' => $list_ids[0], 'order' => 1 ], [ 'title' => __('🚀 Build something awesome', 'alba-board'), 'content' => '', 'list_id' => $list_ids[1], 'order' => 0 ] ]; foreach ($cards_data as $c) { wp_insert_post([ 'post_type' => 'alba_card', 'post_title' => $c['title'], 'post_content'=> $c['content'], 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'menu_order' => $c['order'], 'meta_input' => ['alba_list_parent' => $c['list_id']], ]); } } // Redirigir al usuario al nuevo tablero para el momento "Aha!" wp_redirect(admin_url('admin.php?page=alba-board-visual&board_id=' . $board_id)); exit; } } // Handle create board if ( isset($_POST['alba_create_board']) && !empty($_POST['alba_new_board_title']) && check_admin_referer('alba_create_board_action') ) { $title = sanitize_text_field($_POST['alba_new_board_title']); $board_id = wp_insert_post([ 'post_type' => 'alba_board', 'post_title' => $title, 'post_status' => 'publish', 'post_author' => get_current_user_id(), ]); if ( $board_id && ! is_wp_error($board_id) ) { $_GET['board_id'] = $board_id; } } // Handle create list if ( isset($_POST['alba_create_list']) && !empty($_POST['alba_new_list_title']) && !empty($_POST['current_board_id']) && check_admin_referer('alba_create_list_action') ) { $title = sanitize_text_field($_POST['alba_new_list_title']); $board_id = absint($_POST['current_board_id']); wp_insert_post([ 'post_type' => 'alba_list', 'post_title' => $title, 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'meta_input' => [ 'alba_board_parent' => $board_id, ], ]); } // Handle create card (add card at end of list) if ( isset($_POST['alba_create_card'], $_POST['alba_new_card_title'], $_POST['current_list_id']) && !empty($_POST['alba_new_card_title']) && !empty($_POST['current_list_id']) && check_admin_referer('alba_create_card_action') ) { $title = sanitize_text_field($_POST['alba_new_card_title']); $list_id = absint($_POST['current_list_id']); global $wpdb; $max_menu_order = $wpdb->get_var( $wpdb->prepare( "SELECT MAX(menu_order) FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' AND ID IN ( SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'alba_list_parent' AND meta_value = %d )", 'alba_card', $list_id )); $next_menu_order = ( $max_menu_order !== null ) ? intval($max_menu_order) + 1 : 0; wp_insert_post([ 'post_type' => 'alba_card', 'post_title' => $title, 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'menu_order' => $next_menu_order, 'meta_input' => [ 'alba_list_parent' => $list_id, ], ]); } $boards = get_posts([ 'post_type' => 'alba_board', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ]); // Selected board $selected_board_id = 0; if ( isset($_GET['board_id']) ) { $selected_board_id = absint($_GET['board_id']); } elseif ( !empty($boards) ) { $selected_board_id = $boards[0]->ID; } echo '
' . esc_html__('It looks like you don\'t have any boards yet. Let\'s get you started quickly so you can see the magic in action.', 'alba-board') . '
'; echo ''; echo '' . esc_html__('No cards.', 'alba-board') . '
'; } // Show add card button per list echo ''; echo ''; echo '' . esc_html__('This board has no lists.', 'alba-board') . '
'; } } else { // Elimina el mensaje de error si no hay tableros en absoluto (ya cubierto por el Empty State) if (!empty($boards)) { echo '' . esc_html__('Invalid board.', 'alba-board') . '
'; } } } // Modal HTML for Admin Card Details ?> '; // .wrap }