1 | <?php |
||
11 | class Updater { |
||
12 | |||
13 | /** |
||
14 | * Relevant containers |
||
15 | * |
||
16 | * @var arrat |
||
17 | */ |
||
18 | public static $containers; |
||
19 | |||
20 | /** |
||
21 | * Instance of the Container_Validator class |
||
22 | * |
||
23 | * @var object |
||
24 | */ |
||
25 | public static $validator; |
||
26 | |||
27 | /** |
||
28 | * The fields that belong |
||
29 | * to the $containers |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | public static $fields; |
||
34 | |||
35 | /** |
||
36 | * Map for classes parsing |
||
37 | * special input types |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | public static $value_types = array( |
||
42 | 'complex' => 'Complex_Value_Parser', |
||
43 | 'association' => 'Association_Value_Parser', |
||
44 | 'map' => 'Map_Value_Parser', |
||
45 | 'map_with_address' => 'Map_Value_Parser', |
||
46 | ); |
||
47 | |||
48 | /** |
||
49 | * Flag indicating whether the update call |
||
50 | * is initialized by a REST request |
||
51 | * |
||
52 | * @var boolean |
||
53 | */ |
||
54 | public static $is_rest_request = false; |
||
55 | |||
56 | /** |
||
57 | * Load containers and fields, based on params |
||
58 | * |
||
59 | * @param string $context |
||
60 | * @param string $object_id |
||
61 | */ |
||
62 | public static function boot( $context, $object_id = '' ) { |
||
67 | |||
68 | /** |
||
69 | * Update Carbon Field |
||
70 | * |
||
71 | * @param string $context post_meta|term_meta|user_meta|comment_meta|theme_option |
||
72 | * @param string $object_id |
||
73 | * @param string $field_name |
||
74 | * @param mixed $input string|array|json |
||
75 | * @param string $value_type complex|map|map_with_address|association|null |
||
76 | */ |
||
77 | public static function update_field( $context, $object_id = '', $field_name, $input, $value_type = null ) { |
||
102 | |||
103 | /** |
||
104 | * Load all appropriate containers |
||
105 | * |
||
106 | * @param string $type |
||
107 | * @param string $id |
||
108 | */ |
||
109 | public static function load_containers( $type, $id = '' ) { |
||
120 | |||
121 | /** |
||
122 | * Extract all fields |
||
123 | * from the containers |
||
124 | */ |
||
125 | public static function load_fields() { |
||
132 | |||
133 | /** |
||
134 | * Retrieve Carbon Field by name |
||
135 | * |
||
136 | * @param string $field_name |
||
137 | * @return object |
||
138 | */ |
||
139 | public static function get_field_by_name( $field_name ) { |
||
150 | |||
151 | /** |
||
152 | * Normalize type |
||
153 | * |
||
154 | * @param string $type |
||
155 | * @return string |
||
156 | */ |
||
157 | public static function normalize_type( $type ) { |
||
166 | |||
167 | /** |
||
168 | * Decode json |
||
169 | * |
||
170 | * @param mixed $maybe_json |
||
171 | * @return array |
||
172 | */ |
||
173 | public static function maybe_json_decode( $maybe_json ) { |
||
180 | |||
181 | /** |
||
182 | * is_json |
||
183 | * |
||
184 | * @param string $string |
||
185 | * @return boolean |
||
186 | */ |
||
187 | public static function is_json( $string ) { |
||
190 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: