'edit_boards', 'alba_create_board' => 'edit_boards', 'alba_create_list' => 'edit_lists', 'alba_create_card' => 'edit_cards' ] as $field => $capability ) { if ( isset( $_POST[$field] ) && ! current_user_can( $capability ) ) wp_die( esc_html__( 'Permission denied.', 'alba-board' ), '', [ 'response' => 403 ] ); } if ( isset( $_POST['alba_create_card'] ) ) { $parent_list = isset( $_POST['current_list_id'] ) ? absint( $_POST['current_list_id'] ) : 0; if ( 'alba_list' !== get_post_type( $parent_list ) || 'publish' !== get_post_status( $parent_list ) || ! current_user_can( 'edit_list', $parent_list ) ) wp_die( esc_html__( 'Invalid list or permission denied.', 'alba-board' ), '', [ 'response' => 403 ] ); } if ( isset($_POST['alba_create_demo_board']) && check_admin_referer('alba_create_demo_board_action') ) { $board_id = wp_insert_post([ 'post_type' => '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)) { $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] ]); } if (count($list_ids) >= 3) { $cards_data = [ ['title' => __('👋 Welcome!', 'alba-board'), 'content' => '', 'list_id' => $list_ids, 'order' => 0], ['title' => __('🖱️ Drag me', 'alba-board'), 'content' => '', 'list_id' => $list_ids, 'order' => 1] ]; 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']] ]); } } wp_safe_redirect(admin_url('admin.php?page=alba-board-visual&board_id=' . $board_id)); exit; } } if ( isset($_POST['alba_create_board']) && !empty($_POST['alba_new_board_title']) && check_admin_referer('alba_create_board_action') ) { $board_id = wp_insert_post([ 'post_type' => 'alba_board', 'post_title' => sanitize_text_field(wp_unslash($_POST['alba_new_board_title'])), 'post_status' => 'publish', 'post_author' => get_current_user_id() ]); if ( $board_id && ! is_wp_error($board_id) ) { wp_safe_redirect(admin_url('admin.php?page=alba-board-visual&board_id=' . $board_id)); exit; } } if ( isset($_POST['alba_create_list']) && !empty($_POST['alba_new_list_title']) && !empty($_POST['current_board_id']) && check_admin_referer('alba_create_list_action') ) { $board_id = absint($_POST['current_board_id']); global $wpdb; $max_list_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_board_parent' AND meta_value = %d)", 'alba_list', $board_id) ); $new_list_order = (($max_list_order !== null) ? intval($max_list_order) + 1 : 0); $list_id = wp_insert_post([ 'post_type' => 'alba_list', 'post_title' => sanitize_text_field(wp_unslash($_POST['alba_new_list_title'])), 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'menu_order' => $new_list_order, 'meta_input' => ['alba_board_parent' => $board_id] ]); if ( $list_id && ! is_wp_error($list_id) ) { wp_safe_redirect(admin_url('admin.php?page=alba-board-visual&board_id=' . $board_id)); exit; } } 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') ) { $list_id = absint($_POST['current_list_id']); $board_id = isset($_POST['current_board_id']) ? absint($_POST['current_board_id']) : 0; 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)); $card_id = wp_insert_post([ 'post_type' => 'alba_card', 'post_title' => sanitize_text_field(wp_unslash($_POST['alba_new_card_title'])), 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'menu_order' => (($max_menu_order !== null) ? intval($max_menu_order) + 1 : 0), 'meta_input' => ['alba_list_parent' => $list_id] ]); if ( $card_id && ! is_wp_error($card_id) ) { wp_safe_redirect(admin_url('admin.php?page=alba-board-visual' . ($board_id ? '&board_id=' . $board_id : ''))); exit; } } } /** * 2. UI LAYER (Rendering Only) */ function alba_render_admin_board_page() { $boards = get_posts(['post_type' => 'alba_board', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC']); $selected_board_id = 0; if ( isset($_GET['board_id']) ) { $selected_board_id = absint($_GET['board_id']); } elseif ( !empty($boards) ) { $first_board = (object) reset($boards); $selected_board_id = $first_board->ID; } $is_archive_view = isset( $_GET['view'] ) && 'archived' === sanitize_key( wp_unslash( $_GET['view'] ) ); $display_opts = get_option('alba_board_display', ['show_avatars' => 1, 'theme' => 'default']); $show_avatars = !empty($display_opts['show_avatars']); $theme_class = isset($display_opts['theme']) ? 'alba-theme-' . $display_opts['theme'] : 'alba-theme-default'; echo '
' . esc_html__('No cards.', 'alba-board') . '
'; echo '