WPSEO_Upgrade

This code handles the option upgrades.

Defined (1)

The class is defined in the following location(s).

/inc/class-upgrade.php  
  1. class WPSEO_Upgrade { 
  2.  
  3. /** 
  4. * Holds the Yoast SEO options 
  5. * @var array 
  6. */ 
  7. private $options = array(); 
  8.  
  9. /** 
  10. * Class constructor 
  11. */ 
  12. public function __construct() { 
  13. $this->options = WPSEO_Options::get_option( 'wpseo' ); 
  14.  
  15. WPSEO_Options::maybe_set_multisite_defaults( false ); 
  16.  
  17. if ( version_compare( $this->options['version'], '1.5.0', '<' ) ) { 
  18. $this->upgrade_15( $this->options['version'] ); 
  19.  
  20. if ( version_compare( $this->options['version'], '2.0', '<' ) ) { 
  21. $this->upgrade_20(); 
  22.  
  23. if ( version_compare( $this->options['version'], '2.1', '<' ) ) { 
  24. $this->upgrade_21(); 
  25.  
  26. if ( version_compare( $this->options['version'], '2.2', '<' ) ) { 
  27. $this->upgrade_22(); 
  28.  
  29. if ( version_compare( $this->options['version'], '2.3', '<' ) ) { 
  30. $this->upgrade_23(); 
  31.  
  32. if ( version_compare( $this->options['version'], '3.0', '<' ) ) { 
  33. $this->upgrade_30(); 
  34.  
  35. if ( version_compare( $this->options['version'], '3.3', '<' ) ) { 
  36. $this->upgrade_33(); 
  37.  
  38. if ( version_compare( $this->options['version'], '3.6', '<' ) ) { 
  39. $this->upgrade_36(); 
  40.  
  41. if ( version_compare( $this->options['version'], '4.0', '<' ) ) { 
  42. $this->upgrade_40(); 
  43.  
  44. if ( version_compare( $this->options['version'], '4.4', '<' ) ) { 
  45. $this->upgrade_44(); 
  46.  
  47. // Since 3.7. 
  48. $upsell_notice = new WPSEO_Product_Upsell_Notice(); 
  49. $upsell_notice->set_upgrade_notice(); 
  50.  
  51. /** 
  52. * Filter: 'wpseo_run_upgrade' - Runs the upgrade hook which are dependent on Yoast SEO 
  53. * @api string - The current version of Yoast SEO 
  54. */ 
  55. do_action( 'wpseo_run_upgrade', $this->options['version'] ); 
  56.  
  57. $this->finish_up(); 
  58.  
  59. /** 
  60. * Run the Yoast SEO 1.5 upgrade routine 
  61. * @param string $version Current plugin version. 
  62. */ 
  63. private function upgrade_15( $version ) { 
  64. // Clean up options and meta. 
  65. WPSEO_Options::clean_up( null, $version ); 
  66. WPSEO_Meta::clean_up(); 
  67.  
  68. // Add new capabilities on upgrade. 
  69. wpseo_add_capabilities(); 
  70.  
  71. /** 
  72. * Moves options that moved position in WPSEO 2.0 
  73. */ 
  74. private function upgrade_20() { 
  75. /** 
  76. * Clean up stray wpseo_ms options from the options table, option should only exist in the sitemeta table. 
  77. * This could have been caused in many version of Yoast SEO, so deleting it for everything below 2.0 
  78. */ 
  79. delete_option( 'wpseo_ms' ); 
  80.  
  81. $this->move_pinterest_option(); 
  82.  
  83. /** 
  84. * Detects if taxonomy terms were split and updates the corresponding taxonomy meta's accordingly. 
  85. */ 
  86. private function upgrade_21() { 
  87. $taxonomies = get_option( 'wpseo_taxonomy_meta', array() ); 
  88.  
  89. if ( ! empty( $taxonomies ) ) { 
  90. foreach ( $taxonomies as $taxonomy => $tax_metas ) { 
  91. foreach ( $tax_metas as $term_id => $tax_meta ) { 
  92. if ( function_exists( 'wp_get_split_term' ) && $new_term_id = wp_get_split_term( $term_id, $taxonomy ) ) { 
  93. $taxonomies[ $taxonomy ][ $new_term_id ] = $taxonomies[ $taxonomy ][ $term_id ]; 
  94. unset( $taxonomies[ $taxonomy ][ $term_id ] ); 
  95.  
  96. update_option( 'wpseo_taxonomy_meta', $taxonomies ); 
  97.  
  98. /** 
  99. * Performs upgrade functions to Yoast SEO 2.2 
  100. */ 
  101. private function upgrade_22() { 
  102. // Unschedule our tracking. 
  103. wp_clear_scheduled_hook( 'yoast_tracking' ); 
  104.  
  105. // Clear the tracking settings, the seen about setting and the ignore tour setting. 
  106. $options = get_option( 'wpseo' ); 
  107. unset( $options['tracking_popup_done'], $options['yoast_tracking'], $options['seen_about'], $options['ignore_tour'] ); 
  108. update_option( 'wpseo', $options ); 
  109.  
  110. /** 
  111. * Schedules upgrade function to Yoast SEO 2.3 
  112. */ 
  113. private function upgrade_23() { 
  114. add_action( 'wp', array( $this, 'upgrade_23_query' ), 90 ); 
  115. add_action( 'admin_head', array( $this, 'upgrade_23_query' ), 90 ); 
  116.  
  117. /** 
  118. * Performs upgrade query to Yoast SEO 2.3 
  119. */ 
  120. public function upgrade_23_query() { 
  121. $wp_query = new WP_Query( 'post_type=any&meta_key=_yoast_wpseo_sitemap-include&meta_value=never&order=ASC' ); 
  122.  
  123. if ( ! empty( $wp_query->posts ) ) { 
  124. $options = get_option( 'wpseo_xml' ); 
  125.  
  126. $excluded_posts = array(); 
  127. if ( $options['excluded-posts'] !== '' ) { 
  128. $excluded_posts = explode( ', ', $options['excluded-posts'] ); 
  129.  
  130. foreach ( $wp_query->posts as $post ) { 
  131. if ( ! in_array( $post->ID, $excluded_posts ) ) { 
  132. $excluded_posts[] = $post->ID; 
  133.  
  134. // Updates the meta value. 
  135. $options['excluded-posts'] = implode( ', ', $excluded_posts ); 
  136.  
  137. // Update the option. 
  138. update_option( 'wpseo_xml', $options ); 
  139.  
  140. // Remove the meta fields. 
  141. delete_post_meta_by_key( '_yoast_wpseo_sitemap-include' ); 
  142.  
  143. /** 
  144. * Performs upgrade functions to Yoast SEO 3.0 
  145. */ 
  146. private function upgrade_30() { 
  147. // Remove the meta fields for sitemap prio. 
  148. delete_post_meta_by_key( '_yoast_wpseo_sitemap-prio' ); 
  149.  
  150. /** 
  151. * Performs upgrade functions to Yoast SEO 3.3 
  152. */ 
  153. private function upgrade_33() { 
  154. // Notification dismissals have been moved to User Meta instead of global option. 
  155. delete_option( Yoast_Notification_Center::STORAGE_KEY ); 
  156.  
  157. /** 
  158. * Performs upgrade functions to Yoast SEO 3.6 
  159. */ 
  160. private function upgrade_36() { 
  161. global $wpdb; 
  162.  
  163. // Between 3.2 and 3.4 the sitemap options were saved with autoloading enabled. 
  164. $wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "wpseo_sitemap_%" AND autoload = "yes"' ); 
  165.  
  166. /** 
  167. * Move the pinterest verification option from the wpseo option to the wpseo_social option 
  168. */ 
  169. private function move_pinterest_option() { 
  170. $options_social = get_option( 'wpseo_social' ); 
  171.  
  172. if ( isset( $option_wpseo['pinterestverify'] ) ) { 
  173. $options_social['pinterestverify'] = $option_wpseo['pinterestverify']; 
  174. unset( $option_wpseo['pinterestverify'] ); 
  175. update_option( 'wpseo_social', $options_social ); 
  176. update_option( 'wpseo', $option_wpseo ); 
  177.  
  178. /** 
  179. * Runs the needed cleanup after an update, setting the DB version to latest version, flushing caches etc. 
  180. */ 
  181. private function finish_up() { 
  182. $this->options = WPSEO_Options::get_option( 'wpseo' ); // Re-get to make sure we have the latest version. 
  183. update_option( 'wpseo', $this->options ); // This also ensures the DB version is equal to WPSEO_VERSION. 
  184.  
  185. add_action( 'shutdown', 'flush_rewrite_rules' ); // Just flush rewrites, always, to at least make them work after an upgrade. 
  186. WPSEO_Sitemaps_Cache::clear(); // Flush the sitemap cache. 
  187.  
  188. WPSEO_Options::ensure_options_exist(); // Make sure all our options always exist - issue #1245. 
  189.  
  190. /** 
  191. * Removes the about notice when its still in the database. 
  192. */ 
  193. private function upgrade_40() { 
  194. $center = Yoast_Notification_Center::get(); 
  195. $notification = $center->get_notification_by_id( 'wpseo-dismiss-about' ); 
  196.  
  197. if ( $notification ) { 
  198. $center->remove_notification( $notification ); 
  199.  
  200. /** 
  201. * Moves the content-analysis-active and keyword-analysis-acive options from wpseo-titles to wpseo. 
  202. */ 
  203. private function upgrade_44() { 
  204. $option_titles = WPSEO_Options::get_option( 'wpseo_titles' ); 
  205. $option_wpseo = WPSEO_Options::get_option( 'wpseo' ); 
  206.  
  207. if ( isset( $option_titles['content-analysis-active'] ) && isset( $option_titles['keyword-analysis-active'] ) ) { 
  208. $option_wpseo['content_analysis_active'] = $option_titles['content-analysis-active']; 
  209. unset( $option_titles['content-analysis-active'] ); 
  210.  
  211. $option_wpseo['keyword_analysis_active'] = $option_titles['keyword-analysis-active']; 
  212. unset( $option_titles['keyword-analysis-active'] ); 
  213.  
  214. update_option( 'wpseo_titles', $option_titles ); 
  215. update_option( 'wpseo', $option_wpseo );