Title: Requiring admin credentials
Last modified: October 24, 2016

---

# Requiring admin credentials

 *  Resolved [scienceofspock](https://wordpress.org/support/users/scienceofspock/)
 * (@scienceofspock)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/requiring-admin-credentials/)
 * Howdy Y’all,
    I’m creating a 3D map for a client, and to that end, I’m using 
   a custom post type to contain points of interest. This works well, but in order
   to place the POIs, each one needs an X and Y coord. These coords are for the 
   underlying 3D environment, and cannot accurately be guessed, so I have a version
   of the map that shows the X and Y coords where the user clicks (Among other things).
   I want to protect this page by making sure that any user that accesses it is 
   logged in as an admin. How do I do that? I do not want to use a plugin.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Ben Sibley](https://wordpress.org/support/users/bensibley/)
 * (@bensibley)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/requiring-admin-credentials/#post-8350553)
 * Hi scienceofspock,
 * When editing the page, click on the “Edit” link next to the “Visibility” status.
   This will reveal a few options including one to make the page private: [http://pics.competethemes.com/1p16101A1s45](http://pics.competethemes.com/1p16101A1s45)
 * When a page is set to private in this way, only logged-in users with the Editor
   and Admin user role will be able to view it.
    -  This reply was modified 9 years, 7 months ago by [Ben Sibley](https://wordpress.org/support/users/bensibley/).
 *  Thread Starter [scienceofspock](https://wordpress.org/support/users/scienceofspock/)
 * (@scienceofspock)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/requiring-admin-credentials/#post-8350621)
 * Hi Ben,
    thanks for the reply, but I was more looking for a way to do it programmatically.
   Sorry, I should have specified that in my original post. Something along the 
   lines of:
 *     ```
       if ( admin_user() ) {
       // do admin stuff here
       } else {
       echo "Restricted!";
       exit;
       }
       ```
   
 *  Thread Starter [scienceofspock](https://wordpress.org/support/users/scienceofspock/)
 * (@scienceofspock)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/requiring-admin-credentials/#post-8354008)
 * Figured it out:
 *     ```
       $user = wp_get_current_user();
   
       if ( !in_array( 'administrator', $user->roles ) ) {
       	header("location:/");
       	exit;
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Requiring admin credentials’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [scienceofspock](https://wordpress.org/support/users/scienceofspock/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/requiring-admin-credentials/#post-8354008)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
