WCPBC_Admin

WCPBC_Admin.

Defined (1)

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

/includes/admin/class-wcpbc-admin.php  
  1. class WCPBC_Admin { 
  2.  
  3. /** 
  4. * Hook actions and filters 
  5. */ 
  6. public static function init() { 
  7.  
  8. add_action( 'init', array( __CLASS__, 'includes' ) ); 
  9.  
  10. add_action( 'init', array( __CLASS__, 'about_hooks' ) ); 
  11.  
  12. add_action( 'current_screen', array( __CLASS__, 'dashboard_includes' ) ); 
  13.  
  14. add_action( 'admin_init', array( __CLASS__, 'admin_redirects' ) ); 
  15.  
  16. add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_admin_script' ) );  
  17.  
  18. add_filter( 'woocommerce_get_settings_pages', array( __CLASS__, 'settings_price_based_country' ) );  
  19.  
  20. add_filter( 'woocommerce_currency', array( __CLASS__, 'order_currency' ) );  
  21.  
  22.  
  23. /** 
  24. * Include any classes we need within admin. 
  25. */ 
  26. public static function includes() {  
  27.  
  28. include_once('class-wcpbc-admin-product-data.php');  
  29.  
  30. if ( in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {  
  31. include_once('class-wcpbc-admin-translation-management.php');  
  32.  
  33. do_action('wc_price_based_country_admin_init'); 
  34.  
  35. /** 
  36. * Add hooks to manage about page 
  37. */ 
  38. public static function about_hooks() { 
  39. if ( ! empty( $_GET['page'] ) && $_GET['page'] === 'wcpbc-about' ) { 
  40. add_action( 'admin_menu', array( __CLASS__, 'create_about_page' ) );  
  41.  
  42. /** 
  43. * Include admin files conditionally 
  44. */ 
  45. public static function dashboard_includes() { 
  46. $screen = get_current_screen(); 
  47.  
  48. if ( $screen->id == 'dashboard' ) {  
  49. include( 'class-wcpbc-admin-dashboard.php' ); 
  50.  
  51. /** 
  52. * Handle redirects to welcome page after install and updates. 
  53. * Transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. 
  54. */ 
  55. public static function admin_redirects() { 
  56. if ( ! get_transient( '_wcpbc_activation_redirect' ) ) { 
  57. return; 
  58.  
  59. delete_transient( '_wcpbc_activation_redirect' ); 
  60.  
  61. if ( ( ! empty( $_GET['page'] ) && $_GET['page'] === 'wcpbc-about' ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_woocommerce' ) ) { 
  62. return; 
  63.  
  64. wp_safe_redirect( admin_url( 'index.php?page=wcpbc-about' ) ); 
  65. exit; 
  66.  
  67.  
  68. /** 
  69. * Add Price Based Country settings tab to woocommerce settings 
  70. */ 
  71. public static function settings_price_based_country( $settings ) { 
  72.  
  73. $settings[] = include( 'settings/class-wc-settings-price-based-country.php' ); 
  74.  
  75. return $settings; 
  76. }  
  77.  
  78.  
  79. /** 
  80. * default currency in order 
  81. */ 
  82. public static function order_currency( $currency ) { 
  83.  
  84. global $post; 
  85.  
  86. if ($post && $post->post_type == 'shop_order' ) { 
  87.  
  88. global $theorder; 
  89. if ( $theorder )  
  90. return $theorder->order_currency; 
  91.  
  92.  
  93. return $currency; 
  94. }  
  95.  
  96. public static function load_admin_script( ) {  
  97.  
  98. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  99.  
  100. wp_enqueue_script( 'wc-price-based-country-admin', WCPBC()->plugin_url() . 'assets/js/wcpbc-admin' . $suffix . '.js', array('jquery'), WCPBC()->version, true );  
  101.  
  102.  
  103. /** 
  104. * Display the welcome/about page after successfully upgrading to the latest version. 
  105. * @since 1.5 
  106. */ 
  107. public static function create_about_page() { 
  108. $about_page = add_dashboard_page( __( 'Welcome to WooCommerce Price Based On Countries', 'wc-price-based-country' ), __( 'About WooCommerce Price Based On Countries', 'wc-price-based-country' ), 'manage_options', 'wcpbc-about', array( __CLASS__, 'about_screen' ) );  
  109. add_action( 'admin_head', array( __CLASS__, 'remove_about_page_link' ) ); 
  110.  
  111. /** 
  112. * Output the about screen. 
  113. */ 
  114. public static function about_screen() {  
  115. include_once( 'views/html-about.php' ); 
  116.  
  117. /** 
  118. * Remove dashboard about page link. 
  119. */ 
  120. public static function remove_about_page_link() { 
  121. remove_submenu_page( 'index.php', 'wcpbc-about' ); 
  122. }  
  123.