-2

I am working on a plugin. I make a query on "register_activation_hook". When I activate the plugin the Query work perfectly, but I get an error

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

What is the issue? I don't get it.

Here is my code:

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');

Any idea?

halfer
  • 19,824
  • 17
  • 99
  • 186
deemi-D-nadeem
  • 2,343
  • 3
  • 30
  • 71
  • 3
    This isn't an appropriate question for SO, if you want someone to urgently debug your code then hire a developer. This has also been asked and answered before: http://stackoverflow.com/questions/4074477/the-plugin-generated-x-characters-of-unexpected-output – Joe Jun 20 '14 at 10:52
  • sorry bro, i am a developer, and i make a wp plugin first time – deemi-D-nadeem Jun 20 '14 at 10:58
  • 1
    Why `mysql_query` if you have **`$wpdb`**? – brasofilo Jun 20 '14 at 11:10
  • Kill the script at the end of customtaxorder_init function to see that unexpected output. – Danijel Jun 20 '14 at 11:22
  • @Danijel how can i "kill the script" please tell me – deemi-D-nadeem Jun 20 '14 at 11:39
  • After the plugin's activation hook is run the page is redirected, and if there was some output generated WP will show that error message. Quick workaround is to use die() at the end of activation to see that output in browser, it is probably PHP warning or notice. – Danijel Jun 20 '14 at 12:35
  • Check [this](http://wordpress.stackexchange.com/a/84284/12615) – brasofilo Jun 20 '14 at 15:32

3 Answers3

4

if you are using dreamweaver then there is a option "Apply source formatting" under control menu, try that and it will remove unwanted whitespaces.

and also make sure there are no any extra whitespaces or line breaks after the ?>(php closing tag at the end of your page..)

Yamu
  • 1,652
  • 10
  • 15
1

1) Please remove extra spacing in the inner pages or plugin pages.

2) remove the inline styling in the pages or plugin pages.

its worked for me everytime. i have used many times same method. when the problem error in the plugin page or Wordpress page.

Regards,

Hitesh Nagpal

-2

Disable error reporting i.e define('WP_DEBUG', false); It worked for me

Manik Thakur
  • 294
  • 2
  • 15