PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.2
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.2
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Admin / Permalink.php

Permalink.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.2, at includes/Admin/Permalink.php

77 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add a POS settings on the permalink admin page.
4 *
5 * @author Paul Kilmurray <paul@kilbot.com.au>
6 *
7 * @see http://www.wcpos.com
8 * @package WCPOS\WooCommercePOS
9 */
10
11 namespace WCPOS\WooCommercePOS\Admin;
12
13 use const WCPOS\WooCommercePOS\PLUGIN_NAME;
14
15 /**
16 * Permalink class.
17 */
18 class Permalink {
19 public const DB_KEY = 'woocommerce_pos_settings_permalink';
20
21 /**
22 * Constructor.
23 */
24 public function __construct() {
25 $this->init();
26 $this->save();
27 }
28
29 /**
30 * Output the POS field.
31 */
32 public function pos_slug_input(): void {
33 $slug = self::get_slug();
34 if ( 'pos' === $slug ) {
35 $slug = ''; // use placeholder.
36 }
37 echo '<input name="woocommerce_pos_permalink" type="text" class="regular-text code" value="' . esc_attr( $slug ) . '" placeholder="pos" />';
38 wp_nonce_field( 'wcpos-permalinks', 'wcpos-permalinks-nonce' );
39 }
40
41 /**
42 * Watch for $_POST and save POS setting
43 * - sanitize field and remove slash from start and end.
44 */
45 public function save(): void {
46 if ( isset( $_POST['woocommerce_pos_permalink'], $_POST['wcpos-permalinks-nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['wcpos-permalinks-nonce'] ), 'wcpos-permalinks' ) ) {
47 $permalink = trim( sanitize_text_field( wp_unslash( $_POST['woocommerce_pos_permalink'] ) ), '/\\' );
48 update_option( self::DB_KEY, $permalink );
49 }
50 }
51
52 /**
53 * Return the custom slug, defaults to 'pos'.
54 *
55 * @return string
56 */
57 public static function get_slug(): string {
58 $slug = get_option( self::DB_KEY );
59
60 return empty( $slug ) ? 'pos' : sanitize_text_field( $slug );
61 }
62
63 /**
64 * Hook into the permalinks setting api.
65 */
66 private function init(): void {
67 add_settings_field(
68 'woocommerce-pos-permalink',
69 /* translators: Permalink settings label for the POS base URL. */
70 _x( 'POS base', 'Permalink setting, eg: /pos', 'woocommerce-pos' ),
71 array( $this, 'pos_slug_input' ),
72 'permalink',
73 'optional'
74 );
75 }
76 }
77