• Resolved scienceofspock

    (@scienceofspock)


    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)
  • 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: https://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 8 years, 1 month ago by Ben Sibley.
    Thread Starter scienceofspock

    (@scienceofspock)

    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

    (@scienceofspock)

    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.