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