' . esc_html($card->post_title) . '';
$due_date = get_post_meta($card->ID, 'alba_due_date', true);
if (!empty($due_date)) {
$formatted_date = date_i18n('M j', strtotime($due_date));
echo '
';
echo '
' . esc_html__('Boards', 'alba-board') . '
';
if (!empty($boards) || $is_archive_view) {
echo '
';
if ( ! $is_archive_view && ! empty( $boards ) ) {
echo '
';
}
if ( ! $is_archive_view ) {
echo '
';
echo '';
echo '
';
}
// Board management buttons
echo '
';
echo '
';
// Inline form for board creation
if ( ! $is_archive_view ) {
echo '
';
}
} else {
echo '
';
echo '
' . esc_html__('Welcome to Alba Board! 🎉', 'alba-board') . '
';
echo '';
}
if ( $is_archive_view ) {
alba_board_render_archived_cards();
} elseif ($selected_board_id) {
$board = (object) get_post($selected_board_id);
if ($board && isset($board->post_type) && $board->post_type === 'alba_board') {
echo '
' . esc_html($board->post_title) . '
';
$lists = get_posts(['post_type' => 'alba_list', 'numberposts' => -1, 'meta_key' => 'alba_board_parent', 'meta_value' => $board->ID, 'orderby' => 'menu_order', 'order' => 'ASC']);
$cards_by_list = alba_board_get_cards_grouped_by_list( wp_list_pluck( $lists, 'ID' ) );
echo '
';
if ($lists) {
foreach ($lists as $list) {
$list = (object) $list;
echo '
';
}
}
echo '
';
$add_list_text = empty($lists) ? __('Add List', 'alba-board') : __('Add another list', 'alba-board');
echo '
';
echo '
';
}
}
?>
';
echo '
';
}
/**
* 3. AJAX LIST HANDLERS
*/
add_action('wp_ajax_alba_delete_list_action', function() {
check_ajax_referer('alba_delete_list_nonce', 'nonce');
$list_id = isset($_POST['list_id']) ? absint($_POST['list_id']) : 0;
if (!$list_id || 'alba_list' !== get_post_type($list_id) || !current_user_can('delete_list', $list_id)) {
wp_send_json_error(['message' => esc_html__('Permission denied.', 'alba-board')], 403);
}
$cards = get_posts([
'post_type' => 'alba_card',
'numberposts' => -1,
'meta_key' => 'alba_list_parent',
'meta_value' => $list_id,
]);
foreach ($cards as $card) {
if (!current_user_can('edit_card', $card->ID)) {
wp_send_json_error(['message' => esc_html__('You cannot archive every card in this list.', 'alba-board')], 403);
}
}
foreach ($cards as $card) {
if (!alba_board_archive_card($card->ID)) {
wp_send_json_error(['message' => esc_html__('Could not archive a card in this list.', 'alba-board')], 500);
}
}
if (!wp_trash_post($list_id)) {
wp_send_json_error(['message' => esc_html__('Could not delete this list.', 'alba-board')], 500);
}
wp_send_json_success();
});
add_action('wp_ajax_alba_move_list_action', function() {
check_ajax_referer('alba_move_list_nonce', 'nonce');
// Preserve array shape so malformed/nested input is rejected by strict validation below.
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$raw_orders = isset($_POST['order']) && is_array($_POST['order']) ? wp_unslash($_POST['order']) : [];
if (!$raw_orders) {
wp_send_json_error(['message' => esc_html__('No list order was provided.', 'alba-board')], 400);
}
$list_orders = [];
$seen_lists = [];
foreach ($raw_orders as $position => $raw_list_id) {
if (!is_scalar($position) || !preg_match('/^\d+$/', (string) $position) || !is_scalar($raw_list_id) || !preg_match('/^[0-9]+$/', (string) $raw_list_id)) {
wp_send_json_error(['message' => esc_html__('Invalid list order.', 'alba-board')], 400);
}
$position = absint($position);
$list_id = absint($raw_list_id);
if (
!$list_id ||
'alba_list' !== get_post_type($list_id) ||
'publish' !== get_post_status($list_id) ||
!current_user_can('edit_list', $list_id) ||
isset($seen_lists[$list_id]) ||
isset($list_orders[$position])
) {
wp_send_json_error(['message' => esc_html__('Invalid list order or permission denied.', 'alba-board')], 403);
}
$seen_lists[$list_id] = true;
$list_orders[$position] = $list_id;
}
ksort($list_orders, SORT_NUMERIC);
if (array_keys($list_orders) !== range(0, count($list_orders) - 1)) {
wp_send_json_error(['message' => esc_html__('Invalid list order.', 'alba-board')], 400);
}
foreach ($list_orders as $position => $list_id) {
$list = get_post( $list_id );
if ( ! $list || (int) $list->menu_order === $position ) {
continue;
}
$updated = wp_update_post(['ID' => $list_id, 'menu_order' => $position], true);
if (is_wp_error($updated) || !$updated) {
wp_send_json_error(['message' => esc_html__('Could not save the list order.', 'alba-board')], 500);
}
}
wp_send_json_success();
});