Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

[WordPress] How to check if current user is Administrator

DZone's Guide to

[WordPress] How to check if current user is Administrator

· Web Dev Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

It’s been quite a while since I posted anything on this blog. Have been really busy doing development work for others and could not devote time to blogging.

I have a quick snippet to share, which is most commonly used while programming in WordPress. The following code snippet let’s you check if the current user logged in is an Administrator or not.

function dm_is_admin(){
    return current_user_can( 'manage_options' );
}

Paste the above code inside functions.phpof the active theme. Please note that I have used the function name as dm_is_admin, since is_admin function for WordPress already exists. However, the built-in is_admin function only checks if you are currently on the WordPress Dashboard or no.

You can use this code snippet to display certain information in the front end only when the Admin is logged in. I use this to display debugging information on any live site, this comes very handy.

Hope this is going to help you, as well!
Stay Digified!!
Sachin Khosla

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of Sachin Khosla, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}