Create frontend Admin Menu in WordPress

May 23, 2010 · Print This Article

Here is a short tutorial on how to create an additional WordPress menu that only shows up if a user is logged in. We can use this technique to create admin front end interface menus for the most used tasks: writing and editing posts and pages, editing the current post , a direct link to the “manage” Section of the WordPress admin Interface etc.

This is easily done with the WordPress function current_user_can()

As a parameter for the function you just have to add the expected user level and wrap the whole function call in an if statement.

<?php
        if (current_user_can('level_10')){
        /*do something*/
        }
?>

The /*do something*/ code would now only be added/executed if the user has a status of level 10, thus is an administrator. To get more information on User Levels check the WordPress Documentation.

Here is a short list of the user capabilities, just in case you don’t really care and only want to add a menue for a specific user group:

  • Subscriber : level_0
  • Contributor: level_1
  • Author: level_2
  • Editor: level_3 – level_7
  • Administrator: level_8 – level_10

Last but not least a short example of how an admin menu could look like:

<?php
    if (current_user_can('level_10')){ ?>
        <ul class="admin_box">
            <?php wp_register(); ?>
            <li><?php wp_loginout(); ?></li>
            <li><a href="<?php echo get_option('home'); ?>/wp-admin/post-new.php">Write new Post</a></li>
            <li><a href="<?php echo get_option('home'); ?>/wp-admin/page-new.php">Write new Page</a></li>
            <li>do something</li>
            <li>do something</li>
        </ul>
<?php }?>

Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.