Last active
June 3, 2019 15:43
-
-
Save mahfelwp/b8092f1962562cd8b01f07b5a87133e2 to your computer and use it in GitHub Desktop.
Add new column to plugin table in new version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class Plugin_Name { | |
private function __construct() { | |
register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) ); | |
} | |
public function plugin_activation() { | |
if ( get_option( 'plugin_version' ) != PLUGIN_VERSION ) { | |
update_option( 'plugin_version', PLUGIN_VERSION ); | |
} | |
$this->create_tables(); | |
$this->upgrade_tables(); | |
} | |
public function create_tables() { | |
// codes here... | |
} | |
public function upgrade_tables() { | |
if ( get_option( 'plugin_version' ) == '1.2.0' ) { | |
global $wpdb, $table_prefix; | |
$plugin_tbl_name = $table_prefix . 'plugin_tbl_name'; | |
$the_upgrade_query = "ALTER TABLE `{$plugin_tbl_name}` ADD `products` TEXT NULL DEFAULT NULL AFTER `users`;"; | |
$wpdb->query( $the_upgrade_query ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment