[wp-trac] [WordPress Trac] #32640: wp-db.php bug when activating plugin ("unexpected output" During Plugin Activation)

WordPress Trac noreply at wordpress.org
Sun Jun 14 04:30:10 UTC 2015


#32640: wp-db.php bug when activating plugin ("unexpected output" During Plugin
Activation)
---------------------------+------------------------------
 Reporter:  s1nc1tycyph3r  |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Database       |     Version:  4.2.2
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by s1nc1tycyph3r):

 Replying to [comment:2 dd32]:
 > This sounds like you're passing invalid data to `$wpdb->insert()`, or
 passing invalid data to another function that is ultimately passing it
 through to the DB layer.
 >
 > Are you able to post a minimal plugin which duplicates the issue?

 yes i just did as you suggested and i'm still getting the same issue

 heres the
 code im using for the minimal plugin


 {{{
 <?php
 /**
  * @package Minimal Plugin
  * @version 1.0
  */
 /*
 Plugin Name: Minimal Plugin
 Plugin URI: http://primagemedia.com/
 Description: This Is A Minimal Plugin
 Author: Michael Christopher Ingli
 Version: 1.0
 Author URI: http://www.primagemedia.com/
 */
 global $minimalplugin_db_version;
 $minimalplugin_db_version = '1.0';
 // define Plugin Version
 define( 'MINIMALPLUGIN_VERSION', $minimalplugin_db_version );
 // define Plugin Url
 define( 'MINIMALPLUGIN__PLUGIN_URL', plugin_dir_url( __FILE__ ) );
 // define Plugin Dir
 define( 'MINIMALPLUGIN__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
 // ensure ABSPATH IS Already Defined (Wordpress Should have Defined it
 already at this point)
 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

 // Create and Define Plugin Install Function(Gets called On Plugin
 Activation! see register_activation_hook declaration at the end of this
 file)
 function minimalplugin_install() {
         // ensure we define global $wpdb For this Function locally
         if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];
         global $wpdb;
         global $minimalplugin_db_version;

         //global $wp_query;
         //define all the sql table names that our plugin will make use of
 where $wpdb->prefix usually is 'wp_'

         $minimalplugin_data_tablename=$wpdb->prefix . 'minimaltestdata';
         //$mapformadminemail_tablename =
 $wpdb->prefix.'mapform_adminemail'

         //get character collation to create our Sql Tables With
         $charset_collate = $wpdb->get_charset_collate();
         //define and Sql Tables Stucture

         $sql = "CREATE TABLE $minimalplugin_data_tablename (
         id int(11) NOT NULL AUTO_INCREMENT,
         testdataa varchar(255) NOT NULL,
         testdatab varchar(255) NOT NULL,
         PRIMARY KEY  id (id)
         ) $charset_collate;";
         //include require_once( ABSPATH . 'wp-admin/includes/upgrade.php'
 ); as this is where the dbDelta function is defined
         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
         // create our Sql Tables Now
         dbDelta( $sql );

         // Add the db version
         add_option( 'minimalplugin_db_version', $minimalplugin_db_version
 );
 }
 // define our Sql Install Data Function(Gets called On Plugin Activation!
 see register_activation_hook declaration at the end of this file)
 function minimalplugin_install_data() {
         // ensure we define global $wpdb For this Function locally
         if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];
         global $wpdb;
         global $wp_query;

         $minimalplugin_data_tablename=$wpdb->prefix . 'minimaltestdata';
         $testdata=array(array('id'=>'1', 'testdataa'=>'mytestdataa',
 'testdatab'=>'mytestdatab'),
                                         array('id'=>'2',
 'testdataa'=>'mytestdataa2', 'testdatab'=>'mytestdatab2'),
                                         array('id'=>'3',
 'testdataa'=>'mytestdataa3', 'testdatab'=>'mytestdatab3'));
 for($i=0; $i<=sizeof($testdata); $i++)
 {
         $wpdb->insert(
                 $minimalplugin_data_tablename,
 $testdata[$i]
         );
 }

 }
 register_activation_hook( __FILE__, 'minimalplugin_install' );
 register_activation_hook( __FILE__, 'minimalplugin_install_data' );
 add_action('activated_plugin','save_error');
 function save_error(){
 file_put_contents(ABSPATH. 'wp-
 content/uploads/2015/error_activation.html', ob_get_contents());
 }

 ?>
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32640#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list