/** * Legacy data upgrades from anything prior to version 2.0 of OptinMonster. * * @since 2.0.0 */ public function legacy_20() { // Grab optins (but not any in cache). $optins = get_posts(array('post_type' => 'optin', 'posts_per_page' => -1)); if (!$optins) { return; } // Loop through each optin and update meta structures. foreach ((array) $optins as $optin) { $meta = get_post_meta($optin->ID, '_om_meta', true); // If the optin is a clone, create its own post meta field. if (isset($meta['is_clone']) && $meta['is_clone']) { update_post_meta($optin->ID, '_om_is_clone', $meta['is_clone']); } // If the optin has a clone, create its own post meta field as an array to allow unlimited split tests. if (isset($meta['has_clone']) && $meta['has_clone']) { $clones = array(); $clones[] = $meta['has_clone']; update_post_meta($optin->ID, '_om_has_clone', $clones); } // Convert each theme name to the proper name for v2. if (!empty($meta['theme'])) { switch ($meta['theme']) { case 'balance-theme': $meta['theme'] = 'balance'; break; case 'bullseye-theme': $meta['theme'] = 'bullseye'; break; case 'case-study-theme': $meta['theme'] = 'case-study'; break; case 'chalkboard-theme': $meta['theme'] = 'chalkboard'; break; case 'clean-slate-theme': $meta['theme'] = 'clean-slate'; break; case 'pendleton-theme': $meta['theme'] = 'pendleton'; break; case 'postal-theme': $meta['theme'] = 'postal'; break; case 'target-theme': $meta['theme'] = 'target'; break; case 'transparent-theme': $meta['theme'] = 'transparent'; break; case 'whiteboard-theme': $meta['theme'] = 'whiteboard'; break; case 'sleek-theme': $meta['theme'] = 'sleek'; break; case 'tiles-theme': $meta['theme'] = 'tiles'; break; case 'action-theme': $meta['theme'] = 'action'; break; case 'banner-theme': $meta['theme'] = 'banner'; break; case 'fabric-theme': $meta['theme'] = 'fabric'; break; case 'valley-theme': $meta['theme'] = 'valley'; break; case 'converse-theme': $meta['theme'] = 'converse'; break; } // Update the meta so that the theme name is updated. update_post_meta($optin->ID, '_om_meta', $meta); } } // Grab options from the old v1 setting and add it to the new setting. $v1_option = get_option('optin_monster_license'); $v2_option = get_option('optin_monster'); if (!$v2_option || empty($v2_option)) { $v2_option = Optin_Monster::default_options(); } if (!empty($v1_option['key'])) { $v2_option['key'] = $v1_option['key']; } if (!empty($v1_option['global_cookie'])) { $v2_option['cookie'] = $v1_option['global_cookie']; } if (!empty($v1_option['aff_link'])) { $v2_option['affiliate_link'] = $v1_option['aff_link']; } if (!empty($v1_option['aff_link_pos'])) { $v2_option['affiliate_link_position'] = $v1_option['aff_link_pos']; } // Update the new option. update_option('optin_monster', $v2_option); // Update the option to be sure this does not run again. update_option('optin_monster_upgrade_2.0', true); }
/** * Deactivates a license key entered by the user. * * @since 2.0.0 */ public function deactivate_key() { // Perform a request to deactivate the key. $deactivate = $this->perform_remote_request('deactivate-key', array('tgm-updater-key' => $_POST['optin-monster-license-key'])); // If it returns false, send back a generic error message and return. if (!$deactivate) { $this->errors[] = __('There was an error connecting to the remote key API. Please try again later.', 'optin-monster'); return; } // If an error is returned, set the error and return. if (!empty($deactivate->error)) { $this->errors[] = $deactivate->error; return; } // Otherwise, our request has been done successfully. Reset the option and set the success message. $this->success[] = isset($deactivate->success) ? $deactivate->success : __('Congratulations! You have deactivated the key from this site successfully.', 'optin-monster'); update_option('optin_monster', Optin_Monster::default_options()); }
/** * Sets our global option if it is not found in the DB. * * @since 2.0.0 */ public function set_option() { $option = get_option('optin_monster'); if (!$option || empty($option)) { $option = Optin_Monster::default_options(); update_option('optin_monster', $option); } }