Plugin: register_deactivation_hook works perfectly well, while register_activation_hook suddenly stopped working

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 … Read more

dbDelta with the character ;

That happens for this reason : The function dbDelta can receive as first parameter ($queries) an array or a string. If $queries is a string, dbDelta will make an array with “;” as delimiter. inside dbDelta if ( !is_array($queries) ) { $queries = explode( ‘;’, $queries ); $queries = array_filter( $queries ); } So the … Read more

dbDelta using Foreign key not working on update [duplicate]

From the Codex: Note that the dbDelta function is rather picky, however. For instance: […] You must not use any apostrophes or backticks around field names. $sql = “CREATE TABLE “.TEST_TABLE.” ( id INT( 11 ) NOT NULL AUTO_INCREMENT, title VARCHAR( 100 ) NOT NULL, description TEXT DEFAULT NULL, location_id INT( 11 ) NOT NULL, … Read more

How to update an existing table while updating plugin?

register_activation_hook() only attaches a function to run on activation of your plugin, not on updating. See the docs for full details, particularly this part: 3.1 : This hook is now fired only when the user activates the plugin and not when an automatic plugin update occurs (#14915). Of course, you could force your hook to … Read more

Adding a Table to the wordpress database

Try: function vw_postcode_checker_create_db () { global $wpdb; // Create Table Name $table_name = $wpdb->prefix . “vw_postcode_checker”; // Write Query to add table to database if ( $wpdb->get_var(“SHOW TABLES LIKE ‘$table_name'”) != $table_name) { $sql = “CREATE TABLE $table_name ( id INTEGER(10) UNSIGNED AUTO_INCREMENT, postcode varchar(250) DEFAULT ” NOT NULL, area varchar(250) DEFAULT ” NOT NULL, … Read more