0

The plugin generated 198 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds,,, Where the error ?

    if ( ! defined( 'ABSPATH' ) ) { exit; }
define('CUSTOM_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ));
define('CUSTOM_PLUGIN_URL',plugins_url());
define('VERSION','1.0.0');
add_action( 'admin_menu', 'add_custom_menu' );
function add_custom_menu(){
    // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, '', '', null );
    add_menu_page( 'CustomPlugin', 'Custom Plugin', 'manage_options', 'custom_plugin', 'add_new_function', 'dashicons-smiley', 11 );
    // add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, '' );
    add_submenu_page('custom_plugin', 'Add New', 'General', 'manage_options', 'custom_plugin', 'add_new_function' );
    add_submenu_page('custom_plugin', 'All Pages', 'All Pages', 'manage_options', 'all-pages', 'add_new_function2' );
}
// General menu function 
function add_new_function(){
    include_once CUSTOM_PLUGIN_DIR_PATH.'/templates/general.php';
}
// all pages menun function 
function add_new_function2(){
    echo "sub menu ";
}
add_action( 'admin_enqueue_scripts', 'custom_plugin_asset' );
function custom_plugin_asset(){
    // css and js file 
    wp_enqueue_style('custom-css', CUSTOM_PLUGIN_URL.'/custom-plugin/assets/css/custom.css','',VERSION );
    wp_enqueue_script('custom-js', CUSTOM_PLUGIN_URL.'/custom-plugin/assets/js/custom.js', array('jquery'),VERSION);
    // wp_enqueue_script( $handle, '', array( '' ), false, false );
}
function custom_plugin_tables(){
    global $wpdb;
    require_once (ABSPATH.'wp-admin/includes/upgrade.php');
    if (count($wpdb->get_var('SHOW TABLES LIKE "wp_custom_plugin"')) == 0) {
        $sql_query_to_create_table = "CREATE TABLE `wp_custom_plugin` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` varchar(150) DEFAULT NULL,
        `email` varchar(150) DEFAULT NULL,
        `phone` varchar(50) NOT NULL,
        `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1" ;// sql query to create table
        dbDelta( $sql_query_to_create_table);
    }
}
register_activation_hook( __FILE__, 'custom_plugin_tables' );
Mamunur Rashid
  • 186
  • 2
  • 11
  • Possible duplicate of [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) – T.Todua Dec 24 '18 at 00:04

3 Answers3

1

Remove space from start of tags. remove addHeaderCode(); from top and add this code add_action('wp_head', 'addHeaderCode'); to your file after addHeaderCode() function. its definitely resolve your problem.

0

There are few thing which cause this type of error message..

1). Please check is there any blank space in End and starting of you plugin files. if there is any space please remove this space..

2). You use a function (add_new_function2) for menu page..

function add_new_function2(){
echo "sub menu ";
}

This is wrong.. You can't use echo here. you have to include file in this section...

Yogesh Garg
  • 299
  • 3
  • 10
0

I find the solution , Just replace with

function custom_plugin_tables(){
    global $wpdb;
    require_once (ABSPATH.'wp-admin/includes/upgrade.php');
        $table_name = $wpdb->prefix.'custom_plugin';
        if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
            $sql_query_to_create_table = "CREATE TABLE $table_name (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `name` varchar(150) DEFAULT NULL,
            `email` varchar(150) DEFAULT NULL,
            `phone` varchar(50) NOT NULL,
            `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;" ;// sql query to create table
            dbDelta( $sql_query_to_create_table);
        }
}
register_activation_hook( __FILE__, 'custom_plugin_tables' );
Mamunur Rashid
  • 186
  • 2
  • 11