AIOSEOP_Updates

Handles detection of new plugin version updates.

Defined (1)

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

/inc/aioseop_updates_class.php  
  1. class AIOSEOP_Updates { 
  2.  
  3. /** 
  4. * Constructor 
  5. * @since 1.0.0 
  6. */ 
  7. function __construct() { 
  8.  
  9. /** 
  10. * Updates version. 
  11. * @since 1.0.0 
  12. * @global $aiosp , $aioseop_options. 
  13. * @return null 
  14. */ 
  15. function version_updates() { 
  16. global $aiosp, $aioseop_options; 
  17. if ( empty( $aioseop_options ) ) { 
  18. $aioseop_options = get_option( $aioseop_options ); 
  19. if ( empty( $aioseop_options ) ) { 
  20. // Something's wrong. bail. 
  21. return; 
  22.  
  23. // Last known running plugin version. 
  24. $last_active_version = '0.0'; 
  25. if ( isset( $aioseop_options['last_active_version'] ) ) { 
  26. $last_active_version = $aioseop_options['last_active_version']; 
  27.  
  28. // Compares version to see which one is the newer. 
  29. if ( version_compare( $last_active_version, AIOSEOP_VERSION, '<' ) ) { 
  30.  
  31. // Upgrades based on previous version. 
  32. do_action( 'before_doing_aioseop_updates' ); 
  33. $this->do_version_updates( $last_active_version ); 
  34. do_action( 'after_doing_aioseop_updates' ); 
  35. // If we're running Pro, let the Pro updater set the version. 
  36. if ( ! AIOSEOPPRO ) { 
  37.  
  38. // Save the current plugin version as the new last_active_version. 
  39. $aioseop_options['last_active_version'] = AIOSEOP_VERSION; 
  40. $aiosp->update_class_option( $aioseop_options ); 
  41.  
  42. /** 
  43. * Perform updates that are dependent on external factors, not 
  44. * just the plugin version. 
  45. */ 
  46. $this->do_feature_updates(); 
  47.  
  48.  
  49. /** 
  50. * Updates version. 
  51. * TODO: the compare here should be extracted into a function 
  52. * @since 1.0.0 
  53. * @global $aioseop_options . 
  54. * @param String $old_version 
  55. */ 
  56. function do_version_updates( $old_version ) { 
  57. global $aioseop_options; 
  58. if ( 
  59. ( ! AIOSEOPPRO && version_compare( $old_version, '2.3.3', '<' ) ) || 
  60. ( AIOSEOPPRO && version_compare( $old_version, '2.4.3', '<' ) ) 
  61. ) { 
  62. $this->bad_bots_201603(); 
  63.  
  64. if ( 
  65. ( ! AIOSEOPPRO && version_compare( $old_version, '2.3.4.1', '<' ) ) || 
  66. ( AIOSEOPPRO && version_compare( $old_version, '2.4.4.1', '<' ) ) 
  67. ) { 
  68. $this->bad_bots_remove_yandex_201604(); 
  69.  
  70.  
  71. /** 
  72. * Removes overzealous 'DOC' entry which is causing false-positive bad 
  73. * bot blocking. 
  74.   
  75. * @since 2.3.3 
  76. * @global $aiosp , $aioseop_options. 
  77. */ 
  78. function bad_bots_201603() { 
  79. global $aiosp, $aioseop_options; 
  80.  
  81. // Remove 'DOC' from bad bots list to avoid false positives. 
  82. if ( isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'] ) ) { 
  83. $list = $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist']; 
  84. $list = str_replace( array( 
  85. "DOC\r\n",  
  86. "DOC\n",  
  87. ), '', $list ); 
  88. $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'] = $list; 
  89. update_option( 'aioseop_options', $aioseop_options ); 
  90. $aiosp->update_class_option( $aioseop_options ); 
  91. if ( isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] ) 
  92. && 'on' === $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] 
  93. ) { 
  94. if ( ! class_exists( 'All_in_One_SEO_Pack_Bad_Robots' ) ) { 
  95. require_once( 
  96. AIOSEOP_PLUGIN_DIR . 
  97. 'admin/aioseop_module_class.php' 
  98. ); 
  99. require_once( 
  100. AIOSEOP_PLUGIN_DIR . 
  101. 'modules/aioseop_bad_robots.php' 
  102. ); 
  103. $aiosp_reset_htaccess = new All_in_One_SEO_Pack_Bad_Robots; 
  104. $aiosp_reset_htaccess->generate_htaccess_blocklist(); 
  105. if ( ! isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] ) 
  106. && extract_from_markers( get_home_path() . '.htaccess', 'Bad Bot Blocker' ) 
  107. ) { 
  108. insert_with_markers( get_home_path() . '.htaccess', 'Bad Bot Blocker', '' ); 
  109.  
  110. /** 
  111. * Functions for specific version milestones. 
  112. */ 
  113.  
  114. /** 
  115. * Remove 'yandex' entry. This is a major Russian search engine, and no longer needs to be blocked. 
  116. * @since 2.3.4.1 
  117. * @global $aiosp , $aioseop_options. 
  118. */ 
  119. function bad_bots_remove_yandex_201604() { 
  120. global $aiosp, $aioseop_options; 
  121.  
  122. // Remove 'yandex' from bad bots list to avoid false positives. 
  123. if ( isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'] ) ) { 
  124. $list = $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist']; 
  125. $list = str_replace( array( 
  126. "yandex\r\n",  
  127. "yandex\n",  
  128. ), '', $list ); 
  129. $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'] = $list; 
  130. update_option( 'aioseop_options', $aioseop_options ); 
  131. $aiosp->update_class_option( $aioseop_options ); 
  132.  
  133. if ( isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] ) && 'on' === $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] ) { 
  134.  
  135. if ( ! class_exists( 'All_in_One_SEO_Pack_Bad_Robots' ) ) { 
  136. require_once( AIOSEOP_PLUGIN_DIR . 'admin/aioseop_module_class.php' ); 
  137. require_once( AIOSEOP_PLUGIN_DIR . 'modules/aioseop_bad_robots.php' ); 
  138.  
  139. $aiosp_reset_htaccess = new All_in_One_SEO_Pack_Bad_Robots; 
  140. $aiosp_reset_htaccess->generate_htaccess_blocklist(); 
  141.  
  142. if ( ! isset( $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules'] ) && extract_from_markers( get_home_path() . '.htaccess', 'Bad Bot Blocker' ) ) { 
  143. insert_with_markers( get_home_path() . '.htaccess', 'Bad Bot Blocker', '' ); 
  144.  
  145. /** 
  146. * Updates features. 
  147.   
  148. * @since 1.0.0 
  149. * @return null 
  150. * if ( ! ( isset( $aioseop_options['version_feature_flags']['FEATURE_NAME'] ) && 
  151. * $aioseop_options['version_feature_flags']['FEATURE_NAME'] === 'yes' ) ) { 
  152. * $this->some_feature_update_method(); // sets flag to 'yes' on completion. 
  153. */ 
  154. public function do_feature_updates() { 
  155. global $aioseop_options; 
  156.  
  157. // We don't need to check all the time. Use a transient to limit frequency. 
  158. if ( get_site_transient( 'aioseop_update_check_time' ) ) { 
  159. return; 
  160.  
  161. // If we're running Pro, let the Pro updater set the transient. 
  162. if ( ! AIOSEOPPRO ) { 
  163.  
  164. // We haven't checked recently. Reset the timestamp, timeout 6 hours. 
  165. set_site_transient( 
  166. 'aioseop_update_check_time',  
  167. time(),  
  168. apply_filters( 'aioseop_update_check_time', 3600 * 6 ) 
  169. );