我每次激活插件时都收到此消息:
该插件在激活期间生成了80个字符的意外输出.如果您注意到"已发送标头"消息,联合供稿问题或其他问题,请尝试停用或删除此插件.
我能够抑制消息的唯一方法是将我的激活功能代码包装在if语句中(请参阅下面的代码片段).
这里,当我收到上述错误时,我的插件代码片段:
function myPlugin( $post ) {
echo "Whatever is here throws an unexpected output alert when the plugin isa activated";
}
register_activation_hook( __FILE__, 'myPlugin' );
Run Code Online (Sandbox Code Playgroud)
接下来,我在if语句中将函数包装在我的插件中; 它抑制了上面讨论的先前错误:
function myPlugin( $post ) {
global $pagenow;
if ( is_admin() && $pagenow !== 'plugins.php' ) {
echo "No more alerts when its wrapped this way";
}
}
}
register_activation_hook( __FILE__, 'myPlugin' );
Run Code Online (Sandbox Code Playgroud)
究竟是什么导致了这个错误,我怎样才能有效地完成我的逻辑插件而不必遇到它?
有没有更好的方法来处理这个?