0

我正在为 WordPress 编写一个插件。当我使用该函数register_activation_hook时,我收到以下错误:

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

相关代码:

register_activation_hook(__FILE__, function(){
echo "<script>alert('ok')</script>";
});
4

1 回答 1

0

Wordpress 可能在发送标头之前被调用。如果在发出之前生成了任何header()输出,那么 PHP/Wordpress 通常会抱怨。

试试这个:

function my_activation_func() {    
    echo "<script>alert('ok')</script>";
}

register_activation_hook( __FILE__, 'my_activation_func' );

在此处阅读文档。

于 2013-07-09T14:15:16.403 回答