1

So interestingly, I moved my main plugin file into a folder within the plugin directory. Where before the register_activation_hook worked perfectly well, it now does not work; however, the register_deactivation_hook still works perfectly, and it is currently being called from within the same file. I have attempted explicitly defining a path as well for the activation hooks instead of just relying on the __FILE__ keyword. Any insight that can be offered as to why the plugin no longer calls to hook on actviation would be much appreciated, thank you.

//define paths
$skirmish_table_name = $wpdb->prefix . 'skirmishes';

function skirmish_create_db() {
  global $wpdb;
  $charset_collate = $wpdb->get_charset_collate();
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

  //* Create thetable
  global $skirmish_table_name;
  $sql = "CREATE TABLE $skirmish_table_name (
  skirmish_id INTEGER NOT NULL AUTO_INCREMENT,
  skirmish_SID TEXT NOT NULL,
  skirmish_name TEXT NOT NULL,
  skirmish_visibility TEXT NOT NULL,
  skirmish_public_tries TEXT NOT NULL,
  PRIMARY KEY (skirmish_id)
  ) $charset_collate;";
   dbDelta( $sql );
  }
  register_activation_hook(__FILE__, 'skirmish_create_db' );

is the basic structure of the code.

As it turns out, I reverted the plugin back to its original format and the tables are still not being generated. I have attempted deactivating all of the plugins that had been activated previously, but it still seems that something is interfering with the plugin's ability to CREATE tables in the mysql database. Any insight into why this is going on would be much appreciated.

I have attempted checking all of the various logs, but cannot figure out what is going on. I have no idea why this is suddenly not working, when it was working perfectly well before. Either something is going on with the activation hook, or for some reason the server is rejecting/dropping the create table requests....

1 Answer 1

0

So I figured out the problem, or at least to an extent, and it involves the invocation of the global keyword. This works well in other contexts/functions, but for some reason (I am still unclear as to why), dbDelta does not like it. I can get away with it in other functions that do not use dbDelta (such as basic queries), but yes, this....so anyhow, if anyone ends up dealing with a dbDelta issue, well, hopefully this might save someone else some time down the line....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.