Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wp is user admin

if ( current_user_can('administrator') ) {} // also others than admin w same capabilities
if ( is_user_admin() ){} // if it is admin
if ( is_admin() ){} //if the view is not the admin interface but the theme
Comment

wordpress is admin

// Determines whether the current request is for an 
// administrative interface page.
is_admin()
Comment

user is admin wordpress

if( ! function_exists( 'current_user_has_role' ) ){
    function current_user_has_role( $role ){
        return user_has_role_by_user_id( get_current_user_id(), $role );
    }
}

if( ! function_exists( 'get_user_roles_by_user_id' ) ){
    function get_user_roles_by_user_id( $user_id ) {
        $user = get_userdata( $user_id );
        return empty( $user ) ? array() : $user->roles;
    }
}

if( ! function_exists( 'user_has_role_by_user_id' ) ){
    function user_has_role_by_user_id( $user_id, $role ) {

        $user_roles = get_user_roles_by_user_id( $user_id );

        if( is_array( $role ) ){
            return array_intersect( $role, $user_roles ) ? true : false;
        }

        return in_array( $role, $user_roles );
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: eloquent get distinct 
Php :: how to publish stubs in laravel 
Php :: PHP strtotime() Function 
Php :: php get total amount of days in month 
Php :: php get all php files in a directory 
Php :: laravel route group name 
Php :: append to collection laravel 
Php :: php.ini path 
Php :: check type in php 
Php :: generate random string php 
Php :: laravel migration remove relationship from table 
Php :: php append to csv 
Php :: magento 2 print php error 
Php :: wp debug 
Php :: how to get woocommerce category image 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 
Php :: how to replace double quotes in a string in php 
Php :: laravel where not 
Php :: docker check php version 
Php :: laravel tinker generate password 
Php :: column of csv to array php 
Php :: In PackageManifest.php line 122: 
Php :: find curren monday in laravel carbon 
Php :: how to delete php from win10 
Php :: Laravel randomise data from database 
Php :: strcasecmp php 
Php :: php time ago 
Php :: php unix timestamp to date 
Php :: how to search by sku woocommerce 
Php :: reset password multipple database laravel 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =