PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
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
← All changes | includes/Admin/Permalink.php +25 -4 1.10.11.10.18 View file →
@@ -17,8 +17,11 @@
17 17 */
18 18 class Permalink {
19 19 public const DB_KEY = 'woocommerce_pos_settings_permalink';
20 20
21 + /** The slug served when the merchant never customised it. */
22 + public const DEFAULT_SLUG = 'pos';
23 +
21 24 /**
22 25 * Constructor.
23 26 */
24 27 public function __construct() {
@@ -30,12 +33,12 @@
30 33 * Output the POS field.
31 34 */
32 35 public function pos_slug_input(): void {
33 36 $slug = self::get_slug();
34 - if ( 'pos' === $slug ) {
37 + if ( self::DEFAULT_SLUG === $slug ) {
35 38 $slug = ''; // use placeholder.
36 39 }
37 - echo '<input name="woocommerce_pos_permalink" type="text" class="regular-text code" value="' . esc_attr( $slug ) . '" placeholder="pos" />';
40 + echo '<input name="woocommerce_pos_permalink" type="text" class="regular-text code" value="' . esc_attr( $slug ) . '" placeholder="' . esc_attr( self::DEFAULT_SLUG ) . '" />';
38 41 wp_nonce_field( 'wcpos-permalinks', 'wcpos-permalinks-nonce' );
39 42 }
40 43
41 44 /**
@@ -44,9 +47,10 @@
44 47 */
45 48 public function save(): void {
46 49 if ( isset( $_POST['woocommerce_pos_permalink'], $_POST['wcpos-permalinks-nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['wcpos-permalinks-nonce'] ), 'wcpos-permalinks' ) ) {
47 50 $permalink = trim( sanitize_text_field( wp_unslash( $_POST['woocommerce_pos_permalink'] ) ), '/\\' );
48 - update_option( self::DB_KEY, $permalink );
51 + // Autoloaded: Template_Router reads the slug on every request.
52 + update_option( self::DB_KEY, $permalink, true );
49 53 }
50 54 }
51 55
52 56 /**
@@ -56,9 +60,26 @@
56 60 */
57 61 public static function get_slug(): string {
58 62 $slug = get_option( self::DB_KEY );
59 63
60 - return empty( $slug ) ? 'pos' : sanitize_text_field( $slug );
64 + return false === $slug || '' === $slug ? self::DEFAULT_SLUG : sanitize_text_field( $slug );
65 + }
66 +
67 + /**
68 + * Make sure the option row exists, autoloaded.
69 + *
70 + * Template_Router reads the slug on every request. An ABSENT option is not
71 + * free: without a persistent object cache WordPress queries for it on every
72 + * request (the notoptions cache does not survive the request), so a store
73 + * that never customised the slug paid one query per page. Seeding an EMPTY
74 + * row makes the read an alloptions hit while get_slug() keeps resolving the
75 + * default from DEFAULT_SLUG — materialising 'pos' would freeze it and turn a
76 + * future default change into a migration. A customised value is left alone.
77 + */
78 + public static function ensure_default(): void {
79 + if ( false === get_option( self::DB_KEY ) ) {
80 + add_option( self::DB_KEY, '', '', true );
81 + }
61 82 }
62 83
63 84 /**
64 85 * Hook into the permalinks setting api.