Restrict admin access to certain pages for certain users

This code seems to work well for me (in functions.php): $user_id = get_current_user_id(); if ($user_id == 2) { add_filter( ‘parse_query’, ‘exclude_pages_from_admin’ ); } function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow==’edit.php’ && $post_type ==’page’) { $query->query_vars[‘post__not_in’] = array(‘123′,’234′,’345’); } }

Add header and footer to WP backend

The in_admin_header action may be used to insert content before <div id=”wpbody”> in the wordpress backend. See Line 101 of /wp-admin/admin-header.php (line number as of version 3.3.2) Further reading on actions: Action Reference, codex

How to obtain the user ID of the current profile being edited in WP-Admin?

There is a global variable called … $user_id available on that page. Always. From user-edit.php: $user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( ‘IS_PROFILE_PAGE’ ) ) define( ‘IS_PROFILE_PAGE’, ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; elseif ( ! $user_id && ! IS_PROFILE_PAGE ) … Read more

Remove “Time to upgrade” message from dashboard

How to hide WordPress update mesages CSS The low-tech way to hide something is using css: // Low-tech hiding of update-mesages // source: http://wpsnipp.com/index.php/functions-php/hide-update-nag-within-the-admin/ function remove_upgrade_nag() { echo ‘<style type=”text/css”> .update-nag {display: none} </style>’; } add_action(‘admin_head’, ‘remove_upgrade_nag’); This more-or-less works, but it is a lot of work to find al the places WordPress shows messages. … Read more

How to stop showing admin notice after close button has been clicked

Two ways to handle this. a. Attach a timer to the notice: You could attach a 3-second timer (or however long you wish) to the notice, as follows: <?php set_transient( “my-plugin”, “alive”, 3 ); add_action( ‘admin_notices’, function() { //Syntax correction if ( “alive” == get_transient( “my-plugin” ) ) { ?> <div class=”notice notice-success is-dismissible”> <p><?php … Read more

How to remove comments option from wp-admin bar and modify profile icon

To remove the comments menu from the top admin bar you can use the $wp_admin_bar global and the remove_menu() method like this: function my_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->remove_menu(‘comments’); } add_action( ‘wp_before_admin_bar_render’, ‘my_admin_bar_render’ ); As for changing the icon on the settings section of the left admin menu, you can modify the dashicon that is used … Read more

How do I change the login logo URL and hover title?

Try these filters instead // changing the logo link from wordpress.org to your site function mb_login_url() { return home_url(); } add_filter( ‘login_headerurl’, ‘mb_login_url’ ); // changing the alt text on the logo to show your site name function mb_login_title() { return get_option( ‘blogname’ ); } add_filter( ‘login_headertitle’, ‘mb_login_title’ ); Though if you’re on a Network/MultiSite … Read more