• Resolved enriquerene

    (@enriquerene)


    Hi,

    I put the following code inside my activation hook function:

    function easydm_create_table_in_wpdb(){
    	global $wpdb;
    
    	$table_name = $wpdb->prefix.'easy_downloader_manager';
    
    	$charset_collate = $wpdb->get_charset_collate();
    	echo '<script type="text/javascript">alert('.$charset_collate.');</script>';
    
    	$sql = "CREATE TABLE $table_name (
    		name varchar(20) NOT NULL,
    		level int(1) NOT NULL,
    		url varchar(55) DEFAULT '' NOT NULL
    	) $charset_collate;";
    
    	require_once( ABSPATH.'wp-admin/includes/upgrade.php' );
    	dbDelta( $sql, true );
    }

    and

    function easydm_activation() {
    	$path = WP_CONTENT_DIR.'/easydm-uploads';
    	if( !file_exists( $path ) ){
    		mkdir( $path );
    	}
    
    	easydm_create_table_in_wpdb();
    }

    When the plugin is activated, it creates a directory and a table in wp db. I’m in ubuntu 14.04 and keep my file manager opened to see the directory appear (no problem here). It’s weird, when I insert the function to create the table, because I keep phpMyAdmin opened to see the table creation (and it is created in all activation) even the following message appears to me:

    The plugin generated 104 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 should I do? How to debugger correctly? I wanna publish my plugins (this first and future ones) in WordPress repository

Viewing 3 replies - 1 through 3 (of 3 total)
  • This line is causing the issue:

    echo '<script type="text/javascript">alert('.$charset_collate.');</script>';

    You can’t output anything there. If you do, it will throw that error, and as you’ve seen it breaks the activation process for the plugin. Just remove that line, and you should be alright.

    Thread Starter enriquerene

    (@enriquerene)

    Nice! I put there for debugging reason and forgot to take off… thanks

    I do that myself all the time… it’s amazing how easy it is to have another set of fresh eyes pick it up. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘create tables (ok and not ok at same time)’ is closed to new replies.