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’); } }

Troubleshooting a “You do not have sufficient permissions to access this page” error

I spent several hours of my Saturday looking for this error. I could not find a guide anywhere on the ‘net that described my eventual solution. Here is my solution. In the WP core, the “You do not have sufficient permissions to access this page.” error is generated at the end of /wp-admin/includes/menu.php. A grep … Read more

wp_update_user not updating

Im using remove_role and then add_role to upgrade a user from one role to another. Here is a function that checks all user within the user role subscriber and upgrade them to editor every hour. /** * Add a cron job that will update * Subscribers to editors. Runs hourly */ add_action(‘check_user_role’, ‘upgrade_user’); function run_check_user_role() … Read more

Filtering the Admin Comments List to Show Only Comments from the Current User?

Either of these 3 will help you: //Before getting the comments, on the WP_Comment_Query object for each comment add_action(‘pre_get_comments’, ‘wpse56652_filt_comm’); //Applied on the comments SQL Query, you can modify the ‘Where’ part of the query add_filter(‘comments_clauses’, ‘wpse56652_filt_comm’); //After the comments are fetched, you can modify the comments array add_filter(‘the_comments’, ‘wpse56652_filt_comm’); function wpse56652_filt_comm($param) { //access the … Read more

How to restrict attachment download to a specific user?

What needs to happen is that you need to proxy download requests for the file types you want through WordPress. Let’s assume you’re going to restrict access to “.doc” files. 1. Define a query variable that indicates the requested file function add_get_file_query_var( $vars ) { $vars[] = ‘get_file’; return $vars; } add_filter( ‘query_vars’, ‘add_get_file_query_var’ ); … Read more