WC_Payment_Discounts_Admin

WC_Payment_Discounts_Admin class.

Defined (1)

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

/includes/admin/class-wc-payment-discounts-admin.php  
  1. class WC_Payment_Discounts_Admin { 
  2.  
  3. /** 
  4. * Initialize the plugin admin. 
  5. */ 
  6. public function __construct() { 
  7. // Add the options page and menu item. 
  8. add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) ); 
  9.  
  10. // Register plugin settings. 
  11. add_action( 'admin_init', array( $this, 'register_settings' ) ); 
  12.  
  13. $this->maybe_update(); 
  14.  
  15. /** 
  16. * Maybe update the plugin. 
  17. */ 
  18. protected function maybe_update() { 
  19. $current_version = get_option( 'woocommerce_payment_discounts_version', '0' ); 
  20.  
  21. if ( ! version_compare( $current_version, WC_Payment_Discounts::VERSION, '>=' ) ) { 
  22. update_option( 'woocommerce_payment_discounts_version', WC_Payment_Discounts::VERSION ); 
  23.  
  24. /** 
  25. * Register the administration menu for this plugin into the WordPress Dashboard menu. 
  26. * @return void 
  27. */ 
  28. public function add_plugin_admin_menu() { 
  29. add_submenu_page( 
  30. 'woocommerce',  
  31. __( 'Payment Discounts', 'woocommerce-payment-discounts' ),  
  32. __( 'Payment Discounts', 'woocommerce-payment-discounts' ),  
  33. 'manage_woocommerce',  
  34. 'woocommerce-payment-discounts',  
  35. array( $this, 'display_plugin_admin_page' ) 
  36. ); 
  37.  
  38. /** 
  39. * Register plugin settings. 
  40. * @return void 
  41. */ 
  42. public function register_settings() { 
  43. register_setting( 'woocommerce_payment_discounts_group', 'woocommerce_payment_discounts', array( $this, 'validate_settings' ) ); 
  44.  
  45. /** 
  46. * Validate the plugin settings. 
  47. * @param array $options Submitted values. 
  48. * @return array Fixed values. 
  49. */ 
  50. public function validate_settings( $options ) { 
  51. $output = array(); 
  52.  
  53. foreach ( $options as $key => $value ) { 
  54. if ( isset( $options[ $key ] ) ) { 
  55. if ( strstr( $value, '%' ) ) { 
  56. $value = str_replace( '%', '', floatval( $value ) ) . '%'; 
  57. } else { 
  58. $value = floatval( $value ); 
  59.  
  60. $output[ $key ] = $value; 
  61.  
  62. return $output; 
  63.  
  64. /** 
  65. * Render the settings page for this plugin. 
  66. * @return string Settings page content. 
  67. */ 
  68. public function display_plugin_admin_page() { 
  69. $settings = get_option( 'woocommerce_payment_discounts' ); 
  70. $payment_gateways = WC()->payment_gateways->payment_gateways(); 
  71.  
  72. include_once 'views/html-admin-settings.php';