So I have managed to come up with a solution to my problem and I thought I’d share it here.
The basic idea is to manipulate the content of the $views array, which is an associative array containing the links that make up the All, Mine, Published, Drafts (etc.) menu options in the ‘edit.php’ screen. By making sure that all keys in $views are set, it is possible to keep all menu options visible even when one or more of them have no associated posts.
The below code uses the filter views_edit-{$post-type} to access the $views array. It loops through the array and if it finds a key/post status that isn’t set (due to there being no posts with that particular status), it creates a value/link for that key.
As you can see I’ve had to create my own translations for the post status menu options (since my website is in a language other than English). Ideally I would like to use WordPress’ built-in functions for translation and localization, but I’m not sure how to go about accessing them from within the filter callback (or if this is even possible or a good idea?).
Thank you @bcworkz for your suggested filters and links, they helped put me on the right track to solving my issue. ??
Without further ado, here is the code:
add_filter('views_edit-text', 'keep_post_status_menu_options_visible');
/**
* Keep all 'post status' menu options visible all the time.
*/
function keep_post_status_menu_options_visible($views) {
$current_user = strval(get_current_user_id());
$post_statuses = array("all" => "all_posts=1",
"mine" => "author={$current_user}",
"publish" => "post_status=publish",
"future" => "post_status=future",
"draft" => "post_status=draft",
"pending" => "post_status=pending",
"private" => "post_status=private",
"trash" => "post_status=trash");
$post_statuses_translated = array("all" => "Alla",
"mine" => "Mina",
"publish" => "Publicerat",
"future" => "Tidsinst?llt",
"draft" => "Utkast",
"pending" => "Inv?ntar granskning",
"private" => "Privat",
"trash" => "Papperskorg");
foreach ($post_statuses as $status => $query_arg) {
if (!isset($views[$status])) {
$querystring = "post_type=text&{$query_arg}";
$href = admin_url("edit.php?{$querystring}");
$status_translation = $post_statuses_translated[$status];
$selected = ($querystring === $_SERVER['QUERY_STRING']) ? "class='current'" : "";
$link = "<a href='{$href}' {$selected}>{$status_translation}<span class='count'>(0)</span></a>";
$views[$status] = $link;
}
}
return $views;
}