You mention user ‘status’….are you looking to show/hide the menu for classes of users (by role/capability) rather than individual users (by ID)?
I do something similar so that users below a level cannot access certain back-end menu items, using current_user_can and !current_user_can.
As an example, this checks to see if a user is an Editor or higher, and if not does not allow the user to see ANY Posts except their own (default WP behavior is to show all Posts but only allow them to edit their own, we don’t want them to even see others’ Posts).
add_action( 'load-edit.php', 'posts_for_current_contributor' );
function posts_for_current_contributor() {
global $user_ID;
if ( !current_user_can( 'delete_others_posts' ) ) {
if ( ! isset( $_GET['author'] ) ) {
wp_redirect( add_query_arg( 'author', $user_ID ) );
exit;
}
}
}
You can learn more about Roles & Capabilities with some other examples here:
https://codex.wordpress.org/Roles_and_Capabilities
Related Posts:
- Difference Between Filter and Action Hooks?
- Which hook should be used to add an action containing a redirect?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How Do I Load My Action Earlier Enough?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- How can I hook into existing WordPress Bulk actions?
- Hook event for upload image in the menu
- Define a function outside a class and call the function using action or filter hook
- Create a plugin to change the action to which a function is hooked
- Modifying values with add_action to be sent to db
- Woocommerce – Hide a Column in Cart Table
- Hook to get image filename when it is uploaded
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Namespaced action and filter tags
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- I have 2 plugins using the same wp_login action hook and one is not working
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to get all queries’s results after they have executed?
- Bug: Post needs to be updated twice when adding action for save_post hook
- When does save_post hook fire on post save/update
- Add child pages to submenu automatically
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- How to find list of all functions bind to a particular hook from my plugin?
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- add_option_{$option} action hook not being called
- Does WordPress have something like timer hook?
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- Insert plugin html content to a specific spot in the frontpage
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?
- How to override existing plugin action with new action
- Change the_title() of a page dynamically
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- WordPress scheduled task is called but not executed
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How to modify post content before writing to database?
- Plugin development, hooks, generate content
- When is it too late to call the action wp_enqueue_scripts?
- Odd behaviour with submenu link creation
- Help with callback using do_action_ref_array
- What is the Difference between directly call a function and call a function using add_action?
- How to register custom post types in a plugin?
- Is it possible to add an action to the currently running action?
- Best Practices for Creating and Handling Forms with Plugins?
- Is there a better way to implement responsive images than what WordPress uses by default?
- How to prevent action in ajax request, when in admin side?
- How to add pages to custom menus on the fly [duplicate]
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- Trying to understand order and frequency of action hooks firing
- Remove unwanted elements for a wp_nav_menu
- wp_set_object_terms not updating database without a die()
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- How to remove or add submenu item on plugin activate or deactive
- Adding function to Genesis genesis_header [closed]
- template_redirect or admin-ajax.php?
- Show error message after exception handled
- Delete data from database using row action
- Remove an action by extending class and replacing it
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- Why enqueue styles on hook?
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Hide one specific woocoomerce product
- How to add Plugin functionality in WordPress Frontend Menus
- How to hide page links from theme menu
- WP_NAV_MENU filter targets all menus
- Redirect returning users to a certain page?
- Adding tables to dashboard pages programmatically?
- I cannot include a file in my plugin settings page
- Set the payment processor callbacks to a plugin
- How to update global variables in plugin activation callback?
- Add two button to page and post admin to redirect to : add new & list of (posts – pages) just after saving post or page
- Where do I hook to have the server do something in PHP on block attribute change?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Add a custom submenu under submenu in a Custom WordPress Plugin
- Post is uncatagorized in publish_post action
- How do I remove an action hook inside a class that is called by another class?
- WordPress Reset password Strength set to medium
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- plugin modal/popup integration best practice
- Create and style menu
- Get user logged in status from within a plugin. $current_user not defined
- How wordpress plugin hooks works? [duplicate]
- Send Webhook when post-status is publish or trash
- Using “add_image_size” to register custom image sizes inside plugins not working
- wp_head is not fired from the hook I have used in my plugin
- Trigger a JavaScript function based on the data fetched from Woo commerce hook