| @@ -9,15 +9,16 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | use BitCode\BitForm\Core\Database\DB; |
| 12 | 12 | use BitCode\BitForm\Core\Database\FormModel; |
| 13 | +use BitCode\BitForm\Core\Fallback\Form as FormFallback; | |
| 13 | 14 | use BitCode\BitForm\Core\Hooks\Hooks; |
| 14 | 15 | use BitCode\BitForm\Core\Util\Activation; |
| 15 | 16 | use BitCode\BitForm\Core\Util\Deactivation; |
| 16 | -use BitCode\BitForm\Core\Util\FrontendHelpers; | |
| 17 | 17 | use BitCode\BitForm\Core\Util\Uninstallation; |
| 18 | 18 | |
| 19 | -final class Plugin { | |
| 19 | +final class Plugin | |
| 20 | +{ | |
| 20 | 21 | /** |
| 21 | 22 | * Main instance of the plugin. |
| 22 | 23 | * |
| 23 | 24 | * @since 1.0.0-alpha |
| @@ -29,34 +30,18 @@ | ||
| 29 | 30 | * Registers the plugin with WordPress. |
| 30 | 31 | * |
| 31 | 32 | * @since 1.0.0-alpha |
| 32 | 33 | */ |
| 33 | - public function register() { | |
| 34 | + public function register() | |
| 35 | + { | |
| 34 | 36 | add_action('plugins_loaded', [$this, 'init_plugin']); |
| 35 | - add_action('init', [$this, 'checkIfFirstHttpRequest']); | |
| 36 | 37 | (new Activation())->activate(); |
| 37 | 38 | (new Deactivation())->register(); |
| 38 | 39 | (new Uninstallation())->register(); |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | - public function checkIfFirstHttpRequest() { | |
| 42 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; | |
| 43 | - $referrerQueryParams = FrontendHelpers::parseQueryParams($referrer); | |
| 44 | - $pageBuilderQueryParams = FrontendHelpers::$pageBuilderList; | |
| 45 | - $referrerMatchesWithPageBuilder = array_intersect_assoc($referrerQueryParams, $pageBuilderQueryParams); | |
| 46 | - if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($referrer) && 0 === count($referrerMatchesWithPageBuilder)) { | |
| 47 | - delete_transient('is_page_builder'); | |
| 48 | - delete_transient('bf_frontend_form_ids'); | |
| 49 | - $currentUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; | |
| 50 | - $currentUrlQueryParams = FrontendHelpers::parseQueryParams($currentUrl); | |
| 51 | - $currentUrlMatchesWithPageBuilder = array_intersect_assoc($currentUrlQueryParams, $pageBuilderQueryParams); | |
| 52 | - if (0 !== count($currentUrlMatchesWithPageBuilder)) { | |
| 53 | - set_transient('is_page_builder', true); | |
| 54 | - } | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | - private function commaReplace($options, $lbl, $val) { | |
| 42 | + private function commaReplace($options, $lbl, $val) | |
| 43 | + { | |
| 59 | 44 | foreach ($options as $key => $option) { |
| 60 | 45 | if (!empty($option[$lbl]) && !empty($option[$val])) { |
| 61 | 46 | $options[$key][$val] = str_replace(',', '_', $option[$val]); |
| 62 | 47 | } |
| @@ -66,9 +51,10 @@ | ||
| 66 | 51 | } |
| 67 | 52 | return $options; |
| 68 | 53 | } |
| 69 | 54 | |
| 70 | - private function replaceOptionSeparator($formContent) { | |
| 55 | + private function replaceOptionSeparator($formContent) | |
| 56 | + { | |
| 71 | 57 | $updated = false; |
| 72 | 58 | foreach ($formContent['fields'] as $key => $field) { |
| 73 | 59 | if ('check' === $field['typ']) { |
| 74 | 60 | $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'lbl', 'val'); |
| @@ -81,9 +67,10 @@ | ||
| 81 | 67 | } |
| 82 | 68 | return [$formContent, $updated]; |
| 83 | 69 | } |
| 84 | 70 | |
| 85 | - public function optionFallBack() { | |
| 71 | + public function optionFallBack() | |
| 72 | + { | |
| 86 | 73 | $formModel = new FormModel(); |
| 87 | 74 | $forms = $formModel->get( |
| 88 | 75 | ['id', 'form_content'] |
| 89 | 76 | ); |
| @@ -108,9 +95,10 @@ | ||
| 108 | 95 | * Updates bit form content tables on wp db |
| 109 | 96 | * |
| 110 | 97 | * @return void |
| 111 | 98 | */ |
| 112 | - public function update_tables() { | |
| 99 | + public function update_tables() | |
| 100 | + { | |
| 113 | 101 | if (!current_user_can('manage_options')) { |
| 114 | 102 | return; |
| 115 | 103 | } |
| 116 | 104 | |
| @@ -127,9 +115,15 @@ | ||
| 127 | 115 | * @param array $links |
| 128 | 116 | * |
| 129 | 117 | * @return array |
| 130 | 118 | */ |
| 131 | - public function init_plugin() { | |
| 119 | + public function init_plugin() | |
| 120 | + { | |
| 121 | + $currentBitFormVersion = BITFORMS_VERSION; | |
| 122 | + $installedBitFormVersion = get_option('bitforms_version'); | |
| 123 | + if ($currentBitFormVersion !== $installedBitFormVersion) { | |
| 124 | + (new FormFallback())->resetJsGeneratedPageIds(); | |
| 125 | + } | |
| 132 | 126 | Hooks::init_hooks(); |
| 133 | 127 | $this->update_tables(); |
| 134 | 128 | do_action('bitform_loaded'); |
| 135 | 129 | } |
| @@ -140,13 +134,15 @@ | ||
| 140 | 134 | * @since 1.0.0-alpha |
| 141 | 135 | * |
| 142 | 136 | * @return BITFORM Plugin main instance. |
| 143 | 137 | */ |
| 144 | - public static function instance() { | |
| 138 | + public static function instance() | |
| 139 | + { | |
| 145 | 140 | return static::$instance; |
| 146 | 141 | } |
| 147 | 142 | |
| 148 | - public function plugin_action_links($links) { | |
| 143 | + public function plugin_action_links($links) | |
| 144 | + { | |
| 149 | 145 | $links[] = '<a href="https://docs.form.bitapps.pro" target="_blank">' . __('Docs') . '</a>'; |
| 150 | 146 | |
| 151 | 147 | return $links; |
| 152 | 148 | } |
| @@ -157,9 +153,10 @@ | ||
| 157 | 153 | * @param string $main_file Absolute path to the plugin main file. |
| 158 | 154 | * |
| 159 | 155 | * @return bool True if the plugin main instance could be loaded, false otherwise. |
| 160 | 156 | */ |
| 161 | - public static function load($main_file) { | |
| 157 | + public static function load($main_file) | |
| 158 | + { | |
| 162 | 159 | if (null !== static::$instance) { |
| 163 | 160 | return false; |
| 164 | 161 | } |
| 165 | 162 | |