/** * An update is required, do it * * @param $current_version */ private function do_update($current_version) { // < 1.0.4 if ($current_version < 5) { /** * Upgrade to version 1.0.4 * * - Save the old license to the new license option */ // Save the old license to the new license option $license_manager = new Yoast_Plugin_License_Manager(new WPSEO_Product_Premium()); $license_manager->set_license_key(trim(get_option('wpseo_license_key', ''))); $license_manager->set_license_status(trim(get_option('wpseo_license_status', ''))); // Remove old license options delete_option('wpseo_license_key'); delete_option('wpseo_license_status'); } // Upgrade to version 1.2.0 if ($current_version < 15) { /** * Upgrade redirects */ // URL Redirects $url_redirect_manager = new WPSEO_URL_Redirect_Manager(); $url_redirects = $url_redirect_manager->get_redirects(); // Loop through the redirects foreach ($url_redirects as $old_url => $redirect) { // Check if the redirect is not an array yet if (!is_array($redirect)) { $url_redirects[$old_url] = array('url' => $redirect, 'type' => '301'); } } // Save the URL redirects $url_redirect_manager->save_redirects($url_redirects); // Regex Redirects $regex_redirect_manager = new WPSEO_REGEX_Redirect_Manager(); $regex_redirects = $regex_redirect_manager->get_redirects(); // Loop through the redirects foreach ($regex_redirects as $old_url => $redirect) { // Check if the redirect is not an array yet if (!is_array($redirect)) { $regex_redirects[$old_url] = array('url' => $redirect, 'type' => '301'); } } // Save the URL redirects $regex_redirect_manager->save_redirects($regex_redirects); } }
/** * Generate file content * * @return string */ protected function generate_file_content() { $file_content = ""; // Generate URL redirects $url_redirect_manager = new WPSEO_URL_Redirect_Manager(); $url_redirects = $url_redirect_manager->get_redirects(); if (count($url_redirects) > 0) { foreach ($url_redirects as $old_url => $redirect) { $file_content .= $this->format_url_redirect($old_url, $redirect['url'], $redirect['type']) . "\n"; } } // Generate REGEX redirects $regex_redirect_manager = new WPSEO_REGEX_Redirect_Manager(); $regex_redirects = $regex_redirect_manager->get_redirects(); if (count($regex_redirects) > 0) { foreach ($regex_redirects as $regex => $redirect) { $file_content .= $this->format_regex_redirect($regex, $redirect['url'], $redirect['type']) . "\n"; } } return $file_content; }