PluginProbe
Ultimate Store Kit / 3.1.2
Ultimate Store Kit v3.1.2
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / includes / builder / meta.php

meta.php in Ultimate Store Kit 3.1.2, at includes/builder/meta.php

100 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit\Includes\Builder;
4
5 if (! defined('ABSPATH')) {
6 exit;
7 } // Exit if accessed directly
8
9 use UltimateStoreKit\Base\Singleton;
10
11 class Meta {
12
13 use Singleton;
14
15 const POST_TYPE = 'usk-template-builder';
16
17 const EDIT_WITH = '_ultimate_store_kit_edit_with';
18
19 const TEMPLATE_TYPE = '_ultimate_store_kit_template_type';
20
21 /**
22 * Prefix for the wp_options keys that record which builder template is
23 * assigned to each template type.
24 *
25 * These are options, not post meta, so the leading-underscore "protected"
26 * convention does not apply and a reserved "_" prefix is not permitted.
27 */
28 const TEMPLATE_ID = 'ultimate_store_kit_template_';
29
30 /**
31 * The pre-3.1.2 prefix. Still read so existing sites keep their assigned
32 * templates; see Meta::get_template_option().
33 */
34 const TEMPLATE_ID_LEGACY = '_usk_template_';
35
36 /**
37 * Read a template-assignment option, migrating it forward from the legacy
38 * "_usk_template_" key the first time it is seen.
39 *
40 * Historically some call sites lowercased the key and others did not, so a
41 * legacy site can hold two rows for the same template in different cases.
42 * Both spellings are tried before giving up.
43 *
44 * @param string $suffix Template type, e.g. "product|shop".
45 * @return mixed Option value, or false when unset.
46 */
47 public static function get_template_option($suffix) {
48 $key = strtolower(self::TEMPLATE_ID . $suffix);
49 $value = get_option($key, null);
50
51 if (null !== $value) {
52 return $value;
53 }
54
55 foreach ([self::TEMPLATE_ID_LEGACY . $suffix, strtolower(self::TEMPLATE_ID_LEGACY . $suffix)] as $legacy_key) {
56 $legacy = get_option($legacy_key, null);
57
58 if (null !== $legacy) {
59 update_option($key, $legacy);
60 delete_option($legacy_key);
61 return $legacy;
62 }
63 }
64
65 return false;
66 }
67
68 /**
69 * Write a template-assignment option, clearing any legacy row.
70 *
71 * @param string $suffix Template type.
72 * @param mixed $value Template post ID.
73 * @return void
74 */
75 public static function update_template_option($suffix, $value) {
76 update_option(strtolower(self::TEMPLATE_ID . $suffix), $value);
77 self::delete_legacy_template_option($suffix);
78 }
79
80 /**
81 * Delete a template-assignment option in both the current and legacy keys.
82 *
83 * @param string $suffix Template type.
84 * @return void
85 */
86 public static function delete_template_option($suffix) {
87 delete_option(strtolower(self::TEMPLATE_ID . $suffix));
88 self::delete_legacy_template_option($suffix);
89 }
90
91 /**
92 * @param string $suffix Template type.
93 * @return void
94 */
95 private static function delete_legacy_template_option($suffix) {
96 delete_option(self::TEMPLATE_ID_LEGACY . $suffix);
97 delete_option(strtolower(self::TEMPLATE_ID_LEGACY . $suffix));
98 }
99 }
100