WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.' "/>';
share|improve this question
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. – Joseph Lancaster Jun 20 '12 at 20:45

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').

share|improve this answer

You only need one if statement:

//your code here...

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

share|improve this answer
Actually this does not work for some reason. – Joseph Lancaster Jun 20 '12 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. – OriginalEXE Jun 20 '12 at 20:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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