WC_POS_Admin_Permalink

Add a POS settings on the permalink admin page.

Defined (1)

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

/includes/admin/class-wc-pos-permalink.php  
  1. class WC_POS_Admin_Permalink { 
  2.  
  3. const DB_KEY = 'woocommerce_pos_settings_permalink'; 
  4.  
  5. /** 
  6. * Constructor 
  7. */ 
  8. public function __construct() { 
  9. $this->init(); 
  10. $this->save(); 
  11.  
  12. /** 
  13. * Hook into the permalinks setting api 
  14. */ 
  15. private function init() { 
  16. add_settings_field( 
  17. 'woocommerce-pos-permalink',  
  18. _x( 'POS base', 'Permalink setting, eg: /pos', 'woocommerce-pos' ),  
  19. array( $this, 'pos_slug_input' ),  
  20. 'permalink',  
  21. 'optional' 
  22. ); 
  23.  
  24. /** 
  25. * Output the POS field 
  26. */ 
  27. public function pos_slug_input() { 
  28. $slug = self::get_slug(); 
  29. if( $slug === 'pos' ) $slug = ''; // use placeholder 
  30. echo '<input name="woocommerce_pos_permalink" type="text" class="regular-text code" value="'. esc_attr( $slug ) .'" placeholder="pos" />'; 
  31.  
  32. /** 
  33. * Watch for $_POST and save POS setting 
  34. * - sanitize field and remove slash from start and end 
  35. */ 
  36. public function save() { 
  37. if( isset( $_POST['woocommerce_pos_permalink'] ) ) { 
  38. $permalink = trim( sanitize_text_field( $_POST['woocommerce_pos_permalink'] ), '/\\' ); 
  39. update_option( self::DB_KEY, $permalink ); 
  40.  
  41. /** 
  42. * Return the custom slug, defaults to 'pos' 
  43. * @return string 
  44. */ 
  45. static public function get_slug() { 
  46. $slug = get_option( self::DB_KEY ); 
  47. return empty( $slug ) ? 'pos' : sanitize_text_field( $slug ); 
  48.