/**
  * 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;
 }
 /**
  * Look up if url does exists in the current redirects
  *
  * @param string $url url to search for
  *
  * @return bool
  */
 public function check_if_redirect_exists($url)
 {
     $redirect_manager = new WPSEO_URL_Redirect_Manager();
     $redirects = $redirect_manager->get_redirects();
     return array_key_exists($url, $redirects);
 }
 /**
  * Setup the table variables, fetch the items from the database, search, sort and format the items.
  * Set the items as the WPSEO_Redirect_Table items variable.
  */
 public function prepare_items()
 {
     // Setup the columns
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Vies
     $this->views();
     // Get current view
     $current_view = $this->get_current_view();
     // Build crawl issues args
     $ci_args = array();
     // Set the post status
     $ci_args['post_status'] = 'publish';
     // Set the orderby
     $orderby = !empty($_GET['orderby']) ? $_GET['orderby'] : 'title';
     $ci_args['orderby'] = $orderby;
     // Set the order
     $order = !empty($_GET['order']) ? $_GET['order'] : 'asc';
     $ci_args['order'] = $order;
     // Prepares the issue filter
     $this->prepare_issue_filter();
     // Set the issue filter
     if ($issue_filter = get_transient('gwt-issue_filter')) {
         $filter_posts = $this->issue_filter($issue_filter);
         if (is_array($filter_posts) && !empty($filter_posts)) {
             $ci_args['post__in'] = $filter_posts;
         }
     }
     // Get variables needed for pagination
     $per_page = $this->get_items_per_page('errors_per_page', 25);
     $current_page = intval(isset($_GET['paged']) ? $_GET['paged'] : 1);
     // Set query pagination
     $ci_args['posts_per_page'] = $per_page;
     $ci_args['offset'] = ($current_page - 1) * $per_page;
     // Check current view
     if ('ignored' == $current_view) {
         $ci_args['post_status'] = 'trash';
     }
     // Filter crawl errors
     if ('not-redirected' == $current_view) {
         $url_redirect_manager = new WPSEO_URL_Redirect_Manager();
         $redirects = $url_redirect_manager->get_redirects();
         $wpseo_urls = array();
         if (count($redirects) > 0) {
             foreach ($redirects as $old_url => $new_url) {
                 $wpseo_urls[] = $old_url;
             }
         }
         $ci_args['wpseo_urls'] = $wpseo_urls;
     }
     // Get the crawl issues
     $crawl_issue_manager = new WPSEO_Crawl_Issue_Manager();
     $crawl_issues = $crawl_issue_manager->get_crawl_issues($this->gwt, $ci_args);
     // Get the total items
     $total_items = $crawl_issue_manager->get_latest_query()->found_posts;
     // Set table pagination
     $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => ceil($total_items / $per_page), 'per_page' => $per_page));
     // Set items
     $items_array = array();
     if (is_array($crawl_issues) && count($crawl_issues) > 0) {
         foreach ($crawl_issues as $crawl_issue) {
             $items_array[] = $crawl_issue->to_array();
         }
     }
     $this->items = $items_array;
 }