WCPBC_Install

WCPBC_Install Class.

Defined (1)

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

/includes/class-wcpbc-install.php  
  1. class WCPBC_Install { 
  2.  
  3. /** 
  4. * Hooks. 
  5. */ 
  6. public static function init() {  
  7.  
  8. add_action( 'admin_init', array( __CLASS__, 'update_actions' ), 5 ); 
  9. add_action( 'admin_init', array( __CLASS__, 'check_version' ) );  
  10.  
  11. /** 
  12. * Get install version 
  13. */ 
  14. private static function get_install_version() { 
  15.  
  16. $install_version = get_option( 'wc_price_based_country_version', null ); 
  17.  
  18. if ( is_null( $install_version ) && get_option('_oga_wppbc_countries_groups') ) { 
  19. $install_version = '1.3.1'; 
  20.  
  21. return $install_version; 
  22. }  
  23.  
  24. /** 
  25. * Update WCPBC version 
  26. */ 
  27. private static function update_wcpbc_version() { 
  28.  
  29. $current_version = self::get_install_version(); 
  30. $major_version = substr( WCPBC()->version, 0, strrpos( WCPBC()->version, '.' ) ); 
  31.  
  32. // Show welcome screen for new install and major updates only 
  33. if ( is_null( $current_version ) || version_compare( $current_version, $major_version, '<' ) ) { 
  34. set_transient( '_wcpbc_activation_redirect', 1, 30 );  
  35.  
  36. //update wcpbc version 
  37. delete_option( 'wc_price_based_country_version' ); 
  38. add_option( 'wc_price_based_country_version', WCPBC()->version ); 
  39.  
  40.  
  41. /** 
  42. * Install function  
  43. */  
  44. public static function install() { 
  45.  
  46. $current_version = self::get_install_version(); 
  47.  
  48. if ( null !== $current_version && version_compare( $current_version, '1.5.0', '<' ) ) { 
  49. add_action( 'admin_notices', array( __CLASS__, 'update_notice' ) ); 
  50. } else { 
  51. self::update_wcpbc_version(); 
  52.  
  53. /** 
  54. * check_version function. 
  55. */ 
  56. public static function check_version() { 
  57.  
  58. if ( ! defined( 'IFRAME_REQUEST' ) && version_compare( self::get_install_version(), '1.5.0', '<' ) ) { 
  59. add_action( 'admin_notices', array( __CLASS__, 'update_notice' ) ); 
  60.  
  61. } else { 
  62. self::check_default_customer_address(); 
  63.  
  64. /** 
  65. * check woocommerce default customer address 
  66. */ 
  67. public static function check_default_customer_address() { 
  68.  
  69. global $pagenow;  
  70.  
  71. if ( ! ( 'admin.php' == $pagenow && isset( $_GET['page'] ) && $_GET['page'] == 'wc-settings' && ( ! isset( $_GET['tab'] ) || ( isset( $_GET['tab'] ) && $_GET['tab'] == 'general' ) ) ) ) { 
  72.  
  73. $default_customer_address = get_option('woocommerce_default_customer_address'); 
  74.  
  75. if ( $default_customer_address !== 'geolocation' && $default_customer_address !== 'geolocation_ajax' ) { 
  76.  
  77. add_action( 'admin_notices', array( __CLASS__, 'geolocation_notice' ) );  
  78.  
  79. /** 
  80. * Update db admin notice 
  81. */  
  82. public static function update_notice() { 
  83. ?> 
  84. <div class="error"> 
  85. <p><?php _e( '<strong>WooCommerce Price Based Country Database Update Required</strong> – We just need to update your install to the latest version', 'wc-price-based-country' ); ?></p> 
  86. <p class="submit"><a href="<?php echo esc_url( add_query_arg( 'do_update_wc_price_based_country', 'true', admin_url( 'admin.php?page=wc-settings&tab=price_based_country' ) ) ); ?>" class="wc-update-now button-primary"><?php _e( 'Run the updater', 'woocommerce' ); ?></a></p> 
  87. </div> 
  88. <script type="text/javascript"> 
  89. jQuery('.wc-update-now').click('click', function() { 
  90. var answer = confirm( '<?php _e( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'woocommerce' ); ?>' ); 
  91. return answer; 
  92. }); 
  93. </script> 
  94. <?php 
  95.  
  96. /** 
  97. * Geolocation address notice 
  98. */  
  99. public static function geolocation_notice() { 
  100. ?> 
  101. <div class="updated woocommerce-message wc-connect"> 
  102. <p><?php _e( '<strong>WooCommerce Price Based Country</strong> required Geolocation Address to determine the customers default address. Go WooCommerce settings page and set <strong>Default Customer Address</strong> to <em>Geolocate Address</em>.', 'wc-price-based-country' ); ?></p>  
  103. <p class="submit"><a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings' ) ); ?>" class="button-primary"><?php _e( 'Go WooCommerce General Setting', 'woocommerce' ); ?></a></p> 
  104. </div>  
  105. <?php 
  106.  
  107. /** 
  108. * Handle updates 
  109. */ 
  110. public static function update_actions() { 
  111.  
  112. if ( ! empty( $_GET['do_update_wc_price_based_country'] ) ) { 
  113.  
  114. $install_version = self::get_install_version(); 
  115. $db_updates = array( 
  116. '1.3.2' => 'updates/wcpbc-update-1.3.2.php',  
  117. '1.4.0' => 'updates/wcpbc-update-1.4.0.php',  
  118. '1.5.0' => 'updates/wcpbc-update-1.5.0.php',  
  119. ); 
  120.  
  121. foreach ( $db_updates as $version => $updater ) { 
  122. if ( version_compare( $install_version, $version, '<' ) ) { 
  123. include( $updater );  
  124.  
  125. self::update_wcpbc_version();  
  126. }