質問

I am trying to activate a tiny plugin on WordPress that is running on localhost but it runs into the following error:

The plugin generated 6 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.

<?php
/*
Plugin Name: myphoto Plugin
Description: A plugin to retrieve photos and share them on the wordpress.
Version: 1.0
Author: Saeed pirdost
Copyright: 2012,  Saeed pirdost  
*/
?>
<?php
myprint();
function myprint()
{
    echo "hello";
}
?>
役に立ちましたか?

解決

Try remove some things and use a suitable hook.

<?php // remove all spaces up of here too
/*
  Plugin Name: RePhotosPic Plugin
  Description: A plugin to retrieve photos and share them on the wordpress.
  Version: 1.0
  Author: Saeed pirdost
  Copyright: 2012,  Saeed pirdost
 */

// remove     ?> <?php

add_filter('admin_notices', 'hello');

function hello()
{
    echo 'Hello';
}

// remove ?>

UPDATE:

Remove myprint(); place it inside a WP hook too. Like this:

add_filter('admin_notices', 'myprint');

function myprint()
{
    echo "hello";
}

他のヒント

The error tells you what's wrong. A plugin should not produce output unless one of its functions is called by WordPress. Yours tries to write "Hello" when WordPress is busy trying to render the administration panel. That's not a well-mannered plugin.

If you want to see "Hello" on the screen, register a hook on an action triggered by WordPress during page rendering, and run your output there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top