Update January 1, 2022 (Happy New Year):
Cindi wrote in asking how to restrict the link to “drafts” in the menu to admin-level users only. I accomplished this by tucking the function inside an “if” statement that reads like this: “if(current_user_can( ‘administrator’ )){……[rest of code….].”
Below is the full, new function restricting the link to drafts to admin-level users only:
<?php /* Plugin Name: Drafts Link in Posts Menu Plugin URI: https://davidwalsh.name/wordpress-admin-add-menu-item Description: Adds a link to draft items from the Posts admin menu. hellotumo.com took David's work and made it into a plugin. Version 2 restricts to admin users only. Version: 2.0 */ function add_drafts_admin_menu_item() { if(current_user_can( 'administrator' )){ add_posts_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=post'); add_pages_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=page'); } /*close if statement*/ } /*close whole function*/ add_action('admin_menu', 'add_drafts_admin_menu_item'); ?>
David Walsh has the secret sauce for getting a link to your post drafts in the posts menu option of your WordPress site. Yes!
I built upon his work and created a custom plugin that does the same. Why?
Because I hate it when a site update wipes out my functions.php custom code. By using a plugin, you can keep this handy-dandy shortcut secure amid the next upgrade.
To do this, just copy the code below into a text file, save it as yourspecialsecretsauce.php, drop it into your plugins directory, and activate it. The original full code of version 1 is below:
<?php /* Plugin Name: Drafts Link in Posts Menu Plugin URI: https://davidwalsh.name/wordpress-admin-add-menu-item Description: Adds a link to draft items from the Posts admin menu. hellotumo.com took David's work and made it into a plugin. Version: 1.0 */ function add_drafts_admin_menu_item() { // $page_title, $menu_title, $capability, $menu_slug, $callback_function /* add_posts_page(__('Drafts'), __('Drafts'), 'read', 'edit.php?post_status=draft&post_type=post'); add_pages_page(__'Drafts'), __('Drafts'), 'read', 'edit.php?post_status=draft&post_type=page'); } */ // $page_title, $menu_title, $capability, $menu_slug, $callback_function add_posts_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=post'); add_pages_page('Drafts', 'Drafts', 'read', 'edit.php?post_status=draft&post_type=page'); } add_action('admin_menu', 'add_drafts_admin_menu_item'); ?>
Is there a way to make the drafts show ONLY for admins? I run a membership site so almost everyone is logged in.
Hi Cindi – Thanks for the question. I reworked the plugin to restrict the display to admin-level users. You can read the details at the top of this post. Look for “Update January 1, 2022 (Happy New Year).”
Cindi, there are plugins that also allow you to manage user roles and their access level. That might also help you refine what different types of users can see. Here is a post about that: https://blog.hubspot.com/website/wordpress-user-roles
Where is the code??
The PHP code got stripped out during some update. You can see it now.