0
<?php

/*
Plugin Name: SQL table creator
Author: Md. Sarwar-A-Kawsar
Author URI: https://xyz.abc
*/

defined('ABSPATH') or die('You cannot access to this page');
function stb_sql_custom_activate(){
    global $wpdb;
    $table_name = $wpdb->prefix.'eg_all_videos';
    if( $wpdb->get_var("SHOW TABLES LIKE ".$table_name) != $table_name ){
        $sql = "CREATE TABLE $table_name (
          id INT(5) NOT NULL AUTO_INCREMENT,
          old_id INT(5) DEFAULT NULL,
          type VARCHAR(10) DEFAULT NULL,
          title VARCHAR(300) DEFAULT NULL,
          year year(4) DEFAULT NULL,
          segment_number INT(3) DEFAULT NULL,
          slug VARCHAR(300) DEFAULT NULL,
          UNIQUE KEY (id)
        ) $charset_collate;";
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $sql );
    }
}
register_activation_hook( __FILE__, 'stb_sql_custom_activate' );

I've used the above code in my plugin but getting this error during activate the plugin:

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

I've changed the SQL query but didn't get any luck and would appreciate if anyone helps to solve this issue.

Regards

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • Does this answer your question? [The plugin generated X characters of unexpected output during activation (WordPress)](https://stackoverflow.com/questions/4074477/the-plugin-generated-x-characters-of-unexpected-output-during-activation-wordpr) – Don Rowe Feb 11 '20 at 01:21

2 Answers2

0

Try removing

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

It is creating output before headers are sent. I'm also not sure why that is there at all.

KGreene
  • 790
  • 7
  • 11
0

Usage ob_start(); - turn output buffering on, and return ob_get_clean(); - return & clean buffer contents help for me.

<?php 

/**
* Plugin Name: Custom Testimonials Slider
* Description: This plugin for "What My Clients Say" section
* Version: 2.0.0
**/

/**
 * Shortcode plugin
 */
 add_shortcode("testimonials-slider", "testimonials_slider_activation");

/**
 * Activation plugin
 */
 register_activation_hook( __FILE__, 'testimonials_slider_activation' );
 function testimonials_slider_activation() {

    ob_start();

    //your code is here

    return ob_get_clean();

}

?>
Iryna
  • 1
  • 1