fix(Database): fix bug create table
This commit is contained in:
17
sodino.php
17
sodino.php
@@ -21,6 +21,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
// Define plugin constants
|
||||
define('SODINO_VERSION', '2.0.0');
|
||||
define('SODINO_DB_VERSION', '2.0');
|
||||
define('SODINO_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('SODINO_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
define('SODINO_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
||||
@@ -74,6 +75,20 @@ function sodino_activate() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run database migrations after code updates, not only on activation.
|
||||
*/
|
||||
function sodino_maybe_run_migrations() {
|
||||
$current_version = get_option('sodino_db_version', '0');
|
||||
|
||||
if (version_compare($current_version, SODINO_DB_VERSION, '>=')) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once SODINO_PLUGIN_DIR . 'database/migrations.php';
|
||||
sodino_create_tables();
|
||||
}
|
||||
|
||||
// Deactivation hook
|
||||
register_deactivation_hook(__FILE__, 'sodino_deactivate');
|
||||
function sodino_deactivate() {
|
||||
@@ -99,6 +114,8 @@ function sodino_init() {
|
||||
// Load text domain
|
||||
load_plugin_textdomain('sodino', false, dirname(SODINO_PLUGIN_BASENAME) . '/languages/');
|
||||
|
||||
sodino_maybe_run_migrations();
|
||||
|
||||
// Initialize admin
|
||||
if (is_admin()) {
|
||||
require_once SODINO_PLUGIN_DIR . 'admin/admin.php';
|
||||
|
||||
Reference in New Issue
Block a user