From e9857658fc89dd3454e5b1065858b65bff2284eb Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 8 Aug 2024 21:22:55 +0200 Subject: [PATCH] feat(admin): add lead author columns to articles and letters Introduced custom columns in the admin list view for both articles and letters to display the lead author. This enhancement improves clarity by directly showing the lead author and removes the default author column. The new columns are populated based on post metadata. --- functions.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/functions.php b/functions.php index a48dcaa..4e4fd74 100644 --- a/functions.php +++ b/functions.php @@ -1119,3 +1119,57 @@ function duck_behavior_journal_redirect_post_new() } add_action('admin_init', 'duck_behavior_journal_redirect_post_new'); + +// Add custom columns to the articles admin list view +function add_article_columns($columns) +{ + // Add a new column for the lead author + $columns['lead_author'] = __('Lead Author', 'duck-behavior-journal'); + + // Remove the default author column + unset($columns['author']); + + return $columns; +} +add_filter('manage_article_posts_columns', 'add_article_columns'); + +// Populate the custom columns for articles +function custom_article_column($column, $post_id) +{ + if ($column == 'lead_author') { + $authors = get_post_meta($post_id, 'article_authors', true); + if (!empty($authors) && is_array($authors)) { + echo esc_html($authors[0]); + } else { + echo __('Unknown', 'duck-behavior-journal'); + } + } +} +add_action('manage_article_posts_custom_column', 'custom_article_column', 10, 2); + +// Add custom columns to the letters admin list view +function add_letter_columns($columns) +{ + // Add a new column for the lead author + $columns['lead_author'] = __('Lead Author', 'duck-behavior-journal'); + + // Remove the default author column + unset($columns['author']); + + return $columns; +} +add_filter('manage_letter_posts_columns', 'add_letter_columns'); + +// Populate the custom columns for letters +function custom_letter_column($column, $post_id) +{ + if ($column == 'lead_author') { + $authors = get_post_meta($post_id, 'article_authors', true); + if (!empty($authors) && is_array($authors)) { + echo esc_html($authors[0]); + } else { + echo __('Unknown', 'duck-behavior-journal'); + } + } +} +add_action('manage_letter_posts_custom_column', 'custom_letter_column', 10, 2); \ No newline at end of file