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.
This commit is contained in:
parent
5522a4599e
commit
e9857658fc
1 changed files with 54 additions and 0 deletions
|
@ -1119,3 +1119,57 @@ function duck_behavior_journal_redirect_post_new()
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('admin_init', '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);
|
Loading…
Reference in a new issue