我正在开发一个插件。我在" register_activation_hook"上查询。当我激活插件时,查询工作完美,但我收到错误
插件在激活期间生成了1个意外输出字符。如果您发现“已发送标头”消息,联合供稿问题或其他问题,请尝试停用或删除此插件。
问题是什么?我不明白。
这是我的代码:
function customtaxorder_init() {
global $wpdb;
$init_query = $wpdb->query("SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'");
if ($init_query == 0) { $wpdb->query("ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'"); }
// For Previous Users Product Images
$prefix = $wpdb->prefix;
$postSql = "SELECT DISTINCT post_id
FROM ".$prefix."postmeta As meta
Inner Join ".$prefix."posts As post
On post.ID = meta.post_id
Where post_type = 'wpcproduct'
And post_status = 'publish'
And meta_key Like '%product_img%'";
$postQry = mysql_query($postSql);
while($postRow = mysql_fetch_array($postQry)){
$post_id = $postRow['post_id'];
$meta_key = "product_images";
$sql = "Select post.*, meta.*
From ".$prefix."posts As post
Inner Join ".$prefix."postmeta As meta
On post.ID = meta.post_id
Where post_type = 'wpcproduct'
And post_status = 'publish'
And meta_key Like '%product_img%'
And post_id = ".$post_id;
$qry = mysql_query($sql);
$prod_key = array();
$prod_value = array();
$a = 0;
while($row = mysql_fetch_array($qry)){
$product_img = $row['meta_key'];
$product_img = preg_replace("([0-9]+)", "", $product_img);
$response[$a] = $row['meta_key'];
$response[$a] = $row['meta_value'];
$data[$a][$product_img] = $response[$a];
$a = $a + 1;
}
//print_r($data);
$data_serialize = serialize($data);
$insert_images = "Insert Into ".$prefix."postmeta(post_id,meta_key,meta_value) Value('$post_id','$meta_key','$data_serialize')";
mysql_query($insert_images);
}
// Delete All product_img1,product_img2,product_img3
mysql_query("Delete From ".$prefix."postmeta Where meta_key IN ('product_img1','product_img2','product_img3')");
// Update All product_price to Product Price
$support_sql = "Select * From ".$prefix."postmeta Where meta_key Like '%product_price%'";
$support_qry = mysql_query($support_sql);
while($support_arr = mysql_fetch_array($support_qry)){
$supportMetaID = $support_arr['post_id'];
$supportMetaPrice = $support_arr['meta_key'];
$price_split = explode("_", $supportMetaPrice);
$supportMetaPrice = $price_split[0]." ".$price_split[1];
$supportMetaPrice = ucwords($supportMetaPrice);
$update_price = "Update ".$prefix."postmeta
Set meta_key = '$supportMetaPrice'
Where post_id = $supportMetaID
And meta_key Like '%product_price%'";
mysql_query($update_price);
}
}
register_activation_hook(__FILE__, 'customtaxorder_init');
有什么想法吗?
答案 0 :(得分:3)
如果您使用的是Dreamweaver,则可以选择"应用源格式"在控制菜单下,尝试它,它将删除不需要的空格。
还要确保在>之后没有任何额外的空格或换行符(页面末尾的php结束标记..)
答案 1 :(得分:1)
1)请删除内页或插件页面中的额外间距。
2)删除页面或插件页面中的内联样式。
每次都为我工作。我使用了很多次相同的方法。当插件页面或Wordpress页面出现问题时。
此致
Hitesh Nagpal
答案 2 :(得分:1)
禁用错误报告,即define('WP_DEBUG', false);
它对我有用