activate.php
6 months ago
admin.php
4 months ago
cache-plugin-filters.php
2 months ago
demo-widgets.php
7 months ago
elementor-widgets.php
1 month ago
feature-request.php
7 months ago
get-more-customers-box.php
7 months ago
rate-us-feedback-box.php
7 months ago
schema.php
9 months ago
shortcode-paste-box.php
7 months ago
step-list.php
7 months ago
troubleshooting.php
7 months ago
uninstall.php
6 months ago
update.php
6 months ago
update.php
85 lines
| 1 | <?php |
| 2 | defined('ABSPATH') or die('No script kiddies please!'); |
| 3 | require_once(ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'upgrade.php'); |
| 4 | global $wpdb; |
| 5 | if (version_compare($this->getVersion(), $this->getVersion('update-version-check'))) { |
| 6 | $tableName = $this->get_tablename('reviews'); |
| 7 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 8 | $results = $wpdb->get_results($wpdb->prepare('SHOW COLUMNS FROM %i', $tableName), ARRAY_A); |
| 9 | $columns = array_column($results, 'Field'); |
| 10 | |
| 11 | if (!in_array('highlight', $columns)) { |
| 12 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 13 | $wpdb->query($wpdb->prepare('ALTER TABLE %i ADD highlight VARCHAR(11) NULL AFTER rating', $tableName)); |
| 14 | } |
| 15 | |
| 16 | if (!in_array('reply', $columns)) { |
| 17 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 18 | $wpdb->query($wpdb->prepare('ALTER TABLE %i ADD reply TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL AFTER date', $tableName)); |
| 19 | } |
| 20 | if (in_array('replied', $columns)) { |
| 21 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 22 | $wpdb->query($wpdb->prepare('ALTER TABLE %i DROP replied', $tableName)); |
| 23 | } |
| 24 | if (!in_array('reviewId', $columns)) { |
| 25 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 26 | $wpdb->query($wpdb->prepare('ALTER TABLE %i ADD reviewId TEXT NULL AFTER date', $tableName)); |
| 27 | } |
| 28 | |
| 29 | if (!in_array('hidden', $columns)) { |
| 30 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 31 | $wpdb->query($wpdb->prepare('ALTER TABLE %i ADD hidden TINYINT(1) NOT NULL DEFAULT 0 AFTER id', $tableName)); |
| 32 | } |
| 33 | $oldRateUs = get_option('trustindex-'. $this->getShortName() .'-rate-us'); |
| 34 | if ($oldRateUs) { |
| 35 | if ($oldRateUs === 'hide') { |
| 36 | $this->setNotificationParam('rate-us', 'hidden', true); |
| 37 | } |
| 38 | else { |
| 39 | $this->setNotificationParam('rate-us', 'active', true); |
| 40 | $this->setNotificationParam('rate-us', 'timestamp', $oldRateUs); |
| 41 | } |
| 42 | } |
| 43 | $oldNotificationEmail = get_option('trustindex-'. $this->getShortName() .'-review-download-notification-email'); |
| 44 | if ($oldNotificationEmail) { |
| 45 | $this->setNotificationParam('review-download-finished', 'email', $oldNotificationEmail); |
| 46 | } |
| 47 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 48 | $results = $wpdb->get_results($wpdb->prepare('SELECT option_name FROM %i WHERE option_name LIKE %s', $wpdb->options, 'trustindex-'.$this->getShortName().'-%'), ARRAY_A); |
| 49 | $optionNamesInDb = array_column($results, 'option_name'); |
| 50 | $usedOptionNames = []; |
| 51 | foreach ($this->get_option_names() as $optName) { |
| 52 | $usedOptionNames []= $this->get_option_name($optName); |
| 53 | } |
| 54 | foreach ($optionNamesInDb as $optName) { |
| 55 | if (!in_array($optName, $usedOptionNames)) { |
| 56 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 57 | $wpdb->delete($wpdb->options, ['option_name' => $optName]); |
| 58 | } |
| 59 | } |
| 60 | if (get_option($this->get_option_name('css-content'))) { |
| 61 | $cssCdnVersion = $this->getCdnVersion('widget-css'); |
| 62 | if ($cssCdnVersion && version_compare($cssCdnVersion, $this->getVersion('widget-css'))) { |
| 63 | $this->noreg_save_css(true); |
| 64 | $this->updateVersion('widget-css', $cssCdnVersion); |
| 65 | } |
| 66 | } |
| 67 | if (get_option($this->get_option_name('review-content'))) { |
| 68 | $htmlCdnVersion = $this->getCdnVersion('widget-html'); |
| 69 | if ($htmlCdnVersion && version_compare($htmlCdnVersion, $this->getVersion('widget-html'))) { |
| 70 | delete_option($this->get_option_name('review-content')); |
| 71 | $this->updateVersion('widget-html', $htmlCdnVersion); |
| 72 | } |
| 73 | } |
| 74 | if (!$this->is_table_exists('views')) { |
| 75 | $tiReviewsTableName = $this->get_tablename('reviews'); |
| 76 | $tiViewsTableName = $this->get_tablename('views'); |
| 77 | include $this->get_plugin_dir() . 'include' . DIRECTORY_SEPARATOR . 'schema.php'; |
| 78 | try { |
| 79 | dbDelta(trim($ti_db_schema['views'])); |
| 80 | } catch (Exception $e) { } |
| 81 | } |
| 82 | $this->updateVersion('update-version-check', $this->getVersion()); |
| 83 | } |
| 84 | ?> |
| 85 |