You could try following:
$current_user = wp_get_current_user();
if( user_can( $current_user, 'main-admin' ) ) {
// Do your stuff
}
For more info please read in the Codex about:
user_can
,wp_get_current_user
Edit: my mistake, was reading wrong, I thought you meant a custom role main-admin.
Not to make my mistake suddenly as correct, but maybe you create a role where the user belongs to. (is maybe even easier to manage?)
Add-on Trying to give an correct answer/option now.
There are several ways/options to achieve your goal below are 2:
Knowing the name makes it able to use: get_currentuserinfo()
global $current_user;
get_currentuserinfo();
if ( $current_user->user_lastname ) {
// Do your stuff
}
Codex:
get_currentuserinfo
When you know the user id you could use get_current_user_id()
:
$user_id = get_current_user_id();
if ( $user_id == 5 ) { // add correct id
// Do your stuff
}
Codex:
get_current_user_id
As mentioned you can also create a custom role with administrator caps, which is explained here by @RutwickGangurde. To keep the answer here complete I added the code here.
NB: The setting is saved to the database (in table wp_options, field wp_user_roles), so it needs to run only once
I personally use a Class in functions.php
to be sure a certain function only runs once, which in this case is a must!
Add both functions into your functions.php
(make first a copy!)
class run_once
{
function run( $key )
{
$scenario = get_option( 'run_once' );
if ( isset( $scenario[$key] ) && $scenario[$key] )
{
return false;
}
else {
$scenario[$key] = true;
update_option( 'run_once', $scenario );
return true;
}
} // end function
} // end class
// Now use the class with this function (which will only run once!)
$run_once = new run_once;
if ( $run_once->run( 'cloneRole' ) )
{
function cloneRole()
{
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$adm = $wp_roles->get_role( 'administrator' );
//Adding a 'new_role' with all admin caps
$wp_roles->add_role( 'main-admin', 'Main Admin', $adm->capabilities );
} // end Function
add_action( 'init', 'cloneRole' );
} // end if(..)
Core info about
add_role
You can now add users to this custom role and use that role in other situations as in:
$current_user = wp_get_current_user();
if( user_can( $current_user, 'main-admin' ) )
{
// Do your stuff
}