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