参见英文答案 > The plugin generated X characters of unexpected output during activation (WordPress) 15个
我正在创建wordpress插件来显示Total Twitter counter& Feed订阅者.您可以通过小部件进行管理.
我收到了这个错误.
该插件在激活期间生成了123个字符的意外输出.如果您注意到“已发送标头”消息,联合供稿问题或其他问题,请尝试停用或删除此插件.
<?PHP
/*
* Plugin Name: Twitter & RSS Stats
* Version: 1.0
* Plugin URI: http://sss.com/
* Description: Facebook, Twitter & RSS Social Stats widget <a href="http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/">tutorial</a>.
* Author: Ajay Patel
* Author URI: http://sss.com/
*/
addHeaderCode();
function addHeaderCode() {
echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/TRR_Stats/css/style.css" />' . "\n";
}
/*******************************/
/* Create table */
/********************************/
function my_plugin_create_table()
{
// do NOT forget this global
global $wpdb;
// this if statement makes sure that the table doe not exist already
if($wpdb->get_var("show tables like TRR_Stats") != 'TRR_Stats')
{
$sql = "CREATE TABLE TRR_Stats (
id mediumint(9) NOT NULL,
RSS_email tinytext NOT NULL,
twitter tinytext NOT NULL,
RSS tinytext NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.PHP');
dbDelta($sql);
}
}
// this hook will cause our creation function to run when the plugin is activated
register_activation_hook( __FILE__, 'my_plugin_create_table' );
class FTRWidget extends WP_Widget
{
/**
* Declares the FTRWidget class.
*
*/
function FTRWidget(){
$widget_ops = array('classname' => 'widget_hello_world', 'description' => __( "Example widget demoing wordpress 2.8 widget API") );
$control_ops = array('width' => 300, 'height' => 300);
$this->WP_Widget('helloworld', __('Twitter & RSS Social Stats'), $widget_ops, $control_ops);
}
/**
* displays the Widget
*
*/
function widget($args, $instance){
extract($args);
$RSS_email = empty($instance['RSS_email']) ? 'webdesignergeeks' : $instance['RSS_email'];
$twitter = empty($instance['twitter']) ? 'webdesignergeek' : $instance['twitter'];
$RSS = empty($instance['RSS']) ? 'webdesignergeeks' : $instance['RSS'];
# Featch Data from table
global $wpdb;
$item_info = $wpdb->get_row("SELECT * FROM TRR_Stats WHERE id=1;");
$RSS_email_f = $item_info->RSS_email;
$url = file_get_contents('https://Feedburner.google.com/api/awareness/1.0/GetFeedData?uri=24thfloor');
preg_match( '/circulation="(\d+)"/', $url, $matches );
if ( $matches[1] )
$RSS_f = $matches[1] . " Subscribers";
else
echo "0";
$twit = file_get_contents('http://twitter.com/users/show/'.$twitter.'.xml');
preg_match( '/\<followers_count\>(\d+)\<\/followers_count\>/', $twit, $matches );
if ( $matches[1] )
$twitter_f = $matches[1] . " Followers";
else
$twitter_f = "0";
echo '
<div class="sidebarContainer" id="sidebarSubscribe">
<a target="_blank" href="http://twitter.com/'.$twitter.'" class="subscribeSidebarBox" id="followTwitter">
<span class="icon"><img src="'.get_bloginfo('url').'/wp-content/plugins/TRR_Stats/img/twitter.png" alt="Twitter" /></span>
<span class="title">Follow Us on Twitter</span>
<span class="count">'.$twitter_f.'+</span>
</a>
<a target="_blank" href="http://Feeds.Feedburner.com/'.$RSS.'" class="subscribeSidebarBox" id="subscribeRSS">
<span class="icon"><img src="'.get_bloginfo('url').'/wp-content/plugins/TRR_Stats/img/RSS_Feed.png" alt="RSS"/></span>
<span class="title">Subscribe to our RSS Feed</span>
<span class="count">'.$RSS_f.'+</span>
</a>
<a target="_blank" href="http://Feedburner.google.com/fb/a/mailverify?uri='.$RSS_email_f.'" class="subscribeSidebarBox" id="subscribeEmail">
<span class="icon"><img src="'.get_bloginfo('url').'/wp-content/plugins/TRR_Stats/img/RSS_email.png" alt="RSS_email" /></span>
<span class="title">Subscribe for updates via</span>
<span class="count">EMAIL</span>
</a>
</div>';
# After the widget
echo $after_widget;
}
/**
* Saves the widgets settings.
*
*/
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['RSS_email'] = strip_tags(stripslashes($new_instance['RSS_email']));
$instance['twitter'] = strip_tags(stripslashes($new_instance['twitter']));
$instance['RSS'] = strip_tags(stripslashes($new_instance['RSS']));
global $wpdb;
//Insert First time
$wpdb->insert( 'TRR_Stats', array(
'id' => 1,
'RSS_email' => $instance['RSS_email'],
'twitter' => $instance['twitter'],
'RSS' => $instance['RSS']
)
);
//Rest Update Data
global $wpdb;
$wpdb->update( 'TRR_Stats',
array(
'RSS_email' => $instance['RSS_email'],
'twitter' => $instance['twitter'],
'RSS' => $instance['RSS']
),
array(
'id' => 1
)
);
return $instance;
}
/**
* Creates the edit form for the widget.
*
*/
function form($instance){
//Defaults
$instance = wp_parse_args( (array) $instance, array('RSS_email'=>'', 'twitter'=>'engiguide', 'RSS'=>'www.RSS_email.com/engiguide') );
$RSS_email = htmlspecialchars($instance['RSS_email']);
$twitter = htmlspecialchars($instance['twitter']);
$RSS = htmlspecialchars($instance['RSS']);
# Output the options
# Twitter
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('twitter') . '">' . ('Twitter:') . ' <input style="width: 200px;" id="' . $this->get_field_id('twitter') . '" name="' . $this->get_field_name('twitter') . '" type="text" value="' . $twitter . '" /></label></p>';
echo '<p style="padding-left: 110;">i.e: webdesignergeeks</p>';
# RSS
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('RSS') . '">' . __('RSS:') . ' <input style="width: 200px;" id="' . $this->get_field_id('RSS') . '" name="' . $this->get_field_name('RSS') . '" type="text" value="' . $RSS . '" /></label></p>';
echo '<p style="padding-left: 110;">i.e: webdesignergeeks</p>';
# RSS Email
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('RSS_email') . '">' . ('RSS Email:') . ' <input style="width: 200px;" id="' . $this->get_field_id('RSS_email') . '" name="' . $this->get_field_name('RSS_email') . '" type="text" value="' . $RSS_email . '" /></label></p>';
echo '<p style="padding-left: 110;">i.e: webdesignergeeks</p>';
}
}// END class
/**
*
* Calls 'widgets_init' action after the Hello World widget has been registered.
*/
function TTRInit() {
register_widget('FTRWidget');
}
add_action('widgets_init', 'TTRInit');
?>
解决方法:
从标签的开头删除空格. remove addHeaderCode();从顶部添加此代码add_action(‘wp_head’,’addHeaderCode’);在addHeaderCode()函数之后到你的文件.它肯定能解决你的问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。