• Resolved akiryk

    (@akiryk)


    There’s a place on my blog where I’d like to provide a link to admin for editing the site — and a link to something else for those without admin privileges. Right now, I’m using this (below). Is there a better way?

    <?php if ( current_user_can('manage_options') )
         {
              edit_post_link('Edit the site');
         } else {
              print("Some content.");}?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • what about in page.php

    <?php edit_post_link('Edit this entry','','.'); ?>

    and/or in single.php

    <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

    These seem to only appear if you are logged in and have permission to edit posts/pages. Both go below the loop.

    The approach you have is fine, only admins have the manage_options capability.

    Ideally that’s how you should be checking what a user can or cannot do… so there’s no problem with the method you’re using..

    A link is only a link anyway, even if for some strange reason another user could see the link, it wouldn’t mean they’d be given the ability to actually edit anything, they’d click it then get redirected or see a permissions/capability error message.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Check if user is admin’ is closed to new replies.