【问题标题】:why is my wordpress plugin reciving "unexpected output"为什么我的 wordpress 插件收到“意外输出”
【发布时间】:2013-05-28 03:07:00
【问题描述】:

当我安装这个 wordpress 插件时,它给了我:

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

这是我的代码:

add_action('wp_head', 'wpse_43672_wp_head', 0);
/**
 * Hooks into the `wp_head` action.
*/
function wpse_43672_wp_head(){ ?>
       <script>
       if (navigator.userAgent.match(/Android/i) ||
             navigator.userAgent.match(/webOS/i) ||
             navigator.userAgent.match(/iPhone/i) ||
             navigator.userAgent.match(/iPad/i) ||
             navigator.userAgent.match(/iPod/i) ||
             navigator.userAgent.match(/BlackBerry/) || 
             navigator.userAgent.match(/Windows Phone/i) || 
             navigator.userAgent.match(/ZuneWP7/i)
             ) {
                // some code
                self.location="<?php echo plugins_url(); ?>/zeevmobile/mobile-page.php";
               }
        </script>
<?php }?>
<style>
li#toplevel_page_zeevmobile-zeevmobile .wp-menu-image {
    background: url(<?php echo plugins_url(); ?>/zeevmobile/images/icon.png) no-repeat 4px !important;
}
</style>
<?php
// create custom plugin settings menu  
add_action('admin_menu', 'zeev_create_menu');  
function zeev_create_menu() {  
    //create new top-level menu  
    add_menu_page('zeev movile redirect', 'zeev mobile', 'administrator', __FILE__, 'zeev_settings_page');  
      //create new top-level menu  
    //call register settings function  
    add_action( 'admin_init', 'register_mysettings' );  
}  
function register_mysettings() {  
    //register our settings  
    register_setting( 'zeev-settings-group', 'zeev_above_text' ); 
    register_setting( 'zeev-settings-group', 'zeev_normal_site' );  
    register_setting( 'zeev-settings-group', 'zeev_mobile_site' );  
} 
function zeev_settings_page() {  
?>  
<div class="wrap">  
<h2>Your Mobile Buttons Links</h2>  
<form method="post" action="options.php">       
    <?php settings_fields('zeev-settings-group'); ?>  
    <table class="form-table">  
        <tr valign="top">  
        <th scope="row">Some text above buttons</th>
        <td><textarea name="zeev_above_text" cols="90"><?php echo get_option('zeev_above_text'); ?></textarea></td>  
        </tr> 
        <tr valign="top">  
        <th scope="row">Normal Site Link</th>
        <td><textarea name="zeev_normal_site" cols="90"><?php echo get_option('zeev_normal_site'); ?></textarea></td>  
        </tr>  
         <tr valign="top">  
        <th scope="row">Mobile Site Link</th>
        <td><textarea name="zeev_mobile_site" cols="90"><?php echo get_option('zeev_mobile_site'); ?></textarea></td>  
        </tr>         
    </table>     
    <p class="submit">  
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />  
    </p>  
</form>  
</div>  
<?php }?>

我知道“意外输出”问题来自此文件,因为当我删除其中的所有 php 时,我没有遇到问题。 你能帮我修一下吗? 我在这里上传了它: http://zeevm.co.il/zeev-mobile-new.zip

【问题讨论】:

  • 你不是一开始就缺少&lt;?php吗?
  • no :) 我把插件的部分没有开头的东西(插件作者和类似的东西)
  • 也许你最后有足够的空白,然后......错误消息基本上是 WP 抱怨包含文件时会回显某些内容。
  • 这是我检查的第一件事。清除了文件中的所有空格..但仍然。这真的很奇怪,它不是来自一个地方。就像这个文件中的所有 PHP 图表都是“意外的”

标签: wordpress plugins


【解决方案1】:

对于每个 cmets,错误消息基本上是 WP 抱怨包含文件时正在回显某些内容。

粗略看一下您的代码,您的&lt;style&gt; 标记似乎得到了回显——它不在函数范围内。插件的其他地方可能还有其他类似的问题。

【讨论】:

    猜你喜欢
    • 2023-01-08
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    相关资源
    最近更新 更多