WordPress.org

Forums

Shortcode Exec PHP
[resolved] How to add a link where using is_admin() (2 posts)

  1. WMEric
    Member
    Posted 1 year ago #

    First off, I love this plugin, it's my new favorite.

    I added a log in form using this to the sidebar. I can't for some reason get the global is_admin() function to work right.

    Code:

    if (!is_user_logged_in()):
      echo wp_login_form();
      echo '<a href="';
      echo wp_login_url();
      echo '" title="Login">Secure Login</a> or <a href="';
      echo (site_url()) . "/" . "register" . "/";
      echo '">Register</a>.';
    else:
      global $current_user;
      get_currentuserinfo();
        echo '<h4>Welcome <a href="';
        echo (bp_loggedin_user_domain());
        echo '">';
        echo bp_loggedin_user_fullname();
        echo '</h4></a>';
    
        echo '<div class="pull-left"><a href="';
        echo (bp_loggedin_user_domain());
        echo '">';
        echo get_avatar( $current_user->ID, 80 );
        echo '</a></div>';
    
        echo '<a href="';
        echo (bp_loggedin_user_domain() . "profile" . "/" . "edit");
        echo '">Update Profile</a><br>';
    
        echo '<a href="';
        echo (bp_loggedin_user_domain()) . "activity" . "/";
        echo '">Update Status</a><br>';
    
        echo '<a href="';
        echo (bp_loggedin_user_domain()) . "messages" . "/";
        echo '">Check Inbox</a>';
    
        echo '<div class="clearfix"></div><a class="btn btn-mini btn-primary" title="Logout" href="';
        echo wp_logout_url( get_permalink() );
        echo '">Logout</a> ';
        echo '<a class="btn btn-mini btn-primary center" title="Help" href="/help">Help</a> ';
        if ( is_admin() ):
        	echo '<a class="btn btn-mini btn-primary" title="Dashboard" href="';
        	echo admin_url();
        	echo '">Dashboard</a>';
        endif;
    endif;

    Basically I want the final button to only show for admin users only but it still showing for all users.

    Any ideas?

    Thanks

    https://wordpress.org/plugins/shortcode-exec-php/

  2. WMEric
    Member
    Posted 1 year ago #

    I guess it would help if I used the right method lol :)

    is_admin() should be current_user_can('role here')

    http://codex.wordpress.org/Function_Reference/current_user_can
    http://codex.wordpress.org/Roles_and_Capabilities#publish_pages

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Shortcode Exec PHP
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.