I am trying to add a QR code to the bar and I can do this but it's my first time to make a WordPress plug-in and I'm having trouble. It ends up showing to everyone even if they are not an admin or even not logged in.

Any ideas or guidance would be very grateful.

function selfURL() {
    $s = empty($_SERVER["HTTPS"]) ? ''
        : ($_SERVER["HTTPS"] == "on") ? "s"
        : "";
    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
        : (":".$_SERVER["SERVER_PORT"]);
    return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
function strleft($s1, $s2) {
    return substr($s1, 0, strpos($s1, $s2));


function generateQRwithGoogle($url,$widthHeight ='30',$EC_level='L',$margin='0') {
    $url = urlencode($url); 
    echo '<img src="http://chart.apis.google.com/chart?chs='.$widthHeight.
'&chl='.$url.'" alt="QR code" widthHeight="'.$widthHeight.
'" widthHeight="'.$widthHeight.' "/>';
  • Also, I get an error upon activating: The plugin generated 371 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. Jun 20, 2012 at 20:45

2 Answers 2


You can limit to logged in users by wrapping the code with is_logged_in().

You can limit to levels via current_user_can('manage_options').


You only need one if statement:

//your code here...

You can check out more about it here: http://codex.wordpress.org/Conditional_Tags

  • Actually this does not work for some reason. Jun 20, 2012 at 20:45
  • Does not work as if it still shows to everyone? About headers already ent error, delete all empty lines in the end of the file. Jun 20, 2012 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.