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