How to restrict an admin page, if the user is not superadmin?

To remove from the admin menu, you could use remove_menu_page(): add_action( ‘admin_menu’, function ( ) { if (is_super_admin()) return; remove_menu_page(); // or remove_submenu_page( … },99); If for some reason the page still exists, it’s just missing it’s menu link, you could check the get_current_screen() to see if the page is being viewed, and prevent access: …

Read more

Change user role of a particular user at specific time

You can do something like this add_action(“after_switch_theme”, “schedule_cron_job”); // hook the schedule on theme switch or plugin activation based on the your usage also switch your theme after putting this on functions.php function schedule_cron_job(){ if (! wp_next_scheduled ( ‘import_into_db’ )) { wp_schedule_event(strtotime(’12:04:00′), ‘daily’, ‘import_into_db’); } } add_action(‘import_into_db’, ‘your_cron_job’); // You were hooking to wp function …

Read more

Block user roles from accessing the WordPress dashboard

You can make an array of the roles that need to be blocked, and use array_intersect() to check if the current user is in any of those roles. function wpse66094_no_admin_access() { $redirect = isset( $_SERVER[‘HTTP_REFERER’] ) ? $_SERVER[‘HTTP_REFERER’] : home_url( “https://wordpress.stackexchange.com/” ); global $current_user; $blocked_roles = array( ‘shopkeeper’, ‘block-this-role’, ‘block-this-role-too’ ); $user_roles = $current_user->roles; // …

Read more

Hide Users by user role in Worpress

you could use wp_list_authors for list your authors in your user page. Put a look here: https://codex.wordpress.org/Function_Reference/wp_list_authors Does it help you? EDIT: According to our communications: $users_array = array(); $users = get_users(‘role=author’); if(count($users) > 0){ foreach($users as $user){ $users_array[] = $user->ID; } } add $users_array instead of array(1, 3, 5) …

How to exclude subscriber from the list in wordpress

working code ..thx @michael <?php $number = 10; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $offset = ($paged – 1) * $number; $users = get_users(); $query = get_users(‘&offset=”.$offset.”&number=”.$number.”&role__not_in=’.subscriber); $total_users = count($users); $total_query = count($query); $total_pages = intval($total_users / $number) + 1; echo ‘<ul id=”list-mitra”>’; foreach($query as $q) { ?> <li class=”bullet-arrow”> <a href=”#mitra<?php echo get_the_author_meta( …

Read more