• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

I want to restrict access of an user (ref. pic given)

To change the admin login page is easy, too, but to be honest: I would never put my logo there, but instead the logo of the website. Anyway, you can do it with this bit of code:

PHP:
function my_login_logo() { ?>
<style type="text/css">body,.login form{background:#FFF!important}#login h1 a {background-image:url(/path/to/logo.png);background-size:320px;width:320px}#login{padding-top:4%!important}.login #backtoblog,.login #nav,.login form .forgetmenot{display:none}.login form{box-shadow:unset!important}</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
function my_login_logo_url(){return home_url();}
add_filter( 'login_headerurl', 'my_login_logo_url' );
function my_login_logo_url_title(){return 'YOUR OWN CUSTOM TEXT (only visible on hover)';}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );

The above code assumes a logo with a width of 320px, change accordingly.
It also removes the 'Remember Me' checkbox, and the links 'Lost your password?' and to the Home Page of the website.
 
  • Like
Reactions: DarKMaSk
@frizzel I have downloaded the plugin 'Admin Menu Edito Pro' from your link and installed it. The options there are really overwhelming. Now please tell me, will this 'mu-plugin', on which you have been guiding me, work for every user-role or it can be used on only selected user-roles?
 
To change the admin login page is easy, too, but to be honest: I would never put my logo there, but instead the logo of the website.

Yes. On second thought, I have decided to put the name & logo of the website because it is their website, not mine. I can put my logo and a link in the Admin Dashboard footer to make them remember me, but not on the Admin login page.

Anyway, you can do it with this bit of code:

PHP:
function my_login_logo() { ?>
<style type="text/css">body,.login form{background:#FFF!important}#login h1 a {background-image:url(/path/to/logo.png);background-size:320px;width:320px}#login{padding-top:4%!important}.login #backtoblog,.login #nav,.login form .forgetmenot{display:none}.login form{box-shadow:unset!important}</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
function my_login_logo_url(){return home_url();}
add_filter( 'login_headerurl', 'my_login_logo_url' );
function my_login_logo_url_title(){return 'YOUR OWN CUSTOM TEXT (only visible on hover)';}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );

The above code assumes a logo with a width of 320px, change accordingly.
It also removes the 'Remember Me' checkbox, and the links 'Lost your password?' and to the Home Page of the website.
Thanks a lot but I think I should leave that checkbox & links there, for just in case. ☺
 
@frizzel My question might look as a dumb,but I have to ask it anyway. Can you please tell me whether this 'mu-plugin' work for every user-role or it can be configured to work for some specific user-role?
 
Give this plugin a try :

White Label – Custom Login & More
White Label is made for those who want to customize their WordPress site. The free version is particularly good for those with clients who have the Editor role.

  • Easy replace the default logo with your own on the WordPress login screen.
  • Custom background color for the login screen.
  • Custom background image for the WordPress login screen.
  • Login page templates & color picker.
  • Custom CSS for the login page.
  • Set up a custom dashboard Widget with the visual editor.
  • Customize the WordPress dashboard page with the visual editor.
  • Add live chat or custom Javascript script to the admin area.
  • Change the welcome message a.k.a. ‘Howdy’.
  • Hide the WordPress admin bar logo.
  • Replace the WordPress admin bar logo with your own.
  • Change the admin footer credit.
  • Hide admin menus & plugins from other administrators.
  • Select multiple White Label administrators that can bypass rules.


Or this one :

White Label CMS
The White Label CMS plugin is for developers who want to give their clients a more personalised and less confusing content management system.

For a overview of the changes in 2.0 version of the plugin please visit the Video User Manuals website.

FEATURES
  • Customize the login page
  • Add your branding to the header and footer
  • Customize the dashboard
  • Control which menus appear for your client
  • Setting up a customized dashboard can be done in seconds using the White Label CMS Wizard
 
  • Like
Reactions: DarKMaSk
@frizzel My question might look as a dumb,but I have to ask it anyway. Can you please tell me whether this 'mu-plugin' work for every user-role or it can be configured to work for some specific user-role?
Yes, you already have it in the code you shared previously. Just wrap the code in an 'if' statement:

PHP:
$user_id = get_current_user_id();
if($user_id !== 1){
    // the code for all users except with ID 1
}

or if you want to do something based on user roles:

PHP:
$user = wp_get_current_user();
$allowed_roles = array( 'editor', 'administrator', 'author' );
if ( array_intersect( $allowed_roles, $user->roles ) ) {
   // the code for allowed users here
}

And here is a list of all roles and capabilities in WordPress.
 
  • Like
Reactions: DarKMaSk
Give this plugin a try :

White Label – Custom Login & More
White Label is made for those who want to customize their WordPress site. The free version is particularly good for those with clients who have the Editor role.

  • Easy replace the default logo with your own on the WordPress login screen.
  • Custom background color for the login screen.
  • Custom background image for the WordPress login screen.
  • Login page templates & color picker.
  • Custom CSS for the login page.
  • Set up a custom dashboard Widget with the visual editor.
  • Customize the WordPress dashboard page with the visual editor.
  • Add live chat or custom Javascript script to the admin area.
  • Change the welcome message a.k.a. ‘Howdy’.
  • Hide the WordPress admin bar logo.
  • Replace the WordPress admin bar logo with your own.
  • Change the admin footer credit.
  • Hide admin menus & plugins from other administrators.
  • Select multiple White Label administrators that can bypass rules.


Or this one :

White Label CMS
The White Label CMS plugin is for developers who want to give their clients a more personalised and less confusing content management system.

For a overview of the changes in 2.0 version of the plugin please visit the Video User Manuals website.

FEATURES
  • Customize the login page
  • Add your branding to the header and footer
  • Customize the dashboard
  • Control which menus appear for your client
  • Setting up a customized dashboard can be done in seconds using the White Label CMS Wizard
This plugin is too complicated to use. I have tried it.
 
or if you want to do something based on user roles:

PHP:
$user = wp_get_current_user();
$allowed_roles = array( 'editor', 'administrator', 'author' );
if ( array_intersect( $allowed_roles, $user->roles ) ) {
   // the code for allowed users here
}
I think this one is better because I can associate it with specific user role and with this one, I don't have to use any plugin for this purpose. As I would have only 1 user (other than me), the client himself, it would be better if the menu restrictions would also be integrated here. But as a plugin, the 'Menu Editor Pro' is doing a good job on menu restrictions and customization of admin login page.
 
  • Like
Reactions: Mscv50
Yes, you already have it in the code you shared previously. Just wrap the code in an 'if' statement:

PHP:
$user_id = get_current_user_id();
if($user_id !== 1){
    // the code for all users except with ID 1
}
This one is giving no error, whereas,
or if you want to do something based on user roles:

PHP:
$user = wp_get_current_user();
$allowed_roles = array( 'editor', 'administrator', 'author' );
if ( array_intersect( $allowed_roles, $user->roles ) ) {
   // the code for allowed users here
}
this one is giving a 'FATAL ERROR' which is as follows:

"Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in C:\xampp\htdocs\aranyak\wp-content\mu-plugins\restrict.php:18 Stack trace: #0 C:\xampp\htdocs\aranyak\wp-settings.php(322): include_once() #1 C:\xampp\htdocs\aranyak\wp-config.php(91): require_once('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\aranyak\wp-load.php(37): require_once('C:\\xampp\\htdocs...') #3 C:\xampp\htdocs\aranyak\wp-admin\admin.php(34): require_once('C:\\xampp\\htdocs...') #4 C:\xampp\htdocs\aranyak\wp-admin\options-general.php(10): require_once('C:\\xampp\\htdocs...') #5 {main} thrown in C:\xampp\htdocs\aranyak\wp-content\mu-plugins\restrict.php on line 18

There has been a critical error on this website. Please check your site admin email inbox for instructions."

Am I doing anything wrong?! I just copied and paste both the code from here. I put the rest of the code in that file inside those { } braces in both the cases.
 
@frizzel Here is the full code of my 'restrict.php' file:

PHP:
<?php

/*
Plugin Name: MU-Plugin
Description: Must Use custom functions plugin
Author: frizzel
*/


$user_id = get_current_user_id();
if($user_id !== 1){
    // the code for all users except with ID 1




/*$user = wp_get_current_user();
$allowed_roles = array( 'editor', 'administrator', 'author' );
if ( array_intersect( $allowed_roles, $user->roles ) ) {
   // the code for allowed users here

*/
show_admin_bar(false);

function customize_my_wp_admin_bar( $wp_admin_bar ) {
    $node = $wp_admin_bar->get_node('site-name');
    $node->meta['target'] = '_blank';
    $node->title = 'Home Page';
    $wp_admin_bar->add_node($node); 
    $wp_admin_bar->remove_node('updates');
    $wp_admin_bar->remove_node('comments');
    $wp_admin_bar->remove_node('new-content');
    $wp_admin_bar->remove_node('wp-logo');
    $wp_admin_bar->remove_node('view-site');
}
add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 999 );

function wporg_remove_all_dashboard_metaboxes() {
    remove_action('welcome_panel','wp_welcome_panel');
    remove_meta_box('dashboard_primary','dashboard','side');
    remove_meta_box('dashboard_quick_press','dashboard','side');
    remove_meta_box('dashboard_site_health','dashboard','normal');
    remove_meta_box('dashboard_right_now','dashboard','normal');
    remove_meta_box('dashboard_activity','dashboard','normal');
    remove_meta_box('e-dashboard-overview','dashboard','normal'); // WooCommerce 
    remove_meta_box('wpdm_dashboard_widget','dashboard','normal');
  
}
add_action( 'wp_dashboard_setup', 'wporg_remove_all_dashboard_metaboxes' );

function remove_screen_options(){
   return current_user_can( 'manage_options' );
}
add_filter('screen_options_show_screen', 'remove_screen_options');

function oz_remove_help_tabs( $old_help, $screen_id, $screen ){
    $screen->remove_help_tabs();
    return $old_help;
}
add_filter( 'contextual_help', 'oz_remove_help_tabs', 999, 3 );

add_action("admin_head" , function(){
   echo "<style>#dashboard-widgets-wrap .empty-container{display:none}</style>";
});

// Customizing the default WordPress logo on the Admin Header

function add_my_own_logo( $wp_admin_bar ) {
    $args = array(
        'id'    => 'my-logo',
        'meta'  => array( 'class' => 'my-logo', 'title' => 'logo' )
    );
    $wp_admin_bar->add_node( $args );
}
add_action( 'admin_bar_menu', 'add_my_own_logo', 1 );



// Customizing the Default footer of Admin Dashboard
function remove_footer_admin () {
return 'Welcome to SD Hotel Booking System';
}
add_filter('admin_footer_text', 'remove_footer_admin', 99);

function remove_footer_update () {
return 'Version 1.0';
}
add_filter('update_footer', 'remove_footer_update', 99);

// CSS for styling and path of my own logo instead of default WordPress Logo on the Admin Header

/*#wp-admin-bar-my-logo div{
    background-image: url( /path/to/your/logo.png );
    background-repeat: no-repeat;
    background-size: 20px;
    background-position: center;
    margin-left:10px!important;
} */
}
 
Use one or the other for restrictions, not both and certainly not 'stacked' (as you seem to have done in your restrict.php).
Since you only have one other user, I'd go for the restrictions by ID any time.
 
Use one or the other for restrictions, not both and certainly not 'stacked' (as you seem to have done in your restrict.php).
I haven't use both of them at once. As you have seen that though I've both the codes in the file but I've commented out one. Both codes cannot work side by side, it's just common sense. So, I tested them one by one and got that 'Fatal error' when using the second code.

Since you only have one other user, I'd go for the restrictions by ID any time.
I've also thought about that but I want to know what happened with the second one. Better to have two alternatives than one, just in case.
 
Reference image:

restrict-access.jpg

@frizzel Friend, with your code (using the restrictions by ID) and 'Menu Editor Pro' all are working just like I wanted, except that 'Theme Setting' at the top of the page. It is still there. Can you please guide me how to find that link or node, whatever it is so that it can be removed for that particular user-role?
 
@frizzel Friend, with your code (using the restrictions by ID) and 'Menu Editor Pro' all are working just like I wanted, except that 'Theme Setting' at the top of the page. It is still there. Can you please guide me how to find that link or node, whatever it is so that it can be removed for that particular user-role?
Try this code:

PHP:
function remove_hoteller_from_admin_bar( $wp_admin_bar ) {
    $wp_admin_bar->remove_menu( 'hoteller_admin' );
}
add_action( 'admin_bar_menu', 'remove_hoteller_from_admin_bar', 2200 );

The theme adds this admin bar menu item with priority '2000'. To remove that action you have to set a priority that's higher in order to make it run AFTER the theme's action. And there you have your answer what that figure '2200' is for.
 
  • Like
Reactions: DarKMaSk
I want to know what happened with the second one. Better to have two alternatives than one, just in case.

Apparently, 'wp_get_current_user()' can only work when wrapped inside an init hook function, because it is included later on by WordPress. This does not apply to the other example which uses 'get_current_user_id()'. WordPress sometimes works in mysterious ways...

Anyway, I've learned something as well and the code should be:

PHP:
function restrict_access(){
  $user = wp_get_current_user();
  $allowed_roles = array( 'editor', 'administrator', 'author' );
    if ( array_intersect( $allowed_roles, $user->roles ) ) {
       // the code for allowed users here
    }
}
add_action('init','restrict_access');
 
  • Like
Reactions: DarKMaSk
Try this code:

PHP:
function remove_hoteller_from_admin_bar( $wp_admin_bar ) {
    $wp_admin_bar->remove_menu( 'hoteller_admin' );
}
add_action( 'admin_bar_menu', 'remove_hoteller_from_admin_bar', 2200 );

The theme adds this admin bar menu item with priority '2000'. To remove that action you have to set a priority that's higher in order to make it run AFTER the theme's action. And there you have your answer what that figure '2200' is for.
Ok. Now the question is, how could I know, this 'priority' thingy?
 
If you check the Theme Setting link, you can see it has an id of 'hoteller_admin'. That's what I searched for in the theme and found where it was added and what priority it has. FYI, it's added on line 721 in /hoteller/lib/theme.filter.lib.php with this:

PHP:
add_action('admin_bar_menu', 'hoteller_create_admin_menu', 2000);

Of course these priorities are always different and sometimes there's no priority at all. It goes a bit too far and is also far beyond the scope of this thread to explain everything about priorities. Just search for 'wordpress', 'php', 'priorities', 'hooks', 'filters', and you'll find lots of information.
 
  • Like
Reactions: DarKMaSk
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock