From 1fa344dd513decc5c917163bd778aeff3d33c927 Mon Sep 17 00:00:00 2001 From: Davod Saraei Date: Fri, 27 Nov 2020 15:05:28 +0330 Subject: [PATCH] create table if not exists when set account id --- classes/Action.php | 12 ++++++++++++ classes/Installer.php | 21 ++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/classes/Action.php b/classes/Action.php index 6051fad..e4fa642 100644 --- a/classes/Action.php +++ b/classes/Action.php @@ -5,10 +5,12 @@ require_once 'Woocommerce.php'; require_once 'ListTable.php'; +require_once 'Installer.php'; use AffiliIR\Woocommerce as AffiliIR_Woocommerce; use AffiliIR\ListTable as AffiliIR_ListTable; +use AffiliIR\Installer as AffiliIR_Installer; class Action { @@ -81,6 +83,8 @@ public function setAccountId() $condition = isset($_POST['affili_set_account_id']) && $nonce; if($condition) { + $this->createTableIfNotExists(); + $account_id = sanitize_text_field($_POST['account_id']); $data = [ 'name' => 'account_id', @@ -338,4 +342,12 @@ public function findCategoryAjax() echo json_encode( $return ); wp_die(); } + + private function createTableIfNotExists() + { + $sql = AffiliIR_Installer::sqlString(); + $table_name = $this->wpdb->prefix.AffiliIR_Installer::$table; + + maybe_create_table($table_name, $sql); + } } \ No newline at end of file diff --git a/classes/Installer.php b/classes/Installer.php index b267e9b..89b4746 100644 --- a/classes/Installer.php +++ b/classes/Installer.php @@ -17,6 +17,19 @@ public static function activation() return; } + $sql = self::sqlString(); + + dbDelta($sql); + update_option(self::$table.'_db_version', $db_version); + } + + public static function deactivation() + { + // + } + + public static function sqlString() + { global $wpdb; $table_name = $wpdb->prefix.self::$table; @@ -32,12 +45,6 @@ public static function activation() ) {$charset_collate};" ; - dbDelta($sql); - update_option(self::$table.'_db_version', $db_version); - } - - public static function deactivation() - { - // + return $sql; } } \ No newline at end of file