1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace WC_POS\Admin;
13
14 class Permalink {
15
16 const DB_KEY = 'woocommerce_pos_settings_permalink';
17
18 19 20
21 public function __construct() {
22 $this->init();
23 $this->save();
24 }
25
26 27 28
29 private function init() {
30 add_settings_field(
31 'woocommerce-pos-permalink',
32 _x( 'POS base', 'Permalink setting, eg: /pos', 'woocommerce-pos' ),
33 array( $this, 'pos_slug_input' ),
34 'permalink',
35 'optional'
36 );
37 }
38
39 40 41
42 public function pos_slug_input() {
43 $slug = self::get_slug();
44 if( $slug === 'pos' ) $slug = '';
45 echo '<input name="woocommerce_pos_permalink" type="text" class="regular-text code" value="'. esc_attr( $slug ) .'" placeholder="pos" />';
46 }
47
48 49 50 51
52 public function save() {
53 if( isset( $_POST['woocommerce_pos_permalink'] ) ) {
54 $permalink = trim( sanitize_text_field( $_POST['woocommerce_pos_permalink'] ), '/\\' );
55 update_option( self::DB_KEY, $permalink );
56 }
57 }
58
59 60 61 62
63 static public function get_slug(){
64 $slug = get_option( self::DB_KEY );
65 return empty( $slug ) ? 'pos' : sanitize_text_field( $slug );
66 }
67
68 }