@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Navigation Menu functions |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Nav_Menus |
|
7 | - * @since 3.0.0 |
|
8 | - */ |
|
3 | + * Navigation Menu functions |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Nav_Menus |
|
7 | + * @since 3.0.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Returns a navigation menu object. |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | register_nav_menus( array( $location => $description ) ); |
127 | 127 | } |
128 | 128 | /** |
129 | - * Returns an array of all registered navigation menus in a theme |
|
130 | - * |
|
131 | - * @since 3.0.0 |
|
132 | - * |
|
133 | - * @global array $_wp_registered_nav_menus |
|
134 | - * |
|
135 | - * @return array |
|
136 | - */ |
|
129 | + * Returns an array of all registered navigation menus in a theme |
|
130 | + * |
|
131 | + * @since 3.0.0 |
|
132 | + * |
|
133 | + * @global array $_wp_registered_nav_menus |
|
134 | + * |
|
135 | + * @return array |
|
136 | + */ |
|
137 | 137 | function get_registered_nav_menus() { |
138 | 138 | global $_wp_registered_nav_menus; |
139 | 139 | if ( isset( $_wp_registered_nav_menus ) ) |
@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | * @param string $menu Menu ID, slug, or name - or the menu object. |
16 | 16 | * @return object|false False if $menu param isn't supplied or term does not exist, menu object if successful. |
17 | 17 | */ |
18 | -function wp_get_nav_menu_object( $menu ) { |
|
18 | +function wp_get_nav_menu_object($menu) { |
|
19 | 19 | $menu_obj = false; |
20 | 20 | |
21 | - if ( is_object( $menu ) ) { |
|
21 | + if (is_object($menu)) { |
|
22 | 22 | $menu_obj = $menu; |
23 | 23 | } |
24 | 24 | |
25 | - if ( $menu && ! $menu_obj ) { |
|
26 | - $menu_obj = get_term( $menu, 'nav_menu' ); |
|
25 | + if ($menu && ! $menu_obj) { |
|
26 | + $menu_obj = get_term($menu, 'nav_menu'); |
|
27 | 27 | |
28 | - if ( ! $menu_obj ) { |
|
29 | - $menu_obj = get_term_by( 'slug', $menu, 'nav_menu' ); |
|
28 | + if ( ! $menu_obj) { |
|
29 | + $menu_obj = get_term_by('slug', $menu, 'nav_menu'); |
|
30 | 30 | } |
31 | 31 | |
32 | - if ( ! $menu_obj ) { |
|
33 | - $menu_obj = get_term_by( 'name', $menu, 'nav_menu' ); |
|
32 | + if ( ! $menu_obj) { |
|
33 | + $menu_obj = get_term_by('name', $menu, 'nav_menu'); |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - if ( ! $menu_obj || is_wp_error( $menu_obj ) ) { |
|
37 | + if ( ! $menu_obj || is_wp_error($menu_obj)) { |
|
38 | 38 | $menu_obj = false; |
39 | 39 | } |
40 | 40 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param object|false $menu_obj Term from nav_menu taxonomy, or false if nothing had been found. |
47 | 47 | * @param string $menu The menu ID, slug, or name passed to wp_get_nav_menu_object(). |
48 | 48 | */ |
49 | - return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu ); |
|
49 | + return apply_filters('wp_get_nav_menu_object', $menu_obj, $menu); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | * @param int|string $menu The menu to check (ID, slug, or name). |
60 | 60 | * @return bool Whether the menu exists. |
61 | 61 | */ |
62 | -function is_nav_menu( $menu ) { |
|
63 | - if ( ! $menu ) |
|
62 | +function is_nav_menu($menu) { |
|
63 | + if ( ! $menu) |
|
64 | 64 | return false; |
65 | 65 | |
66 | - $menu_obj = wp_get_nav_menu_object( $menu ); |
|
66 | + $menu_obj = wp_get_nav_menu_object($menu); |
|
67 | 67 | |
68 | 68 | if ( |
69 | 69 | $menu_obj && |
70 | - ! is_wp_error( $menu_obj ) && |
|
71 | - ! empty( $menu_obj->taxonomy ) && |
|
70 | + ! is_wp_error($menu_obj) && |
|
71 | + ! empty($menu_obj->taxonomy) && |
|
72 | 72 | 'nav_menu' == $menu_obj->taxonomy |
73 | 73 | ) |
74 | 74 | return true; |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text. |
87 | 87 | */ |
88 | -function register_nav_menus( $locations = array() ) { |
|
88 | +function register_nav_menus($locations = array()) { |
|
89 | 89 | global $_wp_registered_nav_menus; |
90 | 90 | |
91 | - add_theme_support( 'menus' ); |
|
91 | + add_theme_support('menus'); |
|
92 | 92 | |
93 | - $_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations ); |
|
93 | + $_wp_registered_nav_menus = array_merge((array) $_wp_registered_nav_menus, $locations); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | * @param string $location The menu location identifier. |
102 | 102 | * @return bool True on success, false on failure. |
103 | 103 | */ |
104 | -function unregister_nav_menu( $location ) { |
|
104 | +function unregister_nav_menu($location) { |
|
105 | 105 | global $_wp_registered_nav_menus; |
106 | 106 | |
107 | - if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) { |
|
108 | - unset( $_wp_registered_nav_menus[$location] ); |
|
109 | - if ( empty( $_wp_registered_nav_menus ) ) { |
|
110 | - _remove_theme_support( 'menus' ); |
|
107 | + if (is_array($_wp_registered_nav_menus) && isset($_wp_registered_nav_menus[$location])) { |
|
108 | + unset($_wp_registered_nav_menus[$location]); |
|
109 | + if (empty($_wp_registered_nav_menus)) { |
|
110 | + _remove_theme_support('menus'); |
|
111 | 111 | } |
112 | 112 | return true; |
113 | 113 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param string $location Menu location identifier, like a slug. |
123 | 123 | * @param string $description Menu location descriptive text. |
124 | 124 | */ |
125 | -function register_nav_menu( $location, $description ) { |
|
126 | - register_nav_menus( array( $location => $description ) ); |
|
125 | +function register_nav_menu($location, $description) { |
|
126 | + register_nav_menus(array($location => $description)); |
|
127 | 127 | } |
128 | 128 | /** |
129 | 129 | * Returns an array of all registered navigation menus in a theme |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | function get_registered_nav_menus() { |
138 | 138 | global $_wp_registered_nav_menus; |
139 | - if ( isset( $_wp_registered_nav_menus ) ) |
|
139 | + if (isset($_wp_registered_nav_menus)) |
|
140 | 140 | return $_wp_registered_nav_menus; |
141 | 141 | return array(); |
142 | 142 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | */ |
150 | 150 | |
151 | 151 | function get_nav_menu_locations() { |
152 | - $locations = get_theme_mod( 'nav_menu_locations' ); |
|
153 | - return ( is_array( $locations ) ) ? $locations : array(); |
|
152 | + $locations = get_theme_mod('nav_menu_locations'); |
|
153 | + return (is_array($locations)) ? $locations : array(); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | * @param string $location Menu location identifier. |
162 | 162 | * @return bool Whether location has a menu. |
163 | 163 | */ |
164 | -function has_nav_menu( $location ) { |
|
164 | +function has_nav_menu($location) { |
|
165 | 165 | $has_nav_menu = false; |
166 | 166 | |
167 | 167 | $registered_nav_menus = get_registered_nav_menus(); |
168 | - if ( isset( $registered_nav_menus[ $location ] ) ) { |
|
168 | + if (isset($registered_nav_menus[$location])) { |
|
169 | 169 | $locations = get_nav_menu_locations(); |
170 | - $has_nav_menu = ! empty( $locations[ $location ] ); |
|
170 | + $has_nav_menu = ! empty($locations[$location]); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param bool $has_nav_menu Whether there is a menu assigned to a location. |
179 | 179 | * @param string $location Menu location. |
180 | 180 | */ |
181 | - return apply_filters( 'has_nav_menu', $has_nav_menu, $location ); |
|
181 | + return apply_filters('has_nav_menu', $has_nav_menu, $location); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * @param int $menu_item_id The ID of the potential nav menu item. |
190 | 190 | * @return bool Whether the given ID is that of a nav menu item. |
191 | 191 | */ |
192 | -function is_nav_menu_item( $menu_item_id = 0 ) { |
|
193 | - return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) ); |
|
192 | +function is_nav_menu_item($menu_item_id = 0) { |
|
193 | + return ( ! is_wp_error($menu_item_id) && ('nav_menu_item' == get_post_type($menu_item_id))); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string $menu_name Menu name. |
202 | 202 | * @return int|WP_Error Menu ID on success, WP_Error object on failure. |
203 | 203 | */ |
204 | -function wp_create_nav_menu( $menu_name ) { |
|
205 | - return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) ); |
|
204 | +function wp_create_nav_menu($menu_name) { |
|
205 | + return wp_update_nav_menu_object(0, array('menu-name' => $menu_name)); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -213,29 +213,29 @@ discard block |
||
213 | 213 | * @param string $menu Menu ID, slug, or name. |
214 | 214 | * @return bool|WP_Error True on success, false or WP_Error object on failure. |
215 | 215 | */ |
216 | -function wp_delete_nav_menu( $menu ) { |
|
217 | - $menu = wp_get_nav_menu_object( $menu ); |
|
218 | - if ( ! $menu ) |
|
216 | +function wp_delete_nav_menu($menu) { |
|
217 | + $menu = wp_get_nav_menu_object($menu); |
|
218 | + if ( ! $menu) |
|
219 | 219 | return false; |
220 | 220 | |
221 | - $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
|
222 | - if ( ! empty( $menu_objects ) ) { |
|
223 | - foreach ( $menu_objects as $item ) { |
|
224 | - wp_delete_post( $item ); |
|
221 | + $menu_objects = get_objects_in_term($menu->term_id, 'nav_menu'); |
|
222 | + if ( ! empty($menu_objects)) { |
|
223 | + foreach ($menu_objects as $item) { |
|
224 | + wp_delete_post($item); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | - $result = wp_delete_term( $menu->term_id, 'nav_menu' ); |
|
228 | + $result = wp_delete_term($menu->term_id, 'nav_menu'); |
|
229 | 229 | |
230 | 230 | // Remove this menu from any locations. |
231 | 231 | $locations = get_nav_menu_locations(); |
232 | - foreach ( $locations as $location => $menu_id ) { |
|
233 | - if ( $menu_id == $menu->term_id ) |
|
234 | - $locations[ $location ] = 0; |
|
232 | + foreach ($locations as $location => $menu_id) { |
|
233 | + if ($menu_id == $menu->term_id) |
|
234 | + $locations[$location] = 0; |
|
235 | 235 | } |
236 | - set_theme_mod( 'nav_menu_locations', $locations ); |
|
236 | + set_theme_mod('nav_menu_locations', $locations); |
|
237 | 237 | |
238 | - if ( $result && !is_wp_error($result) ) |
|
238 | + if ($result && ! is_wp_error($result)) |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Fires after a navigation menu has been successfully deleted. |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @param int $term_id ID of the deleted menu. |
246 | 246 | */ |
247 | - do_action( 'wp_delete_nav_menu', $menu->term_id ); |
|
247 | + do_action('wp_delete_nav_menu', $menu->term_id); |
|
248 | 248 | |
249 | 249 | return $result; |
250 | 250 | } |
@@ -258,38 +258,38 @@ discard block |
||
258 | 258 | * @param array $menu_data The array of menu data. |
259 | 259 | * @return int|WP_Error Menu ID on success, WP_Error object on failure. |
260 | 260 | */ |
261 | -function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { |
|
261 | +function wp_update_nav_menu_object($menu_id = 0, $menu_data = array()) { |
|
262 | 262 | $menu_id = (int) $menu_id; |
263 | 263 | |
264 | - $_menu = wp_get_nav_menu_object( $menu_id ); |
|
264 | + $_menu = wp_get_nav_menu_object($menu_id); |
|
265 | 265 | |
266 | 266 | $args = array( |
267 | - 'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ), |
|
268 | - 'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ), |
|
269 | - 'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ), |
|
267 | + 'description' => (isset($menu_data['description']) ? $menu_data['description'] : ''), |
|
268 | + 'name' => (isset($menu_data['menu-name']) ? $menu_data['menu-name'] : ''), |
|
269 | + 'parent' => (isset($menu_data['parent']) ? (int) $menu_data['parent'] : 0), |
|
270 | 270 | 'slug' => null, |
271 | 271 | ); |
272 | 272 | |
273 | 273 | // double-check that we're not going to have one menu take the name of another |
274 | - $_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' ); |
|
274 | + $_possible_existing = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); |
|
275 | 275 | if ( |
276 | 276 | $_possible_existing && |
277 | - ! is_wp_error( $_possible_existing ) && |
|
278 | - isset( $_possible_existing->term_id ) && |
|
277 | + ! is_wp_error($_possible_existing) && |
|
278 | + isset($_possible_existing->term_id) && |
|
279 | 279 | $_possible_existing->term_id != $menu_id |
280 | 280 | ) |
281 | - return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
281 | + return new WP_Error('menu_exists', sprintf(__('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html($menu_data['menu-name']))); |
|
282 | 282 | |
283 | 283 | // menu doesn't already exist, so create a new menu |
284 | - if ( ! $_menu || is_wp_error( $_menu ) ) { |
|
285 | - $menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' ); |
|
284 | + if ( ! $_menu || is_wp_error($_menu)) { |
|
285 | + $menu_exists = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); |
|
286 | 286 | |
287 | - if ( $menu_exists ) |
|
288 | - return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
287 | + if ($menu_exists) |
|
288 | + return new WP_Error('menu_exists', sprintf(__('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html($menu_data['menu-name']))); |
|
289 | 289 | |
290 | - $_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args ); |
|
290 | + $_menu = wp_insert_term($menu_data['menu-name'], 'nav_menu', $args); |
|
291 | 291 | |
292 | - if ( is_wp_error( $_menu ) ) |
|
292 | + if (is_wp_error($_menu)) |
|
293 | 293 | return $_menu; |
294 | 294 | |
295 | 295 | /** |
@@ -300,19 +300,19 @@ discard block |
||
300 | 300 | * @param int $term_id ID of the new menu. |
301 | 301 | * @param array $menu_data An array of menu data. |
302 | 302 | */ |
303 | - do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data ); |
|
303 | + do_action('wp_create_nav_menu', $_menu['term_id'], $menu_data); |
|
304 | 304 | |
305 | 305 | return (int) $_menu['term_id']; |
306 | 306 | } |
307 | 307 | |
308 | - if ( ! $_menu || ! isset( $_menu->term_id ) ) |
|
308 | + if ( ! $_menu || ! isset($_menu->term_id)) |
|
309 | 309 | return 0; |
310 | 310 | |
311 | 311 | $menu_id = (int) $_menu->term_id; |
312 | 312 | |
313 | - $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); |
|
313 | + $update_response = wp_update_term($menu_id, 'nav_menu', $args); |
|
314 | 314 | |
315 | - if ( is_wp_error( $update_response ) ) |
|
315 | + if (is_wp_error($update_response)) |
|
316 | 316 | return $update_response; |
317 | 317 | |
318 | 318 | $menu_id = (int) $update_response['term_id']; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param int $menu_id ID of the updated menu. |
326 | 326 | * @param array $menu_data An array of menu data. |
327 | 327 | */ |
328 | - do_action( 'wp_update_nav_menu', $menu_id, $menu_data ); |
|
328 | + do_action('wp_update_nav_menu', $menu_id, $menu_data); |
|
329 | 329 | return $menu_id; |
330 | 330 | } |
331 | 331 | |
@@ -339,21 +339,21 @@ discard block |
||
339 | 339 | * @param array $menu_item_data The menu item's data. |
340 | 340 | * @return int|WP_Error The menu item's database ID or WP_Error object on failure. |
341 | 341 | */ |
342 | -function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) { |
|
342 | +function wp_update_nav_menu_item($menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array()) { |
|
343 | 343 | $menu_id = (int) $menu_id; |
344 | 344 | $menu_item_db_id = (int) $menu_item_db_id; |
345 | 345 | |
346 | 346 | // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects |
347 | - if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) |
|
348 | - return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
347 | + if ( ! empty($menu_item_db_id) && ! is_nav_menu_item($menu_item_db_id)) |
|
348 | + return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.')); |
|
349 | 349 | |
350 | - $menu = wp_get_nav_menu_object( $menu_id ); |
|
350 | + $menu = wp_get_nav_menu_object($menu_id); |
|
351 | 351 | |
352 | - if ( ! $menu && 0 !== $menu_id ) { |
|
353 | - return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) ); |
|
352 | + if ( ! $menu && 0 !== $menu_id) { |
|
353 | + return new WP_Error('invalid_menu_id', __('Invalid menu ID.')); |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( is_wp_error( $menu ) ) { |
|
356 | + if (is_wp_error($menu)) { |
|
357 | 357 | return $menu; |
358 | 358 | } |
359 | 359 | |
@@ -374,19 +374,19 @@ discard block |
||
374 | 374 | 'menu-item-status' => '', |
375 | 375 | ); |
376 | 376 | |
377 | - $args = wp_parse_args( $menu_item_data, $defaults ); |
|
377 | + $args = wp_parse_args($menu_item_data, $defaults); |
|
378 | 378 | |
379 | - if ( 0 == $menu_id ) { |
|
379 | + if (0 == $menu_id) { |
|
380 | 380 | $args['menu-item-position'] = 1; |
381 | - } elseif ( 0 == (int) $args['menu-item-position'] ) { |
|
382 | - $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
|
383 | - $last_item = array_pop( $menu_items ); |
|
384 | - $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items ); |
|
381 | + } elseif (0 == (int) $args['menu-item-position']) { |
|
382 | + $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft')); |
|
383 | + $last_item = array_pop($menu_items); |
|
384 | + $args['menu-item-position'] = ($last_item && isset($last_item->menu_order)) ? 1 + $last_item->menu_order : count($menu_items); |
|
385 | 385 | } |
386 | 386 | |
387 | - $original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0; |
|
387 | + $original_parent = 0 < $menu_item_db_id ? get_post_field('post_parent', $menu_item_db_id) : 0; |
|
388 | 388 | |
389 | - if ( 'custom' != $args['menu-item-type'] ) { |
|
389 | + if ('custom' != $args['menu-item-type']) { |
|
390 | 390 | /* if non-custom menu item, then: |
391 | 391 | * use original object's URL |
392 | 392 | * blank default title to sync with original object's |
@@ -395,21 +395,21 @@ discard block |
||
395 | 395 | $args['menu-item-url'] = ''; |
396 | 396 | |
397 | 397 | $original_title = ''; |
398 | - if ( 'taxonomy' == $args['menu-item-type'] ) { |
|
399 | - $original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); |
|
400 | - $original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); |
|
401 | - } elseif ( 'post_type' == $args['menu-item-type'] ) { |
|
398 | + if ('taxonomy' == $args['menu-item-type']) { |
|
399 | + $original_parent = get_term_field('parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); |
|
400 | + $original_title = get_term_field('name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); |
|
401 | + } elseif ('post_type' == $args['menu-item-type']) { |
|
402 | 402 | |
403 | - $original_object = get_post( $args['menu-item-object-id'] ); |
|
403 | + $original_object = get_post($args['menu-item-object-id']); |
|
404 | 404 | $original_parent = (int) $original_object->post_parent; |
405 | 405 | $original_title = $original_object->post_title; |
406 | 406 | } |
407 | 407 | |
408 | - if ( $args['menu-item-title'] == $original_title ) |
|
408 | + if ($args['menu-item-title'] == $original_title) |
|
409 | 409 | $args['menu-item-title'] = ''; |
410 | 410 | |
411 | 411 | // hack to get wp to create a post object when too many properties are empty |
412 | - if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) |
|
412 | + if ('' == $args['menu-item-title'] && '' == $args['menu-item-description']) |
|
413 | 413 | $args['menu-item-description'] = ' '; |
414 | 414 | } |
415 | 415 | |
@@ -427,49 +427,49 @@ discard block |
||
427 | 427 | $update = 0 != $menu_item_db_id; |
428 | 428 | |
429 | 429 | // New menu item. Default is draft status |
430 | - if ( ! $update ) { |
|
430 | + if ( ! $update) { |
|
431 | 431 | $post['ID'] = 0; |
432 | 432 | $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; |
433 | - $menu_item_db_id = wp_insert_post( $post ); |
|
434 | - if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) |
|
433 | + $menu_item_db_id = wp_insert_post($post); |
|
434 | + if ( ! $menu_item_db_id || is_wp_error($menu_item_db_id)) |
|
435 | 435 | return $menu_item_db_id; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // Associate the menu item with the menu term |
439 | 439 | // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms() |
440 | - if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) { |
|
441 | - wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' ); |
|
440 | + if ($menu_id && ( ! $update || ! is_object_in_term($menu_item_db_id, 'nav_menu', (int) $menu->term_id))) { |
|
441 | + wp_set_object_terms($menu_item_db_id, array($menu->term_id), 'nav_menu'); |
|
442 | 442 | } |
443 | 443 | |
444 | - if ( 'custom' == $args['menu-item-type'] ) { |
|
444 | + if ('custom' == $args['menu-item-type']) { |
|
445 | 445 | $args['menu-item-object-id'] = $menu_item_db_id; |
446 | 446 | $args['menu-item-object'] = 'custom'; |
447 | 447 | } |
448 | 448 | |
449 | 449 | $menu_item_db_id = (int) $menu_item_db_id; |
450 | 450 | |
451 | - update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) ); |
|
452 | - update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) ); |
|
453 | - update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) ); |
|
454 | - update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) ); |
|
455 | - update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) ); |
|
451 | + update_post_meta($menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type'])); |
|
452 | + update_post_meta($menu_item_db_id, '_menu_item_menu_item_parent', strval((int) $args['menu-item-parent-id'])); |
|
453 | + update_post_meta($menu_item_db_id, '_menu_item_object_id', strval((int) $args['menu-item-object-id'])); |
|
454 | + update_post_meta($menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object'])); |
|
455 | + update_post_meta($menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target'])); |
|
456 | 456 | |
457 | - $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) ); |
|
458 | - $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) ); |
|
459 | - update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] ); |
|
460 | - update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); |
|
461 | - update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); |
|
457 | + $args['menu-item-classes'] = array_map('sanitize_html_class', explode(' ', $args['menu-item-classes'])); |
|
458 | + $args['menu-item-xfn'] = implode(' ', array_map('sanitize_html_class', explode(' ', $args['menu-item-xfn']))); |
|
459 | + update_post_meta($menu_item_db_id, '_menu_item_classes', $args['menu-item-classes']); |
|
460 | + update_post_meta($menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn']); |
|
461 | + update_post_meta($menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url'])); |
|
462 | 462 | |
463 | - if ( 0 == $menu_id ) |
|
464 | - update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
465 | - elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) |
|
466 | - delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
463 | + if (0 == $menu_id) |
|
464 | + update_post_meta($menu_item_db_id, '_menu_item_orphaned', (string) time()); |
|
465 | + elseif (get_post_meta($menu_item_db_id, '_menu_item_orphaned')) |
|
466 | + delete_post_meta($menu_item_db_id, '_menu_item_orphaned'); |
|
467 | 467 | |
468 | 468 | // Update existing menu item. Default is publish status |
469 | - if ( $update ) { |
|
469 | + if ($update) { |
|
470 | 470 | $post['ID'] = $menu_item_db_id; |
471 | 471 | $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; |
472 | - wp_update_post( $post ); |
|
472 | + wp_update_post($post); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @param int $menu_item_db_id ID of the updated menu item. |
484 | 484 | * @param array $args An array of arguments used to update a menu item. |
485 | 485 | */ |
486 | - do_action( 'wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args ); |
|
486 | + do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args); |
|
487 | 487 | |
488 | 488 | return $menu_item_db_id; |
489 | 489 | } |
@@ -499,9 +499,9 @@ discard block |
||
499 | 499 | * Default empty array. |
500 | 500 | * @return array Menu objects. |
501 | 501 | */ |
502 | -function wp_get_nav_menus( $args = array() ) { |
|
503 | - $defaults = array( 'hide_empty' => false, 'orderby' => 'name' ); |
|
504 | - $args = wp_parse_args( $args, $defaults ); |
|
502 | +function wp_get_nav_menus($args = array()) { |
|
503 | + $defaults = array('hide_empty' => false, 'orderby' => 'name'); |
|
504 | + $args = wp_parse_args($args, $defaults); |
|
505 | 505 | |
506 | 506 | /** |
507 | 507 | * Filter the navigation menu objects being returned. |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @param array $menus An array of menu objects. |
514 | 514 | * @param array $args An array of arguments used to retrieve menu objects. |
515 | 515 | */ |
516 | - return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu', $args), $args ); |
|
516 | + return apply_filters('wp_get_nav_menus', get_terms('nav_menu', $args), $args); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -528,24 +528,24 @@ discard block |
||
528 | 528 | * @param object $b The second object to compare |
529 | 529 | * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b. |
530 | 530 | */ |
531 | -function _sort_nav_menu_items( $a, $b ) { |
|
531 | +function _sort_nav_menu_items($a, $b) { |
|
532 | 532 | global $_menu_item_sort_prop; |
533 | 533 | |
534 | - if ( empty( $_menu_item_sort_prop ) ) |
|
534 | + if (empty($_menu_item_sort_prop)) |
|
535 | 535 | return 0; |
536 | 536 | |
537 | - if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) |
|
537 | + if ( ! isset($a->$_menu_item_sort_prop) || ! isset($b->$_menu_item_sort_prop)) |
|
538 | 538 | return 0; |
539 | 539 | |
540 | 540 | $_a = (int) $a->$_menu_item_sort_prop; |
541 | 541 | $_b = (int) $b->$_menu_item_sort_prop; |
542 | 542 | |
543 | - if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) |
|
543 | + if ($a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop) |
|
544 | 544 | return 0; |
545 | - elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) |
|
545 | + elseif ($_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop) |
|
546 | 546 | return $_a < $_b ? -1 : 1; |
547 | 547 | else |
548 | - return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); |
|
548 | + return strcmp($a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | * @param object $item The menu item to check. |
560 | 560 | * @return bool False if invalid, otherwise true. |
561 | 561 | */ |
562 | -function _is_valid_nav_menu_item( $item ) { |
|
563 | - return empty( $item->_invalid ); |
|
562 | +function _is_valid_nav_menu_item($item) { |
|
563 | + return empty($item->_invalid); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -575,76 +575,76 @@ discard block |
||
575 | 575 | * @param array $args Optional. Arguments to pass to {@see get_posts()}. |
576 | 576 | * @return false|array $items Array of menu items, otherwise false. |
577 | 577 | */ |
578 | -function wp_get_nav_menu_items( $menu, $args = array() ) { |
|
579 | - $menu = wp_get_nav_menu_object( $menu ); |
|
578 | +function wp_get_nav_menu_items($menu, $args = array()) { |
|
579 | + $menu = wp_get_nav_menu_object($menu); |
|
580 | 580 | |
581 | - if ( ! $menu ) { |
|
581 | + if ( ! $menu) { |
|
582 | 582 | return false; |
583 | 583 | } |
584 | 584 | |
585 | 585 | static $fetched = array(); |
586 | 586 | |
587 | - $items = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
|
588 | - if ( is_wp_error( $items ) ) { |
|
587 | + $items = get_objects_in_term($menu->term_id, 'nav_menu'); |
|
588 | + if (is_wp_error($items)) { |
|
589 | 589 | return false; |
590 | 590 | } |
591 | 591 | |
592 | - $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', |
|
593 | - 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true ); |
|
594 | - $args = wp_parse_args( $args, $defaults ); |
|
592 | + $defaults = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', |
|
593 | + 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true); |
|
594 | + $args = wp_parse_args($args, $defaults); |
|
595 | 595 | $args['include'] = $items; |
596 | 596 | |
597 | - if ( ! empty( $items ) ) { |
|
598 | - $items = get_posts( $args ); |
|
597 | + if ( ! empty($items)) { |
|
598 | + $items = get_posts($args); |
|
599 | 599 | } else { |
600 | 600 | $items = array(); |
601 | 601 | } |
602 | 602 | |
603 | 603 | // Get all posts and terms at once to prime the caches |
604 | - if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) { |
|
604 | + if (empty($fetched[$menu->term_id]) || wp_using_ext_object_cache()) { |
|
605 | 605 | $fetched[$menu->term_id] = true; |
606 | 606 | $posts = array(); |
607 | 607 | $terms = array(); |
608 | - foreach ( $items as $item ) { |
|
609 | - $object_id = get_post_meta( $item->ID, '_menu_item_object_id', true ); |
|
610 | - $object = get_post_meta( $item->ID, '_menu_item_object', true ); |
|
611 | - $type = get_post_meta( $item->ID, '_menu_item_type', true ); |
|
608 | + foreach ($items as $item) { |
|
609 | + $object_id = get_post_meta($item->ID, '_menu_item_object_id', true); |
|
610 | + $object = get_post_meta($item->ID, '_menu_item_object', true); |
|
611 | + $type = get_post_meta($item->ID, '_menu_item_type', true); |
|
612 | 612 | |
613 | - if ( 'post_type' == $type ) |
|
613 | + if ('post_type' == $type) |
|
614 | 614 | $posts[$object][] = $object_id; |
615 | - elseif ( 'taxonomy' == $type) |
|
615 | + elseif ('taxonomy' == $type) |
|
616 | 616 | $terms[$object][] = $object_id; |
617 | 617 | } |
618 | 618 | |
619 | - if ( ! empty( $posts ) ) { |
|
620 | - foreach ( array_keys($posts) as $post_type ) { |
|
621 | - get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) ); |
|
619 | + if ( ! empty($posts)) { |
|
620 | + foreach (array_keys($posts) as $post_type) { |
|
621 | + get_posts(array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false)); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | unset($posts); |
625 | 625 | |
626 | - if ( ! empty( $terms ) ) { |
|
627 | - foreach ( array_keys($terms) as $taxonomy ) { |
|
628 | - get_terms( $taxonomy, array( |
|
629 | - 'include' => $terms[ $taxonomy ], |
|
626 | + if ( ! empty($terms)) { |
|
627 | + foreach (array_keys($terms) as $taxonomy) { |
|
628 | + get_terms($taxonomy, array( |
|
629 | + 'include' => $terms[$taxonomy], |
|
630 | 630 | 'hierarchical' => false, |
631 | - ) ); |
|
631 | + )); |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | unset($terms); |
635 | 635 | } |
636 | 636 | |
637 | - $items = array_map( 'wp_setup_nav_menu_item', $items ); |
|
637 | + $items = array_map('wp_setup_nav_menu_item', $items); |
|
638 | 638 | |
639 | - if ( ! is_admin() ) { // Remove invalid items only in frontend |
|
640 | - $items = array_filter( $items, '_is_valid_nav_menu_item' ); |
|
639 | + if ( ! is_admin()) { // Remove invalid items only in frontend |
|
640 | + $items = array_filter($items, '_is_valid_nav_menu_item'); |
|
641 | 641 | } |
642 | 642 | |
643 | - if ( ARRAY_A == $args['output'] ) { |
|
643 | + if (ARRAY_A == $args['output']) { |
|
644 | 644 | $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; |
645 | 645 | usort($items, '_sort_nav_menu_items'); |
646 | 646 | $i = 1; |
647 | - foreach( $items as $k => $item ) { |
|
647 | + foreach ($items as $k => $item) { |
|
648 | 648 | $items[$k]->{$args['output_key']} = $i++; |
649 | 649 | } |
650 | 650 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | * @param object $menu The menu object. |
659 | 659 | * @param array $args An array of arguments used to retrieve menu item objects. |
660 | 660 | */ |
661 | - return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); |
|
661 | + return apply_filters('wp_get_nav_menu_items', $items, $menu, $args); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | /** |
@@ -688,60 +688,60 @@ discard block |
||
688 | 688 | * @param object $menu_item The menu item to modify. |
689 | 689 | * @return object $menu_item The menu item with standard menu item properties. |
690 | 690 | */ |
691 | -function wp_setup_nav_menu_item( $menu_item ) { |
|
692 | - if ( isset( $menu_item->post_type ) ) { |
|
693 | - if ( 'nav_menu_item' == $menu_item->post_type ) { |
|
691 | +function wp_setup_nav_menu_item($menu_item) { |
|
692 | + if (isset($menu_item->post_type)) { |
|
693 | + if ('nav_menu_item' == $menu_item->post_type) { |
|
694 | 694 | $menu_item->db_id = (int) $menu_item->ID; |
695 | - $menu_item->menu_item_parent = ! isset( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent; |
|
696 | - $menu_item->object_id = ! isset( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id; |
|
697 | - $menu_item->object = ! isset( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object; |
|
698 | - $menu_item->type = ! isset( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; |
|
699 | - |
|
700 | - if ( 'post_type' == $menu_item->type ) { |
|
701 | - $object = get_post_type_object( $menu_item->object ); |
|
702 | - if ( $object ) { |
|
695 | + $menu_item->menu_item_parent = ! isset($menu_item->menu_item_parent) ? get_post_meta($menu_item->ID, '_menu_item_menu_item_parent', true) : $menu_item->menu_item_parent; |
|
696 | + $menu_item->object_id = ! isset($menu_item->object_id) ? get_post_meta($menu_item->ID, '_menu_item_object_id', true) : $menu_item->object_id; |
|
697 | + $menu_item->object = ! isset($menu_item->object) ? get_post_meta($menu_item->ID, '_menu_item_object', true) : $menu_item->object; |
|
698 | + $menu_item->type = ! isset($menu_item->type) ? get_post_meta($menu_item->ID, '_menu_item_type', true) : $menu_item->type; |
|
699 | + |
|
700 | + if ('post_type' == $menu_item->type) { |
|
701 | + $object = get_post_type_object($menu_item->object); |
|
702 | + if ($object) { |
|
703 | 703 | $menu_item->type_label = $object->labels->singular_name; |
704 | 704 | } else { |
705 | 705 | $menu_item->type_label = $menu_item->object; |
706 | 706 | $menu_item->_invalid = true; |
707 | 707 | } |
708 | 708 | |
709 | - $menu_item->url = get_permalink( $menu_item->object_id ); |
|
709 | + $menu_item->url = get_permalink($menu_item->object_id); |
|
710 | 710 | |
711 | - $original_object = get_post( $menu_item->object_id ); |
|
711 | + $original_object = get_post($menu_item->object_id); |
|
712 | 712 | $original_title = $original_object->post_title; |
713 | 713 | |
714 | - if ( '' === $original_title ) { |
|
714 | + if ('' === $original_title) { |
|
715 | 715 | /* translators: %d: ID of a post */ |
716 | - $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); |
|
716 | + $original_title = sprintf(__('#%d (no title)'), $original_object->ID); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
720 | 720 | |
721 | - } elseif ( 'taxonomy' == $menu_item->type ) { |
|
722 | - $object = get_taxonomy( $menu_item->object ); |
|
723 | - if ( $object ) { |
|
721 | + } elseif ('taxonomy' == $menu_item->type) { |
|
722 | + $object = get_taxonomy($menu_item->object); |
|
723 | + if ($object) { |
|
724 | 724 | $menu_item->type_label = $object->labels->singular_name; |
725 | 725 | } else { |
726 | 726 | $menu_item->type_label = $menu_item->object; |
727 | 727 | $menu_item->_invalid = true; |
728 | 728 | } |
729 | 729 | |
730 | - $term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); |
|
731 | - $menu_item->url = !is_wp_error( $term_url ) ? $term_url : ''; |
|
730 | + $term_url = get_term_link((int) $menu_item->object_id, $menu_item->object); |
|
731 | + $menu_item->url = ! is_wp_error($term_url) ? $term_url : ''; |
|
732 | 732 | |
733 | - $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); |
|
734 | - if ( is_wp_error( $original_title ) ) |
|
733 | + $original_title = get_term_field('name', $menu_item->object_id, $menu_item->object, 'raw'); |
|
734 | + if (is_wp_error($original_title)) |
|
735 | 735 | $original_title = false; |
736 | 736 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
737 | 737 | |
738 | 738 | } else { |
739 | 739 | $menu_item->type_label = __('Custom Link'); |
740 | 740 | $menu_item->title = $menu_item->post_title; |
741 | - $menu_item->url = ! isset( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url; |
|
741 | + $menu_item->url = ! isset($menu_item->url) ? get_post_meta($menu_item->ID, '_menu_item_url', true) : $menu_item->url; |
|
742 | 742 | } |
743 | 743 | |
744 | - $menu_item->target = ! isset( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target; |
|
744 | + $menu_item->target = ! isset($menu_item->target) ? get_post_meta($menu_item->ID, '_menu_item_target', true) : $menu_item->target; |
|
745 | 745 | |
746 | 746 | /** |
747 | 747 | * Filter a navigation menu item's title attribute. |
@@ -750,9 +750,9 @@ discard block |
||
750 | 750 | * |
751 | 751 | * @param string $item_title The menu item title attribute. |
752 | 752 | */ |
753 | - $menu_item->attr_title = ! isset( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title; |
|
753 | + $menu_item->attr_title = ! isset($menu_item->attr_title) ? apply_filters('nav_menu_attr_title', $menu_item->post_excerpt) : $menu_item->attr_title; |
|
754 | 754 | |
755 | - if ( ! isset( $menu_item->description ) ) { |
|
755 | + if ( ! isset($menu_item->description)) { |
|
756 | 756 | /** |
757 | 757 | * Filter a navigation menu item's description. |
758 | 758 | * |
@@ -760,39 +760,39 @@ discard block |
||
760 | 760 | * |
761 | 761 | * @param string $description The menu item description. |
762 | 762 | */ |
763 | - $menu_item->description = apply_filters( 'nav_menu_description', wp_trim_words( $menu_item->post_content, 200 ) ); |
|
763 | + $menu_item->description = apply_filters('nav_menu_description', wp_trim_words($menu_item->post_content, 200)); |
|
764 | 764 | } |
765 | 765 | |
766 | - $menu_item->classes = ! isset( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes; |
|
767 | - $menu_item->xfn = ! isset( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn; |
|
766 | + $menu_item->classes = ! isset($menu_item->classes) ? (array) get_post_meta($menu_item->ID, '_menu_item_classes', true) : $menu_item->classes; |
|
767 | + $menu_item->xfn = ! isset($menu_item->xfn) ? get_post_meta($menu_item->ID, '_menu_item_xfn', true) : $menu_item->xfn; |
|
768 | 768 | } else { |
769 | 769 | $menu_item->db_id = 0; |
770 | 770 | $menu_item->menu_item_parent = 0; |
771 | 771 | $menu_item->object_id = (int) $menu_item->ID; |
772 | 772 | $menu_item->type = 'post_type'; |
773 | 773 | |
774 | - $object = get_post_type_object( $menu_item->post_type ); |
|
774 | + $object = get_post_type_object($menu_item->post_type); |
|
775 | 775 | $menu_item->object = $object->name; |
776 | 776 | $menu_item->type_label = $object->labels->singular_name; |
777 | 777 | |
778 | - if ( '' === $menu_item->post_title ) { |
|
778 | + if ('' === $menu_item->post_title) { |
|
779 | 779 | /* translators: %d: ID of a post */ |
780 | - $menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID ); |
|
780 | + $menu_item->post_title = sprintf(__('#%d (no title)'), $menu_item->ID); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | $menu_item->title = $menu_item->post_title; |
784 | - $menu_item->url = get_permalink( $menu_item->ID ); |
|
784 | + $menu_item->url = get_permalink($menu_item->ID); |
|
785 | 785 | $menu_item->target = ''; |
786 | 786 | |
787 | 787 | /** This filter is documented in wp-includes/nav-menu.php */ |
788 | - $menu_item->attr_title = apply_filters( 'nav_menu_attr_title', '' ); |
|
788 | + $menu_item->attr_title = apply_filters('nav_menu_attr_title', ''); |
|
789 | 789 | |
790 | 790 | /** This filter is documented in wp-includes/nav-menu.php */ |
791 | - $menu_item->description = apply_filters( 'nav_menu_description', '' ); |
|
791 | + $menu_item->description = apply_filters('nav_menu_description', ''); |
|
792 | 792 | $menu_item->classes = array(); |
793 | 793 | $menu_item->xfn = ''; |
794 | 794 | } |
795 | - } elseif ( isset( $menu_item->taxonomy ) ) { |
|
795 | + } elseif (isset($menu_item->taxonomy)) { |
|
796 | 796 | $menu_item->ID = $menu_item->term_id; |
797 | 797 | $menu_item->db_id = 0; |
798 | 798 | $menu_item->menu_item_parent = 0; |
@@ -800,15 +800,15 @@ discard block |
||
800 | 800 | $menu_item->post_parent = (int) $menu_item->parent; |
801 | 801 | $menu_item->type = 'taxonomy'; |
802 | 802 | |
803 | - $object = get_taxonomy( $menu_item->taxonomy ); |
|
803 | + $object = get_taxonomy($menu_item->taxonomy); |
|
804 | 804 | $menu_item->object = $object->name; |
805 | 805 | $menu_item->type_label = $object->labels->singular_name; |
806 | 806 | |
807 | 807 | $menu_item->title = $menu_item->name; |
808 | - $menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy ); |
|
808 | + $menu_item->url = get_term_link($menu_item, $menu_item->taxonomy); |
|
809 | 809 | $menu_item->target = ''; |
810 | 810 | $menu_item->attr_title = ''; |
811 | - $menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy ); |
|
811 | + $menu_item->description = get_term_field('description', $menu_item->term_id, $menu_item->taxonomy); |
|
812 | 812 | $menu_item->classes = array(); |
813 | 813 | $menu_item->xfn = ''; |
814 | 814 | |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * |
822 | 822 | * @param object $menu_item The menu item object. |
823 | 823 | */ |
824 | - return apply_filters( 'wp_setup_nav_menu_item', $menu_item ); |
|
824 | + return apply_filters('wp_setup_nav_menu_item', $menu_item); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | * @param string $taxonomy If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to |
835 | 835 | * @return array The array of menu item IDs; empty array if none; |
836 | 836 | */ |
837 | -function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) { |
|
837 | +function wp_get_associated_nav_menu_items($object_id = 0, $object_type = 'post_type', $taxonomy = '') { |
|
838 | 838 | $object_id = (int) $object_id; |
839 | 839 | $menu_item_ids = array(); |
840 | 840 | |
@@ -848,9 +848,9 @@ discard block |
||
848 | 848 | 'posts_per_page' => -1, |
849 | 849 | ) |
850 | 850 | ); |
851 | - foreach( (array) $menu_items as $menu_item ) { |
|
852 | - if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { |
|
853 | - $menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); |
|
851 | + foreach ((array) $menu_items as $menu_item) { |
|
852 | + if (isset($menu_item->ID) && is_nav_menu_item($menu_item->ID)) { |
|
853 | + $menu_item_type = get_post_meta($menu_item->ID, '_menu_item_type', true); |
|
854 | 854 | if ( |
855 | 855 | 'post_type' == $object_type && |
856 | 856 | 'post_type' == $menu_item_type |
@@ -859,14 +859,14 @@ discard block |
||
859 | 859 | } elseif ( |
860 | 860 | 'taxonomy' == $object_type && |
861 | 861 | 'taxonomy' == $menu_item_type && |
862 | - get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy |
|
862 | + get_post_meta($menu_item->ID, '_menu_item_object', true) == $taxonomy |
|
863 | 863 | ) { |
864 | 864 | $menu_item_ids[] = (int) $menu_item->ID; |
865 | 865 | } |
866 | 866 | } |
867 | 867 | } |
868 | 868 | |
869 | - return array_unique( $menu_item_ids ); |
|
869 | + return array_unique($menu_item_ids); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
@@ -878,13 +878,13 @@ discard block |
||
878 | 878 | * @param int $object_id The ID of the original object being trashed. |
879 | 879 | * |
880 | 880 | */ |
881 | -function _wp_delete_post_menu_item( $object_id = 0 ) { |
|
881 | +function _wp_delete_post_menu_item($object_id = 0) { |
|
882 | 882 | $object_id = (int) $object_id; |
883 | 883 | |
884 | - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' ); |
|
884 | + $menu_item_ids = wp_get_associated_nav_menu_items($object_id, 'post_type'); |
|
885 | 885 | |
886 | - foreach( (array) $menu_item_ids as $menu_item_id ) { |
|
887 | - wp_delete_post( $menu_item_id, true ); |
|
886 | + foreach ((array) $menu_item_ids as $menu_item_id) { |
|
887 | + wp_delete_post($menu_item_id, true); |
|
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
@@ -897,13 +897,13 @@ discard block |
||
897 | 897 | * @param int $object_id The ID of the original object being trashed. |
898 | 898 | * |
899 | 899 | */ |
900 | -function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) { |
|
900 | +function _wp_delete_tax_menu_item($object_id = 0, $tt_id, $taxonomy) { |
|
901 | 901 | $object_id = (int) $object_id; |
902 | 902 | |
903 | - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy ); |
|
903 | + $menu_item_ids = wp_get_associated_nav_menu_items($object_id, 'taxonomy', $taxonomy); |
|
904 | 904 | |
905 | - foreach( (array) $menu_item_ids as $menu_item_id ) { |
|
906 | - wp_delete_post( $menu_item_id, true ); |
|
905 | + foreach ((array) $menu_item_ids as $menu_item_id) { |
|
906 | + wp_delete_post($menu_item_id, true); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 | |
@@ -917,16 +917,16 @@ discard block |
||
917 | 917 | * @param string $old_status The old status of the post object. |
918 | 918 | * @param object $post The post object being transitioned from one status to another. |
919 | 919 | */ |
920 | -function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { |
|
921 | - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) |
|
920 | +function _wp_auto_add_pages_to_menu($new_status, $old_status, $post) { |
|
921 | + if ('publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type) |
|
922 | 922 | return; |
923 | - if ( ! empty( $post->post_parent ) ) |
|
923 | + if ( ! empty($post->post_parent)) |
|
924 | 924 | return; |
925 | - $auto_add = get_option( 'nav_menu_options' ); |
|
926 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) |
|
925 | + $auto_add = get_option('nav_menu_options'); |
|
926 | + if (empty($auto_add) || ! is_array($auto_add) || ! isset($auto_add['auto_add'])) |
|
927 | 927 | return; |
928 | 928 | $auto_add = $auto_add['auto_add']; |
929 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) ) |
|
929 | + if (empty($auto_add) || ! is_array($auto_add)) |
|
930 | 930 | return; |
931 | 931 | |
932 | 932 | $args = array( |
@@ -936,14 +936,14 @@ discard block |
||
936 | 936 | 'menu-item-status' => 'publish', |
937 | 937 | ); |
938 | 938 | |
939 | - foreach ( $auto_add as $menu_id ) { |
|
940 | - $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
|
941 | - if ( ! is_array( $items ) ) |
|
939 | + foreach ($auto_add as $menu_id) { |
|
940 | + $items = wp_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft')); |
|
941 | + if ( ! is_array($items)) |
|
942 | 942 | continue; |
943 | - foreach ( $items as $item ) { |
|
944 | - if ( $post->ID == $item->object_id ) |
|
943 | + foreach ($items as $item) { |
|
944 | + if ($post->ID == $item->object_id) |
|
945 | 945 | continue 2; |
946 | 946 | } |
947 | - wp_update_nav_menu_item( $menu_id, 0, $args ); |
|
947 | + wp_update_nav_menu_item($menu_id, 0, $args); |
|
948 | 948 | } |
949 | 949 | } |
@@ -60,8 +60,9 @@ discard block |
||
60 | 60 | * @return bool Whether the menu exists. |
61 | 61 | */ |
62 | 62 | function is_nav_menu( $menu ) { |
63 | - if ( ! $menu ) |
|
64 | - return false; |
|
63 | + if ( ! $menu ) { |
|
64 | + return false; |
|
65 | + } |
|
65 | 66 | |
66 | 67 | $menu_obj = wp_get_nav_menu_object( $menu ); |
67 | 68 | |
@@ -70,8 +71,9 @@ discard block |
||
70 | 71 | ! is_wp_error( $menu_obj ) && |
71 | 72 | ! empty( $menu_obj->taxonomy ) && |
72 | 73 | 'nav_menu' == $menu_obj->taxonomy |
73 | - ) |
|
74 | - return true; |
|
74 | + ) { |
|
75 | + return true; |
|
76 | + } |
|
75 | 77 | |
76 | 78 | return false; |
77 | 79 | } |
@@ -136,8 +138,9 @@ discard block |
||
136 | 138 | */ |
137 | 139 | function get_registered_nav_menus() { |
138 | 140 | global $_wp_registered_nav_menus; |
139 | - if ( isset( $_wp_registered_nav_menus ) ) |
|
140 | - return $_wp_registered_nav_menus; |
|
141 | + if ( isset( $_wp_registered_nav_menus ) ) { |
|
142 | + return $_wp_registered_nav_menus; |
|
143 | + } |
|
141 | 144 | return array(); |
142 | 145 | } |
143 | 146 | |
@@ -215,8 +218,9 @@ discard block |
||
215 | 218 | */ |
216 | 219 | function wp_delete_nav_menu( $menu ) { |
217 | 220 | $menu = wp_get_nav_menu_object( $menu ); |
218 | - if ( ! $menu ) |
|
219 | - return false; |
|
221 | + if ( ! $menu ) { |
|
222 | + return false; |
|
223 | + } |
|
220 | 224 | |
221 | 225 | $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
222 | 226 | if ( ! empty( $menu_objects ) ) { |
@@ -230,13 +234,14 @@ discard block |
||
230 | 234 | // Remove this menu from any locations. |
231 | 235 | $locations = get_nav_menu_locations(); |
232 | 236 | foreach ( $locations as $location => $menu_id ) { |
233 | - if ( $menu_id == $menu->term_id ) |
|
234 | - $locations[ $location ] = 0; |
|
237 | + if ( $menu_id == $menu->term_id ) { |
|
238 | + $locations[ $location ] = 0; |
|
239 | + } |
|
235 | 240 | } |
236 | 241 | set_theme_mod( 'nav_menu_locations', $locations ); |
237 | 242 | |
238 | - if ( $result && !is_wp_error($result) ) |
|
239 | - |
|
243 | + if ( $result && !is_wp_error($result) ) { |
|
244 | + |
|
240 | 245 | /** |
241 | 246 | * Fires after a navigation menu has been successfully deleted. |
242 | 247 | * |
@@ -245,6 +250,7 @@ discard block |
||
245 | 250 | * @param int $term_id ID of the deleted menu. |
246 | 251 | */ |
247 | 252 | do_action( 'wp_delete_nav_menu', $menu->term_id ); |
253 | + } |
|
248 | 254 | |
249 | 255 | return $result; |
250 | 256 | } |
@@ -277,20 +283,23 @@ discard block |
||
277 | 283 | ! is_wp_error( $_possible_existing ) && |
278 | 284 | isset( $_possible_existing->term_id ) && |
279 | 285 | $_possible_existing->term_id != $menu_id |
280 | - ) |
|
281 | - return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
286 | + ) { |
|
287 | + return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
288 | + } |
|
282 | 289 | |
283 | 290 | // menu doesn't already exist, so create a new menu |
284 | 291 | if ( ! $_menu || is_wp_error( $_menu ) ) { |
285 | 292 | $menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' ); |
286 | 293 | |
287 | - if ( $menu_exists ) |
|
288 | - return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
294 | + if ( $menu_exists ) { |
|
295 | + return new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) ); |
|
296 | + } |
|
289 | 297 | |
290 | 298 | $_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args ); |
291 | 299 | |
292 | - if ( is_wp_error( $_menu ) ) |
|
293 | - return $_menu; |
|
300 | + if ( is_wp_error( $_menu ) ) { |
|
301 | + return $_menu; |
|
302 | + } |
|
294 | 303 | |
295 | 304 | /** |
296 | 305 | * Fires after a navigation menu is successfully created. |
@@ -305,15 +314,17 @@ discard block |
||
305 | 314 | return (int) $_menu['term_id']; |
306 | 315 | } |
307 | 316 | |
308 | - if ( ! $_menu || ! isset( $_menu->term_id ) ) |
|
309 | - return 0; |
|
317 | + if ( ! $_menu || ! isset( $_menu->term_id ) ) { |
|
318 | + return 0; |
|
319 | + } |
|
310 | 320 | |
311 | 321 | $menu_id = (int) $_menu->term_id; |
312 | 322 | |
313 | 323 | $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); |
314 | 324 | |
315 | - if ( is_wp_error( $update_response ) ) |
|
316 | - return $update_response; |
|
325 | + if ( is_wp_error( $update_response ) ) { |
|
326 | + return $update_response; |
|
327 | + } |
|
317 | 328 | |
318 | 329 | $menu_id = (int) $update_response['term_id']; |
319 | 330 | |
@@ -344,8 +355,9 @@ discard block |
||
344 | 355 | $menu_item_db_id = (int) $menu_item_db_id; |
345 | 356 | |
346 | 357 | // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects |
347 | - if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) |
|
348 | - return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
358 | + if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) { |
|
359 | + return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
360 | + } |
|
349 | 361 | |
350 | 362 | $menu = wp_get_nav_menu_object( $menu_id ); |
351 | 363 | |
@@ -405,12 +417,14 @@ discard block |
||
405 | 417 | $original_title = $original_object->post_title; |
406 | 418 | } |
407 | 419 | |
408 | - if ( $args['menu-item-title'] == $original_title ) |
|
409 | - $args['menu-item-title'] = ''; |
|
420 | + if ( $args['menu-item-title'] == $original_title ) { |
|
421 | + $args['menu-item-title'] = ''; |
|
422 | + } |
|
410 | 423 | |
411 | 424 | // hack to get wp to create a post object when too many properties are empty |
412 | - if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) |
|
413 | - $args['menu-item-description'] = ' '; |
|
425 | + if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) { |
|
426 | + $args['menu-item-description'] = ' '; |
|
427 | + } |
|
414 | 428 | } |
415 | 429 | |
416 | 430 | // Populate the menu item object |
@@ -431,8 +445,9 @@ discard block |
||
431 | 445 | $post['ID'] = 0; |
432 | 446 | $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; |
433 | 447 | $menu_item_db_id = wp_insert_post( $post ); |
434 | - if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) |
|
435 | - return $menu_item_db_id; |
|
448 | + if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) { |
|
449 | + return $menu_item_db_id; |
|
450 | + } |
|
436 | 451 | } |
437 | 452 | |
438 | 453 | // Associate the menu item with the menu term |
@@ -460,10 +475,11 @@ discard block |
||
460 | 475 | update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); |
461 | 476 | update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); |
462 | 477 | |
463 | - if ( 0 == $menu_id ) |
|
464 | - update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
465 | - elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) |
|
466 | - delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
478 | + if ( 0 == $menu_id ) { |
|
479 | + update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
480 | + } elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) { |
|
481 | + delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
482 | + } |
|
467 | 483 | |
468 | 484 | // Update existing menu item. Default is publish status |
469 | 485 | if ( $update ) { |
@@ -531,22 +547,25 @@ discard block |
||
531 | 547 | function _sort_nav_menu_items( $a, $b ) { |
532 | 548 | global $_menu_item_sort_prop; |
533 | 549 | |
534 | - if ( empty( $_menu_item_sort_prop ) ) |
|
535 | - return 0; |
|
550 | + if ( empty( $_menu_item_sort_prop ) ) { |
|
551 | + return 0; |
|
552 | + } |
|
536 | 553 | |
537 | - if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) |
|
538 | - return 0; |
|
554 | + if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) { |
|
555 | + return 0; |
|
556 | + } |
|
539 | 557 | |
540 | 558 | $_a = (int) $a->$_menu_item_sort_prop; |
541 | 559 | $_b = (int) $b->$_menu_item_sort_prop; |
542 | 560 | |
543 | - if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) |
|
544 | - return 0; |
|
545 | - elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) |
|
546 | - return $_a < $_b ? -1 : 1; |
|
547 | - else |
|
548 | - return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); |
|
549 | -} |
|
561 | + if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) { |
|
562 | + return 0; |
|
563 | + } elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) { |
|
564 | + return $_a < $_b ? -1 : 1; |
|
565 | + } else { |
|
566 | + return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); |
|
567 | + } |
|
568 | + } |
|
550 | 569 | |
551 | 570 | /** |
552 | 571 | * Return if a menu item is valid. |
@@ -610,10 +629,11 @@ discard block |
||
610 | 629 | $object = get_post_meta( $item->ID, '_menu_item_object', true ); |
611 | 630 | $type = get_post_meta( $item->ID, '_menu_item_type', true ); |
612 | 631 | |
613 | - if ( 'post_type' == $type ) |
|
614 | - $posts[$object][] = $object_id; |
|
615 | - elseif ( 'taxonomy' == $type) |
|
616 | - $terms[$object][] = $object_id; |
|
632 | + if ( 'post_type' == $type ) { |
|
633 | + $posts[$object][] = $object_id; |
|
634 | + } elseif ( 'taxonomy' == $type) { |
|
635 | + $terms[$object][] = $object_id; |
|
636 | + } |
|
617 | 637 | } |
618 | 638 | |
619 | 639 | if ( ! empty( $posts ) ) { |
@@ -731,8 +751,9 @@ discard block |
||
731 | 751 | $menu_item->url = !is_wp_error( $term_url ) ? $term_url : ''; |
732 | 752 | |
733 | 753 | $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); |
734 | - if ( is_wp_error( $original_title ) ) |
|
735 | - $original_title = false; |
|
754 | + if ( is_wp_error( $original_title ) ) { |
|
755 | + $original_title = false; |
|
756 | + } |
|
736 | 757 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
737 | 758 | |
738 | 759 | } else { |
@@ -918,16 +939,20 @@ discard block |
||
918 | 939 | * @param object $post The post object being transitioned from one status to another. |
919 | 940 | */ |
920 | 941 | function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { |
921 | - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) |
|
922 | - return; |
|
923 | - if ( ! empty( $post->post_parent ) ) |
|
924 | - return; |
|
942 | + if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) { |
|
943 | + return; |
|
944 | + } |
|
945 | + if ( ! empty( $post->post_parent ) ) { |
|
946 | + return; |
|
947 | + } |
|
925 | 948 | $auto_add = get_option( 'nav_menu_options' ); |
926 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) |
|
927 | - return; |
|
949 | + if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) { |
|
950 | + return; |
|
951 | + } |
|
928 | 952 | $auto_add = $auto_add['auto_add']; |
929 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) ) |
|
930 | - return; |
|
953 | + if ( empty( $auto_add ) || ! is_array( $auto_add ) ) { |
|
954 | + return; |
|
955 | + } |
|
931 | 956 | |
932 | 957 | $args = array( |
933 | 958 | 'menu-item-object-id' => $post->ID, |
@@ -938,11 +963,13 @@ discard block |
||
938 | 963 | |
939 | 964 | foreach ( $auto_add as $menu_id ) { |
940 | 965 | $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
941 | - if ( ! is_array( $items ) ) |
|
942 | - continue; |
|
966 | + if ( ! is_array( $items ) ) { |
|
967 | + continue; |
|
968 | + } |
|
943 | 969 | foreach ( $items as $item ) { |
944 | - if ( $post->ID == $item->object_id ) |
|
945 | - continue 2; |
|
970 | + if ( $post->ID == $item->object_id ) { |
|
971 | + continue 2; |
|
972 | + } |
|
946 | 973 | } |
947 | 974 | wp_update_nav_menu_item( $menu_id, 0, $args ); |
948 | 975 | } |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Defines constants and global variables that can be overridden, generally in wp-config.php. |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - */ |
|
3 | + * Defines constants and global variables that can be overridden, generally in wp-config.php. |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Defines initial WordPress constants |
@@ -16,16 +16,16 @@ discard block |
||
16 | 16 | global $blog_id; |
17 | 17 | |
18 | 18 | // set memory limits |
19 | - if ( !defined('WP_MEMORY_LIMIT') ) { |
|
20 | - if ( is_multisite() ) { |
|
19 | + if ( ! defined('WP_MEMORY_LIMIT')) { |
|
20 | + if (is_multisite()) { |
|
21 | 21 | define('WP_MEMORY_LIMIT', '64M'); |
22 | 22 | } else { |
23 | 23 | define('WP_MEMORY_LIMIT', '40M'); |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | - if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) { |
|
28 | - define( 'WP_MAX_MEMORY_LIMIT', '256M' ); |
|
27 | + if ( ! defined('WP_MAX_MEMORY_LIMIT')) { |
|
28 | + define('WP_MAX_MEMORY_LIMIT', '256M'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -35,73 +35,73 @@ discard block |
||
35 | 35 | * @global int $blog_id |
36 | 36 | * @since 2.0.0 |
37 | 37 | */ |
38 | - if ( ! isset($blog_id) ) |
|
38 | + if ( ! isset($blog_id)) |
|
39 | 39 | $blog_id = 1; |
40 | 40 | |
41 | 41 | // set memory limits. |
42 | - if ( function_exists( 'memory_get_usage' ) ) { |
|
43 | - $current_limit = @ini_get( 'memory_limit' ); |
|
44 | - $current_limit_int = intval( $current_limit ); |
|
45 | - if ( false !== strpos( $current_limit, 'G' ) ) |
|
42 | + if (function_exists('memory_get_usage')) { |
|
43 | + $current_limit = @ini_get('memory_limit'); |
|
44 | + $current_limit_int = intval($current_limit); |
|
45 | + if (false !== strpos($current_limit, 'G')) |
|
46 | 46 | $current_limit_int *= 1024; |
47 | - $wp_limit_int = intval( WP_MEMORY_LIMIT ); |
|
48 | - if ( false !== strpos( WP_MEMORY_LIMIT, 'G' ) ) |
|
47 | + $wp_limit_int = intval(WP_MEMORY_LIMIT); |
|
48 | + if (false !== strpos(WP_MEMORY_LIMIT, 'G')) |
|
49 | 49 | $wp_limit_int *= 1024; |
50 | 50 | |
51 | 51 | if ( -1 != $current_limit && ( -1 == WP_MEMORY_LIMIT || $current_limit_int < $wp_limit_int ) ) |
52 | - @ini_set( 'memory_limit', WP_MEMORY_LIMIT ); |
|
52 | + @ini_set('memory_limit', WP_MEMORY_LIMIT); |
|
53 | 53 | } |
54 | 54 | |
55 | - if ( !defined('WP_CONTENT_DIR') ) |
|
56 | - define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
|
55 | + if ( ! defined('WP_CONTENT_DIR')) |
|
56 | + define('WP_CONTENT_DIR', ABSPATH.'wp-content'); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
|
57 | 57 | |
58 | 58 | // Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development. |
59 | - if ( !defined('WP_DEBUG') ) |
|
60 | - define( 'WP_DEBUG', false ); |
|
59 | + if ( ! defined('WP_DEBUG')) |
|
60 | + define('WP_DEBUG', false); |
|
61 | 61 | |
62 | 62 | // Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for |
63 | 63 | // display_errors and not force errors to be displayed. Use false to force display_errors off. |
64 | - if ( !defined('WP_DEBUG_DISPLAY') ) |
|
65 | - define( 'WP_DEBUG_DISPLAY', true ); |
|
64 | + if ( ! defined('WP_DEBUG_DISPLAY')) |
|
65 | + define('WP_DEBUG_DISPLAY', true); |
|
66 | 66 | |
67 | 67 | // Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log. |
68 | - if ( !defined('WP_DEBUG_LOG') ) |
|
68 | + if ( ! defined('WP_DEBUG_LOG')) |
|
69 | 69 | define('WP_DEBUG_LOG', false); |
70 | 70 | |
71 | - if ( !defined('WP_CACHE') ) |
|
71 | + if ( ! defined('WP_CACHE')) |
|
72 | 72 | define('WP_CACHE', false); |
73 | 73 | |
74 | 74 | // Add define('SCRIPT_DEBUG', true); to wp-config.php to enable loading of non-minified, |
75 | 75 | // non-concatenated scripts and stylesheets. |
76 | - if ( ! defined( 'SCRIPT_DEBUG' ) ) { |
|
77 | - if ( ! empty( $GLOBALS['wp_version'] ) ) { |
|
78 | - $develop_src = false !== strpos( $GLOBALS['wp_version'], '-src' ); |
|
76 | + if ( ! defined('SCRIPT_DEBUG')) { |
|
77 | + if ( ! empty($GLOBALS['wp_version'])) { |
|
78 | + $develop_src = false !== strpos($GLOBALS['wp_version'], '-src'); |
|
79 | 79 | } else { |
80 | 80 | $develop_src = false; |
81 | 81 | } |
82 | 82 | |
83 | - define( 'SCRIPT_DEBUG', $develop_src ); |
|
83 | + define('SCRIPT_DEBUG', $develop_src); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Private |
88 | 88 | */ |
89 | - if ( !defined('MEDIA_TRASH') ) |
|
89 | + if ( ! defined('MEDIA_TRASH')) |
|
90 | 90 | define('MEDIA_TRASH', false); |
91 | 91 | |
92 | - if ( !defined('SHORTINIT') ) |
|
92 | + if ( ! defined('SHORTINIT')) |
|
93 | 93 | define('SHORTINIT', false); |
94 | 94 | |
95 | 95 | // Constants for features added to WP that should short-circuit their plugin implementations |
96 | - define( 'WP_FEATURE_BETTER_PASSWORDS', true ); |
|
96 | + define('WP_FEATURE_BETTER_PASSWORDS', true); |
|
97 | 97 | |
98 | 98 | // Constants for expressing human-readable intervals |
99 | 99 | // in their respective number of seconds. |
100 | - define( 'MINUTE_IN_SECONDS', 60 ); |
|
101 | - define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS ); |
|
102 | - define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS ); |
|
103 | - define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS ); |
|
104 | - define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS ); |
|
100 | + define('MINUTE_IN_SECONDS', 60); |
|
101 | + define('HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS); |
|
102 | + define('DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS); |
|
103 | + define('WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS); |
|
104 | + define('YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,24 +112,24 @@ discard block |
||
112 | 112 | * @since 3.0.0 |
113 | 113 | */ |
114 | 114 | function wp_plugin_directory_constants() { |
115 | - if ( !defined('WP_CONTENT_URL') ) |
|
116 | - define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up |
|
115 | + if ( ! defined('WP_CONTENT_URL')) |
|
116 | + define('WP_CONTENT_URL', get_option('siteurl').'/wp-content'); // full url - WP_CONTENT_DIR is defined further up |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Allows for the plugins directory to be moved from the default location. |
120 | 120 | * |
121 | 121 | * @since 2.6.0 |
122 | 122 | */ |
123 | - if ( !defined('WP_PLUGIN_DIR') ) |
|
124 | - define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash |
|
123 | + if ( ! defined('WP_PLUGIN_DIR')) |
|
124 | + define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins'); // full path, no trailing slash |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * Allows for the plugins directory to be moved from the default location. |
128 | 128 | * |
129 | 129 | * @since 2.6.0 |
130 | 130 | */ |
131 | - if ( !defined('WP_PLUGIN_URL') ) |
|
132 | - define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash |
|
131 | + if ( ! defined('WP_PLUGIN_URL')) |
|
132 | + define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins'); // full url, no trailing slash |
|
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Allows for the plugins directory to be moved from the default location. |
@@ -137,24 +137,24 @@ discard block |
||
137 | 137 | * @since 2.1.0 |
138 | 138 | * @deprecated |
139 | 139 | */ |
140 | - if ( !defined('PLUGINDIR') ) |
|
141 | - define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat. |
|
140 | + if ( ! defined('PLUGINDIR')) |
|
141 | + define('PLUGINDIR', 'wp-content/plugins'); // Relative to ABSPATH. For back compat. |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Allows for the mu-plugins directory to be moved from the default location. |
145 | 145 | * |
146 | 146 | * @since 2.8.0 |
147 | 147 | */ |
148 | - if ( !defined('WPMU_PLUGIN_DIR') ) |
|
149 | - define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash |
|
148 | + if ( ! defined('WPMU_PLUGIN_DIR')) |
|
149 | + define('WPMU_PLUGIN_DIR', WP_CONTENT_DIR.'/mu-plugins'); // full path, no trailing slash |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Allows for the mu-plugins directory to be moved from the default location. |
153 | 153 | * |
154 | 154 | * @since 2.8.0 |
155 | 155 | */ |
156 | - if ( !defined('WPMU_PLUGIN_URL') ) |
|
157 | - define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); // full url, no trailing slash |
|
156 | + if ( ! defined('WPMU_PLUGIN_URL')) |
|
157 | + define('WPMU_PLUGIN_URL', WP_CONTENT_URL.'/mu-plugins'); // full url, no trailing slash |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * Allows for the mu-plugins directory to be moved from the default location. |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @since 2.8.0 |
163 | 163 | * @deprecated |
164 | 164 | */ |
165 | - if ( !defined( 'MUPLUGINDIR' ) ) |
|
166 | - define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat. |
|
165 | + if ( ! defined('MUPLUGINDIR')) |
|
166 | + define('MUPLUGINDIR', 'wp-content/mu-plugins'); // Relative to ABSPATH. For back compat. |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -178,78 +178,78 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @since 1.5.0 |
180 | 180 | */ |
181 | - if ( !defined( 'COOKIEHASH' ) ) { |
|
182 | - $siteurl = get_site_option( 'siteurl' ); |
|
183 | - if ( $siteurl ) |
|
184 | - define( 'COOKIEHASH', md5( $siteurl ) ); |
|
181 | + if ( ! defined('COOKIEHASH')) { |
|
182 | + $siteurl = get_site_option('siteurl'); |
|
183 | + if ($siteurl) |
|
184 | + define('COOKIEHASH', md5($siteurl)); |
|
185 | 185 | else |
186 | - define( 'COOKIEHASH', '' ); |
|
186 | + define('COOKIEHASH', ''); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | 190 | * @since 2.0.0 |
191 | 191 | */ |
192 | - if ( !defined('USER_COOKIE') ) |
|
193 | - define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH); |
|
192 | + if ( ! defined('USER_COOKIE')) |
|
193 | + define('USER_COOKIE', 'wordpressuser_'.COOKIEHASH); |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * @since 2.0.0 |
197 | 197 | */ |
198 | - if ( !defined('PASS_COOKIE') ) |
|
199 | - define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH); |
|
198 | + if ( ! defined('PASS_COOKIE')) |
|
199 | + define('PASS_COOKIE', 'wordpresspass_'.COOKIEHASH); |
|
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @since 2.5.0 |
203 | 203 | */ |
204 | - if ( !defined('AUTH_COOKIE') ) |
|
205 | - define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH); |
|
204 | + if ( ! defined('AUTH_COOKIE')) |
|
205 | + define('AUTH_COOKIE', 'wordpress_'.COOKIEHASH); |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * @since 2.6.0 |
209 | 209 | */ |
210 | - if ( !defined('SECURE_AUTH_COOKIE') ) |
|
211 | - define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH); |
|
210 | + if ( ! defined('SECURE_AUTH_COOKIE')) |
|
211 | + define('SECURE_AUTH_COOKIE', 'wordpress_sec_'.COOKIEHASH); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * @since 2.6.0 |
215 | 215 | */ |
216 | - if ( !defined('LOGGED_IN_COOKIE') ) |
|
217 | - define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH); |
|
216 | + if ( ! defined('LOGGED_IN_COOKIE')) |
|
217 | + define('LOGGED_IN_COOKIE', 'wordpress_logged_in_'.COOKIEHASH); |
|
218 | 218 | |
219 | 219 | /** |
220 | 220 | * @since 2.3.0 |
221 | 221 | */ |
222 | - if ( !defined('TEST_COOKIE') ) |
|
222 | + if ( ! defined('TEST_COOKIE')) |
|
223 | 223 | define('TEST_COOKIE', 'wordpress_test_cookie'); |
224 | 224 | |
225 | 225 | /** |
226 | 226 | * @since 1.2.0 |
227 | 227 | */ |
228 | - if ( !defined('COOKIEPATH') ) |
|
229 | - define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) ); |
|
228 | + if ( ! defined('COOKIEPATH')) |
|
229 | + define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home').'/')); |
|
230 | 230 | |
231 | 231 | /** |
232 | 232 | * @since 1.5.0 |
233 | 233 | */ |
234 | - if ( !defined('SITECOOKIEPATH') ) |
|
235 | - define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); |
|
234 | + if ( ! defined('SITECOOKIEPATH')) |
|
235 | + define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl').'/')); |
|
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @since 2.6.0 |
239 | 239 | */ |
240 | - if ( !defined('ADMIN_COOKIE_PATH') ) |
|
241 | - define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); |
|
240 | + if ( ! defined('ADMIN_COOKIE_PATH')) |
|
241 | + define('ADMIN_COOKIE_PATH', SITECOOKIEPATH.'wp-admin'); |
|
242 | 242 | |
243 | 243 | /** |
244 | 244 | * @since 2.6.0 |
245 | 245 | */ |
246 | - if ( !defined('PLUGINS_COOKIE_PATH') ) |
|
247 | - define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) ); |
|
246 | + if ( ! defined('PLUGINS_COOKIE_PATH')) |
|
247 | + define('PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)); |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * @since 2.0.0 |
251 | 251 | */ |
252 | - if ( !defined('COOKIE_DOMAIN') ) |
|
252 | + if ( ! defined('COOKIE_DOMAIN')) |
|
253 | 253 | define('COOKIE_DOMAIN', false); |
254 | 254 | } |
255 | 255 | |
@@ -262,21 +262,21 @@ discard block |
||
262 | 262 | /** |
263 | 263 | * @since 2.6.0 |
264 | 264 | */ |
265 | - if ( !defined( 'FORCE_SSL_ADMIN' ) ) { |
|
266 | - if ( 'https' === parse_url( get_option( 'siteurl' ), PHP_URL_SCHEME ) ) { |
|
267 | - define( 'FORCE_SSL_ADMIN', true ); |
|
265 | + if ( ! defined('FORCE_SSL_ADMIN')) { |
|
266 | + if ('https' === parse_url(get_option('siteurl'), PHP_URL_SCHEME)) { |
|
267 | + define('FORCE_SSL_ADMIN', true); |
|
268 | 268 | } else { |
269 | - define( 'FORCE_SSL_ADMIN', false ); |
|
269 | + define('FORCE_SSL_ADMIN', false); |
|
270 | 270 | } |
271 | 271 | } |
272 | - force_ssl_admin( FORCE_SSL_ADMIN ); |
|
272 | + force_ssl_admin(FORCE_SSL_ADMIN); |
|
273 | 273 | |
274 | 274 | /** |
275 | 275 | * @since 2.6.0 |
276 | 276 | * @deprecated 4.0.0 |
277 | 277 | */ |
278 | - if ( defined( 'FORCE_SSL_LOGIN' ) && FORCE_SSL_LOGIN ) { |
|
279 | - force_ssl_admin( true ); |
|
278 | + if (defined('FORCE_SSL_LOGIN') && FORCE_SSL_LOGIN) { |
|
279 | + force_ssl_admin(true); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -289,23 +289,23 @@ discard block |
||
289 | 289 | /** |
290 | 290 | * @since 2.5.0 |
291 | 291 | */ |
292 | - if ( !defined( 'AUTOSAVE_INTERVAL' ) ) |
|
293 | - define( 'AUTOSAVE_INTERVAL', 60 ); |
|
292 | + if ( ! defined('AUTOSAVE_INTERVAL')) |
|
293 | + define('AUTOSAVE_INTERVAL', 60); |
|
294 | 294 | |
295 | 295 | /** |
296 | 296 | * @since 2.9.0 |
297 | 297 | */ |
298 | - if ( !defined( 'EMPTY_TRASH_DAYS' ) ) |
|
299 | - define( 'EMPTY_TRASH_DAYS', 30 ); |
|
298 | + if ( ! defined('EMPTY_TRASH_DAYS')) |
|
299 | + define('EMPTY_TRASH_DAYS', 30); |
|
300 | 300 | |
301 | - if ( !defined('WP_POST_REVISIONS') ) |
|
301 | + if ( ! defined('WP_POST_REVISIONS')) |
|
302 | 302 | define('WP_POST_REVISIONS', true); |
303 | 303 | |
304 | 304 | /** |
305 | 305 | * @since 3.3.0 |
306 | 306 | */ |
307 | - if ( !defined( 'WP_CRON_LOCK_TIMEOUT' ) ) |
|
308 | - define('WP_CRON_LOCK_TIMEOUT', 60); // In seconds |
|
307 | + if ( ! defined('WP_CRON_LOCK_TIMEOUT')) |
|
308 | + define('WP_CRON_LOCK_TIMEOUT', 60); // In seconds |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * Will be used as the fallback if the current theme doesn't exist. |
333 | 333 | * @since 3.0.0 |
334 | 334 | */ |
335 | - if ( !defined('WP_DEFAULT_THEME') ) |
|
336 | - define( 'WP_DEFAULT_THEME', 'twentyfifteen' ); |
|
335 | + if ( ! defined('WP_DEFAULT_THEME')) |
|
336 | + define('WP_DEFAULT_THEME', 'twentyfifteen'); |
|
337 | 337 | |
338 | 338 | } |
@@ -35,41 +35,51 @@ discard block |
||
35 | 35 | * @global int $blog_id |
36 | 36 | * @since 2.0.0 |
37 | 37 | */ |
38 | - if ( ! isset($blog_id) ) |
|
39 | - $blog_id = 1; |
|
38 | + if ( ! isset($blog_id) ) { |
|
39 | + $blog_id = 1; |
|
40 | + } |
|
40 | 41 | |
41 | 42 | // set memory limits. |
42 | 43 | if ( function_exists( 'memory_get_usage' ) ) { |
43 | 44 | $current_limit = @ini_get( 'memory_limit' ); |
44 | 45 | $current_limit_int = intval( $current_limit ); |
45 | - if ( false !== strpos( $current_limit, 'G' ) ) |
|
46 | - $current_limit_int *= 1024; |
|
46 | + if ( false !== strpos( $current_limit, 'G' ) ) { |
|
47 | + $current_limit_int *= 1024; |
|
48 | + } |
|
47 | 49 | $wp_limit_int = intval( WP_MEMORY_LIMIT ); |
48 | - if ( false !== strpos( WP_MEMORY_LIMIT, 'G' ) ) |
|
49 | - $wp_limit_int *= 1024; |
|
50 | + if ( false !== strpos( WP_MEMORY_LIMIT, 'G' ) ) { |
|
51 | + $wp_limit_int *= 1024; |
|
52 | + } |
|
50 | 53 | |
51 | - if ( -1 != $current_limit && ( -1 == WP_MEMORY_LIMIT || $current_limit_int < $wp_limit_int ) ) |
|
52 | - @ini_set( 'memory_limit', WP_MEMORY_LIMIT ); |
|
54 | + if ( -1 != $current_limit && ( -1 == WP_MEMORY_LIMIT || $current_limit_int < $wp_limit_int ) ) { |
|
55 | + @ini_set( 'memory_limit', WP_MEMORY_LIMIT ); |
|
56 | + } |
|
53 | 57 | } |
54 | 58 | |
55 | - if ( !defined('WP_CONTENT_DIR') ) |
|
56 | - define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
|
59 | + if ( !defined('WP_CONTENT_DIR') ) { |
|
60 | + define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); |
|
61 | + } |
|
62 | + // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
|
57 | 63 | |
58 | 64 | // Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development. |
59 | - if ( !defined('WP_DEBUG') ) |
|
60 | - define( 'WP_DEBUG', false ); |
|
65 | + if ( !defined('WP_DEBUG') ) { |
|
66 | + define( 'WP_DEBUG', false ); |
|
67 | + } |
|
61 | 68 | |
62 | 69 | // Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for |
63 | 70 | // display_errors and not force errors to be displayed. Use false to force display_errors off. |
64 | - if ( !defined('WP_DEBUG_DISPLAY') ) |
|
65 | - define( 'WP_DEBUG_DISPLAY', true ); |
|
71 | + if ( !defined('WP_DEBUG_DISPLAY') ) { |
|
72 | + define( 'WP_DEBUG_DISPLAY', true ); |
|
73 | + } |
|
66 | 74 | |
67 | 75 | // Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log. |
68 | - if ( !defined('WP_DEBUG_LOG') ) |
|
69 | - define('WP_DEBUG_LOG', false); |
|
76 | + if ( !defined('WP_DEBUG_LOG') ) { |
|
77 | + define('WP_DEBUG_LOG', false); |
|
78 | + } |
|
70 | 79 | |
71 | - if ( !defined('WP_CACHE') ) |
|
72 | - define('WP_CACHE', false); |
|
80 | + if ( !defined('WP_CACHE') ) { |
|
81 | + define('WP_CACHE', false); |
|
82 | + } |
|
73 | 83 | |
74 | 84 | // Add define('SCRIPT_DEBUG', true); to wp-config.php to enable loading of non-minified, |
75 | 85 | // non-concatenated scripts and stylesheets. |
@@ -86,11 +96,13 @@ discard block |
||
86 | 96 | /** |
87 | 97 | * Private |
88 | 98 | */ |
89 | - if ( !defined('MEDIA_TRASH') ) |
|
90 | - define('MEDIA_TRASH', false); |
|
99 | + if ( !defined('MEDIA_TRASH') ) { |
|
100 | + define('MEDIA_TRASH', false); |
|
101 | + } |
|
91 | 102 | |
92 | - if ( !defined('SHORTINIT') ) |
|
93 | - define('SHORTINIT', false); |
|
103 | + if ( !defined('SHORTINIT') ) { |
|
104 | + define('SHORTINIT', false); |
|
105 | + } |
|
94 | 106 | |
95 | 107 | // Constants for features added to WP that should short-circuit their plugin implementations |
96 | 108 | define( 'WP_FEATURE_BETTER_PASSWORDS', true ); |
@@ -112,24 +124,30 @@ discard block |
||
112 | 124 | * @since 3.0.0 |
113 | 125 | */ |
114 | 126 | function wp_plugin_directory_constants() { |
115 | - if ( !defined('WP_CONTENT_URL') ) |
|
116 | - define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up |
|
127 | + if ( !defined('WP_CONTENT_URL') ) { |
|
128 | + define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); |
|
129 | + } |
|
130 | + // full url - WP_CONTENT_DIR is defined further up |
|
117 | 131 | |
118 | 132 | /** |
119 | 133 | * Allows for the plugins directory to be moved from the default location. |
120 | 134 | * |
121 | 135 | * @since 2.6.0 |
122 | 136 | */ |
123 | - if ( !defined('WP_PLUGIN_DIR') ) |
|
124 | - define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash |
|
137 | + if ( !defined('WP_PLUGIN_DIR') ) { |
|
138 | + define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); |
|
139 | + } |
|
140 | + // full path, no trailing slash |
|
125 | 141 | |
126 | 142 | /** |
127 | 143 | * Allows for the plugins directory to be moved from the default location. |
128 | 144 | * |
129 | 145 | * @since 2.6.0 |
130 | 146 | */ |
131 | - if ( !defined('WP_PLUGIN_URL') ) |
|
132 | - define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash |
|
147 | + if ( !defined('WP_PLUGIN_URL') ) { |
|
148 | + define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); |
|
149 | + } |
|
150 | + // full url, no trailing slash |
|
133 | 151 | |
134 | 152 | /** |
135 | 153 | * Allows for the plugins directory to be moved from the default location. |
@@ -137,24 +155,30 @@ discard block |
||
137 | 155 | * @since 2.1.0 |
138 | 156 | * @deprecated |
139 | 157 | */ |
140 | - if ( !defined('PLUGINDIR') ) |
|
141 | - define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat. |
|
158 | + if ( !defined('PLUGINDIR') ) { |
|
159 | + define( 'PLUGINDIR', 'wp-content/plugins' ); |
|
160 | + } |
|
161 | + // Relative to ABSPATH. For back compat. |
|
142 | 162 | |
143 | 163 | /** |
144 | 164 | * Allows for the mu-plugins directory to be moved from the default location. |
145 | 165 | * |
146 | 166 | * @since 2.8.0 |
147 | 167 | */ |
148 | - if ( !defined('WPMU_PLUGIN_DIR') ) |
|
149 | - define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash |
|
168 | + if ( !defined('WPMU_PLUGIN_DIR') ) { |
|
169 | + define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); |
|
170 | + } |
|
171 | + // full path, no trailing slash |
|
150 | 172 | |
151 | 173 | /** |
152 | 174 | * Allows for the mu-plugins directory to be moved from the default location. |
153 | 175 | * |
154 | 176 | * @since 2.8.0 |
155 | 177 | */ |
156 | - if ( !defined('WPMU_PLUGIN_URL') ) |
|
157 | - define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); // full url, no trailing slash |
|
178 | + if ( !defined('WPMU_PLUGIN_URL') ) { |
|
179 | + define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); |
|
180 | + } |
|
181 | + // full url, no trailing slash |
|
158 | 182 | |
159 | 183 | /** |
160 | 184 | * Allows for the mu-plugins directory to be moved from the default location. |
@@ -162,8 +186,10 @@ discard block |
||
162 | 186 | * @since 2.8.0 |
163 | 187 | * @deprecated |
164 | 188 | */ |
165 | - if ( !defined( 'MUPLUGINDIR' ) ) |
|
166 | - define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat. |
|
189 | + if ( !defined( 'MUPLUGINDIR' ) ) { |
|
190 | + define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); |
|
191 | + } |
|
192 | + // Relative to ABSPATH. For back compat. |
|
167 | 193 | } |
168 | 194 | |
169 | 195 | /** |
@@ -180,78 +206,90 @@ discard block |
||
180 | 206 | */ |
181 | 207 | if ( !defined( 'COOKIEHASH' ) ) { |
182 | 208 | $siteurl = get_site_option( 'siteurl' ); |
183 | - if ( $siteurl ) |
|
184 | - define( 'COOKIEHASH', md5( $siteurl ) ); |
|
185 | - else |
|
186 | - define( 'COOKIEHASH', '' ); |
|
209 | + if ( $siteurl ) { |
|
210 | + define( 'COOKIEHASH', md5( $siteurl ) ); |
|
211 | + } else { |
|
212 | + define( 'COOKIEHASH', '' ); |
|
213 | + } |
|
187 | 214 | } |
188 | 215 | |
189 | 216 | /** |
190 | 217 | * @since 2.0.0 |
191 | 218 | */ |
192 | - if ( !defined('USER_COOKIE') ) |
|
193 | - define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH); |
|
219 | + if ( !defined('USER_COOKIE') ) { |
|
220 | + define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH); |
|
221 | + } |
|
194 | 222 | |
195 | 223 | /** |
196 | 224 | * @since 2.0.0 |
197 | 225 | */ |
198 | - if ( !defined('PASS_COOKIE') ) |
|
199 | - define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH); |
|
226 | + if ( !defined('PASS_COOKIE') ) { |
|
227 | + define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH); |
|
228 | + } |
|
200 | 229 | |
201 | 230 | /** |
202 | 231 | * @since 2.5.0 |
203 | 232 | */ |
204 | - if ( !defined('AUTH_COOKIE') ) |
|
205 | - define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH); |
|
233 | + if ( !defined('AUTH_COOKIE') ) { |
|
234 | + define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH); |
|
235 | + } |
|
206 | 236 | |
207 | 237 | /** |
208 | 238 | * @since 2.6.0 |
209 | 239 | */ |
210 | - if ( !defined('SECURE_AUTH_COOKIE') ) |
|
211 | - define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH); |
|
240 | + if ( !defined('SECURE_AUTH_COOKIE') ) { |
|
241 | + define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH); |
|
242 | + } |
|
212 | 243 | |
213 | 244 | /** |
214 | 245 | * @since 2.6.0 |
215 | 246 | */ |
216 | - if ( !defined('LOGGED_IN_COOKIE') ) |
|
217 | - define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH); |
|
247 | + if ( !defined('LOGGED_IN_COOKIE') ) { |
|
248 | + define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH); |
|
249 | + } |
|
218 | 250 | |
219 | 251 | /** |
220 | 252 | * @since 2.3.0 |
221 | 253 | */ |
222 | - if ( !defined('TEST_COOKIE') ) |
|
223 | - define('TEST_COOKIE', 'wordpress_test_cookie'); |
|
254 | + if ( !defined('TEST_COOKIE') ) { |
|
255 | + define('TEST_COOKIE', 'wordpress_test_cookie'); |
|
256 | + } |
|
224 | 257 | |
225 | 258 | /** |
226 | 259 | * @since 1.2.0 |
227 | 260 | */ |
228 | - if ( !defined('COOKIEPATH') ) |
|
229 | - define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) ); |
|
261 | + if ( !defined('COOKIEPATH') ) { |
|
262 | + define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) ); |
|
263 | + } |
|
230 | 264 | |
231 | 265 | /** |
232 | 266 | * @since 1.5.0 |
233 | 267 | */ |
234 | - if ( !defined('SITECOOKIEPATH') ) |
|
235 | - define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); |
|
268 | + if ( !defined('SITECOOKIEPATH') ) { |
|
269 | + define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); |
|
270 | + } |
|
236 | 271 | |
237 | 272 | /** |
238 | 273 | * @since 2.6.0 |
239 | 274 | */ |
240 | - if ( !defined('ADMIN_COOKIE_PATH') ) |
|
241 | - define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); |
|
275 | + if ( !defined('ADMIN_COOKIE_PATH') ) { |
|
276 | + define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); |
|
277 | + } |
|
242 | 278 | |
243 | 279 | /** |
244 | 280 | * @since 2.6.0 |
245 | 281 | */ |
246 | - if ( !defined('PLUGINS_COOKIE_PATH') ) |
|
247 | - define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) ); |
|
282 | + if ( !defined('PLUGINS_COOKIE_PATH') ) { |
|
283 | + define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) ); |
|
284 | + } |
|
248 | 285 | |
249 | 286 | /** |
250 | 287 | * @since 2.0.0 |
251 | 288 | */ |
252 | - if ( !defined('COOKIE_DOMAIN') ) |
|
253 | - define('COOKIE_DOMAIN', false); |
|
254 | -} |
|
289 | + if ( !defined('COOKIE_DOMAIN') ) { |
|
290 | + define('COOKIE_DOMAIN', false); |
|
291 | + } |
|
292 | + } |
|
255 | 293 | |
256 | 294 | /** |
257 | 295 | * Defines cookie related WordPress constants |
@@ -289,23 +327,28 @@ discard block |
||
289 | 327 | /** |
290 | 328 | * @since 2.5.0 |
291 | 329 | */ |
292 | - if ( !defined( 'AUTOSAVE_INTERVAL' ) ) |
|
293 | - define( 'AUTOSAVE_INTERVAL', 60 ); |
|
330 | + if ( !defined( 'AUTOSAVE_INTERVAL' ) ) { |
|
331 | + define( 'AUTOSAVE_INTERVAL', 60 ); |
|
332 | + } |
|
294 | 333 | |
295 | 334 | /** |
296 | 335 | * @since 2.9.0 |
297 | 336 | */ |
298 | - if ( !defined( 'EMPTY_TRASH_DAYS' ) ) |
|
299 | - define( 'EMPTY_TRASH_DAYS', 30 ); |
|
337 | + if ( !defined( 'EMPTY_TRASH_DAYS' ) ) { |
|
338 | + define( 'EMPTY_TRASH_DAYS', 30 ); |
|
339 | + } |
|
300 | 340 | |
301 | - if ( !defined('WP_POST_REVISIONS') ) |
|
302 | - define('WP_POST_REVISIONS', true); |
|
341 | + if ( !defined('WP_POST_REVISIONS') ) { |
|
342 | + define('WP_POST_REVISIONS', true); |
|
343 | + } |
|
303 | 344 | |
304 | 345 | /** |
305 | 346 | * @since 3.3.0 |
306 | 347 | */ |
307 | - if ( !defined( 'WP_CRON_LOCK_TIMEOUT' ) ) |
|
308 | - define('WP_CRON_LOCK_TIMEOUT', 60); // In seconds |
|
348 | + if ( !defined( 'WP_CRON_LOCK_TIMEOUT' ) ) { |
|
349 | + define('WP_CRON_LOCK_TIMEOUT', 60); |
|
350 | + } |
|
351 | + // In seconds |
|
309 | 352 | } |
310 | 353 | |
311 | 354 | /** |
@@ -332,7 +375,8 @@ discard block |
||
332 | 375 | * Will be used as the fallback if the current theme doesn't exist. |
333 | 376 | * @since 3.0.0 |
334 | 377 | */ |
335 | - if ( !defined('WP_DEFAULT_THEME') ) |
|
336 | - define( 'WP_DEFAULT_THEME', 'twentyfifteen' ); |
|
378 | + if ( !defined('WP_DEFAULT_THEME') ) { |
|
379 | + define( 'WP_DEFAULT_THEME', 'twentyfifteen' ); |
|
380 | + } |
|
337 | 381 | |
338 | 382 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * BackPress Scripts Procedural API |
|
4 | - * |
|
5 | - * @since 2.6.0 |
|
6 | - * |
|
7 | - * @package WordPress |
|
8 | - * @subpackage BackPress |
|
9 | - */ |
|
3 | + * BackPress Scripts Procedural API |
|
4 | + * |
|
5 | + * @since 2.6.0 |
|
6 | + * |
|
7 | + * @package WordPress |
|
8 | + * @subpackage BackPress |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Initialize $wp_scripts if it has not been set. |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function wp_scripts() { |
21 | 21 | global $wp_scripts; |
22 | - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
22 | + if ( ! ($wp_scripts instanceof WP_Scripts)) { |
|
23 | 23 | $wp_scripts = new WP_Scripts(); |
24 | 24 | } |
25 | 25 | return $wp_scripts; |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param string $function Function name. |
35 | 35 | */ |
36 | -function _wp_scripts_maybe_doing_it_wrong( $function ) { |
|
37 | - if ( did_action( 'init' ) ) { |
|
36 | +function _wp_scripts_maybe_doing_it_wrong($function) { |
|
37 | + if (did_action('init')) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - _doing_it_wrong( $function, sprintf( |
|
42 | - __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
41 | + _doing_it_wrong($function, sprintf( |
|
42 | + __('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), |
|
43 | 43 | '<code>wp_enqueue_scripts</code>', |
44 | 44 | '<code>admin_enqueue_scripts</code>', |
45 | 45 | '<code>login_enqueue_scripts</code>' |
46 | - ), '3.3' ); |
|
46 | + ), '3.3'); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -62,27 +62,27 @@ discard block |
||
62 | 62 | * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'. |
63 | 63 | * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. |
64 | 64 | */ |
65 | -function wp_print_scripts( $handles = false ) { |
|
65 | +function wp_print_scripts($handles = false) { |
|
66 | 66 | /** |
67 | 67 | * Fires before scripts in the $handles queue are printed. |
68 | 68 | * |
69 | 69 | * @since 2.1.0 |
70 | 70 | */ |
71 | - do_action( 'wp_print_scripts' ); |
|
72 | - if ( '' === $handles ) { // for wp_head |
|
71 | + do_action('wp_print_scripts'); |
|
72 | + if ('' === $handles) { // for wp_head |
|
73 | 73 | $handles = false; |
74 | 74 | } |
75 | 75 | |
76 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
76 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
77 | 77 | |
78 | 78 | global $wp_scripts; |
79 | - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
80 | - if ( ! $handles ) { |
|
79 | + if ( ! ($wp_scripts instanceof WP_Scripts)) { |
|
80 | + if ( ! $handles) { |
|
81 | 81 | return array(); // No need to instantiate if nothing is there. |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - return wp_scripts()->do_items( $handles ); |
|
85 | + return wp_scripts()->do_items($handles); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * Default 'false'. Accepts 'false' or 'true'. |
108 | 108 | * @return bool Whether the script has been registered. True on success, false on failure. |
109 | 109 | */ |
110 | -function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
|
110 | +function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false) { |
|
111 | 111 | $wp_scripts = wp_scripts(); |
112 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
112 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
113 | 113 | |
114 | - $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); |
|
115 | - if ( $in_footer ) { |
|
116 | - $wp_scripts->add_data( $handle, 'group', 1 ); |
|
114 | + $registered = $wp_scripts->add($handle, $src, $deps, $ver); |
|
115 | + if ($in_footer) { |
|
116 | + $wp_scripts->add_data($handle, 'group', 1); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $registered; |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | * @param array $l10n The data itself. The data can be either a single or multi-dimensional array. |
148 | 148 | * @return bool True if the script was successfully localized, false otherwise. |
149 | 149 | */ |
150 | -function wp_localize_script( $handle, $object_name, $l10n ) { |
|
150 | +function wp_localize_script($handle, $object_name, $l10n) { |
|
151 | 151 | global $wp_scripts; |
152 | - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
153 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
152 | + if ( ! ($wp_scripts instanceof WP_Scripts)) { |
|
153 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
154 | 154 | return false; |
155 | 155 | } |
156 | 156 | |
157 | - return $wp_scripts->localize( $handle, $object_name, $l10n ); |
|
157 | + return $wp_scripts->localize($handle, $object_name, $l10n); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @param string $handle Name of the script to be removed. |
171 | 171 | */ |
172 | -function wp_deregister_script( $handle ) { |
|
173 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
172 | +function wp_deregister_script($handle) { |
|
173 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
174 | 174 | |
175 | 175 | /** |
176 | 176 | * Do not allow accidental or negligent de-registering of critical scripts in the admin. |
177 | 177 | * Show minimal remorse if the correct hook is used. |
178 | 178 | */ |
179 | 179 | $current_filter = current_filter(); |
180 | - if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || |
|
181 | - ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) |
|
180 | + if ((is_admin() && 'admin_enqueue_scripts' !== $current_filter) || |
|
181 | + ('wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter) |
|
182 | 182 | ) { |
183 | 183 | $no = array( |
184 | 184 | 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', |
190 | 190 | ); |
191 | 191 | |
192 | - if ( in_array( $handle, $no ) ) { |
|
193 | - $message = sprintf( __( 'Do not deregister the %1$s script in the administration area. To target the frontend theme, use the %2$s hook.' ), |
|
194 | - "<code>$handle</code>", '<code>wp_enqueue_scripts</code>' ); |
|
195 | - _doing_it_wrong( __FUNCTION__, $message, '3.6' ); |
|
192 | + if (in_array($handle, $no)) { |
|
193 | + $message = sprintf(__('Do not deregister the %1$s script in the administration area. To target the frontend theme, use the %2$s hook.'), |
|
194 | + "<code>$handle</code>", '<code>wp_enqueue_scripts</code>'); |
|
195 | + _doing_it_wrong(__FUNCTION__, $message, '3.6'); |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - wp_scripts()->remove( $handle ); |
|
200 | + wp_scripts()->remove($handle); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -218,25 +218,25 @@ discard block |
||
218 | 218 | * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. |
219 | 219 | * Default 'false'. Accepts 'false' or 'true'. |
220 | 220 | */ |
221 | -function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { |
|
221 | +function wp_enqueue_script($handle, $src = false, $deps = array(), $ver = false, $in_footer = false) { |
|
222 | 222 | $wp_scripts = wp_scripts(); |
223 | 223 | |
224 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
224 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
225 | 225 | |
226 | 226 | |
227 | - if ( $src || $in_footer ) { |
|
228 | - $_handle = explode( '?', $handle ); |
|
227 | + if ($src || $in_footer) { |
|
228 | + $_handle = explode('?', $handle); |
|
229 | 229 | |
230 | - if ( $src ) { |
|
231 | - $wp_scripts->add( $_handle[0], $src, $deps, $ver ); |
|
230 | + if ($src) { |
|
231 | + $wp_scripts->add($_handle[0], $src, $deps, $ver); |
|
232 | 232 | } |
233 | 233 | |
234 | - if ( $in_footer ) { |
|
235 | - $wp_scripts->add_data( $_handle[0], 'group', 1 ); |
|
234 | + if ($in_footer) { |
|
235 | + $wp_scripts->add_data($_handle[0], 'group', 1); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - $wp_scripts->enqueue( $handle ); |
|
239 | + $wp_scripts->enqueue($handle); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @param string $handle Name of the script to be removed. |
250 | 250 | */ |
251 | -function wp_dequeue_script( $handle ) { |
|
252 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
251 | +function wp_dequeue_script($handle) { |
|
252 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
253 | 253 | |
254 | - wp_scripts()->dequeue( $handle ); |
|
254 | + wp_scripts()->dequeue($handle); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | * Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
266 | 266 | * @return bool Whether the script script is queued. |
267 | 267 | */ |
268 | -function wp_script_is( $handle, $list = 'enqueued' ) { |
|
269 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
268 | +function wp_script_is($handle, $list = 'enqueued') { |
|
269 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
270 | 270 | |
271 | - return (bool) wp_scripts()->query( $handle, $list ); |
|
271 | + return (bool) wp_scripts()->query($handle, $list); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -288,6 +288,6 @@ discard block |
||
288 | 288 | * @param mixed $value String containing the data to be added. |
289 | 289 | * @return bool True on success, false on failure. |
290 | 290 | */ |
291 | -function wp_script_add_data( $handle, $key, $value ){ |
|
292 | - return wp_scripts()->add_data( $handle, $key, $value ); |
|
291 | +function wp_script_add_data($handle, $key, $value) { |
|
292 | + return wp_scripts()->add_data($handle, $key, $value); |
|
293 | 293 | } |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Category API |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - */ |
|
3 | + * WordPress Category API |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Retrieve list of category objects. |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | * @param string|array $args Optional. Change the defaults retrieving categories. |
20 | 20 | * @return array List of categories. |
21 | 21 | */ |
22 | -function get_categories( $args = '' ) { |
|
23 | - $defaults = array( 'taxonomy' => 'category' ); |
|
24 | - $args = wp_parse_args( $args, $defaults ); |
|
22 | +function get_categories($args = '') { |
|
23 | + $defaults = array('taxonomy' => 'category'); |
|
24 | + $args = wp_parse_args($args, $defaults); |
|
25 | 25 | |
26 | 26 | $taxonomy = $args['taxonomy']; |
27 | 27 | |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | * @param string $taxonomy Taxonomy to retrieve terms from. |
34 | 34 | * @param array $args An array of arguments. See {@see get_terms()}. |
35 | 35 | */ |
36 | - $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); |
|
36 | + $taxonomy = apply_filters('get_categories_taxonomy', $taxonomy, $args); |
|
37 | 37 | |
38 | 38 | // Back compat |
39 | - if ( isset($args['type']) && 'link' == $args['type'] ) { |
|
40 | - _deprecated_argument( __FUNCTION__, '3.0', '' ); |
|
39 | + if (isset($args['type']) && 'link' == $args['type']) { |
|
40 | + _deprecated_argument(__FUNCTION__, '3.0', ''); |
|
41 | 41 | $taxonomy = $args['taxonomy'] = 'link_category'; |
42 | 42 | } |
43 | 43 | |
44 | - $categories = (array) get_terms( $taxonomy, $args ); |
|
44 | + $categories = (array) get_terms($taxonomy, $args); |
|
45 | 45 | |
46 | - foreach ( array_keys( $categories ) as $k ) |
|
47 | - _make_cat_compat( $categories[$k] ); |
|
46 | + foreach (array_keys($categories) as $k) |
|
47 | + _make_cat_compat($categories[$k]); |
|
48 | 48 | |
49 | 49 | return $categories; |
50 | 50 | } |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | * @return object|array|WP_Error|null Category data in type defined by $output parameter. |
72 | 72 | * WP_Error if $category is empty, null if it does not exist. |
73 | 73 | */ |
74 | -function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
|
75 | - $category = get_term( $category, 'category', $output, $filter ); |
|
74 | +function get_category($category, $output = OBJECT, $filter = 'raw') { |
|
75 | + $category = get_term($category, 'category', $output, $filter); |
|
76 | 76 | |
77 | - if ( is_wp_error( $category ) ) |
|
77 | + if (is_wp_error($category)) |
|
78 | 78 | return $category; |
79 | 79 | |
80 | - _make_cat_compat( $category ); |
|
80 | + _make_cat_compat($category); |
|
81 | 81 | |
82 | 82 | return $category; |
83 | 83 | } |
@@ -101,45 +101,45 @@ discard block |
||
101 | 101 | * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
102 | 102 | * @return object|array|WP_Error|void Type is based on $output value. |
103 | 103 | */ |
104 | -function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) { |
|
105 | - $category_path = rawurlencode( urldecode( $category_path ) ); |
|
106 | - $category_path = str_replace( '%2F', '/', $category_path ); |
|
107 | - $category_path = str_replace( '%20', ' ', $category_path ); |
|
108 | - $category_paths = '/' . trim( $category_path, '/' ); |
|
109 | - $leaf_path = sanitize_title( basename( $category_paths ) ); |
|
110 | - $category_paths = explode( '/', $category_paths ); |
|
104 | +function get_category_by_path($category_path, $full_match = true, $output = OBJECT) { |
|
105 | + $category_path = rawurlencode(urldecode($category_path)); |
|
106 | + $category_path = str_replace('%2F', '/', $category_path); |
|
107 | + $category_path = str_replace('%20', ' ', $category_path); |
|
108 | + $category_paths = '/'.trim($category_path, '/'); |
|
109 | + $leaf_path = sanitize_title(basename($category_paths)); |
|
110 | + $category_paths = explode('/', $category_paths); |
|
111 | 111 | $full_path = ''; |
112 | - foreach ( (array) $category_paths as $pathdir ) { |
|
113 | - $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir ); |
|
112 | + foreach ((array) $category_paths as $pathdir) { |
|
113 | + $full_path .= ($pathdir != '' ? '/' : '').sanitize_title($pathdir); |
|
114 | 114 | } |
115 | - $categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) ); |
|
115 | + $categories = get_terms('category', array('get' => 'all', 'slug' => $leaf_path)); |
|
116 | 116 | |
117 | - if ( empty( $categories ) ) { |
|
117 | + if (empty($categories)) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | - foreach ( $categories as $category ) { |
|
122 | - $path = '/' . $leaf_path; |
|
121 | + foreach ($categories as $category) { |
|
122 | + $path = '/'.$leaf_path; |
|
123 | 123 | $curcategory = $category; |
124 | - while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) { |
|
125 | - $curcategory = get_term( $curcategory->parent, 'category' ); |
|
126 | - if ( is_wp_error( $curcategory ) ) { |
|
124 | + while (($curcategory->parent != 0) && ($curcategory->parent != $curcategory->term_id)) { |
|
125 | + $curcategory = get_term($curcategory->parent, 'category'); |
|
126 | + if (is_wp_error($curcategory)) { |
|
127 | 127 | return $curcategory; |
128 | 128 | } |
129 | - $path = '/' . $curcategory->slug . $path; |
|
129 | + $path = '/'.$curcategory->slug.$path; |
|
130 | 130 | } |
131 | 131 | |
132 | - if ( $path == $full_path ) { |
|
133 | - $category = get_term( $category->term_id, 'category', $output ); |
|
134 | - _make_cat_compat( $category ); |
|
132 | + if ($path == $full_path) { |
|
133 | + $category = get_term($category->term_id, 'category', $output); |
|
134 | + _make_cat_compat($category); |
|
135 | 135 | return $category; |
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | 139 | // If full matching is not required, return the first cat that matches the leaf. |
140 | - if ( ! $full_match ) { |
|
141 | - $category = get_term( reset( $categories )->term_id, 'category', $output ); |
|
142 | - _make_cat_compat( $category ); |
|
140 | + if ( ! $full_match) { |
|
141 | + $category = get_term(reset($categories)->term_id, 'category', $output); |
|
142 | + _make_cat_compat($category); |
|
143 | 143 | return $category; |
144 | 144 | } |
145 | 145 | } |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param string $slug The category slug. |
153 | 153 | * @return object Category data object |
154 | 154 | */ |
155 | -function get_category_by_slug( $slug ) { |
|
156 | - $category = get_term_by( 'slug', $slug, 'category' ); |
|
157 | - if ( $category ) |
|
158 | - _make_cat_compat( $category ); |
|
155 | +function get_category_by_slug($slug) { |
|
156 | + $category = get_term_by('slug', $slug, 'category'); |
|
157 | + if ($category) |
|
158 | + _make_cat_compat($category); |
|
159 | 159 | |
160 | 160 | return $category; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * @param string $cat_name Category name. |
169 | 169 | * @return int 0, if failure and ID of category on success. |
170 | 170 | */ |
171 | -function get_cat_ID( $cat_name ) { |
|
172 | - $cat = get_term_by( 'name', $cat_name, 'category' ); |
|
173 | - if ( $cat ) |
|
171 | +function get_cat_ID($cat_name) { |
|
172 | + $cat = get_term_by('name', $cat_name, 'category'); |
|
173 | + if ($cat) |
|
174 | 174 | return $cat->term_id; |
175 | 175 | return 0; |
176 | 176 | } |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | * @param int $cat_id Category ID |
184 | 184 | * @return string Category name, or an empty string if category doesn't exist. |
185 | 185 | */ |
186 | -function get_cat_name( $cat_id ) { |
|
186 | +function get_cat_name($cat_id) { |
|
187 | 187 | $cat_id = (int) $cat_id; |
188 | - $category = get_term( $cat_id, 'category' ); |
|
189 | - if ( ! $category || is_wp_error( $category ) ) |
|
188 | + $category = get_term($cat_id, 'category'); |
|
189 | + if ( ! $category || is_wp_error($category)) |
|
190 | 190 | return ''; |
191 | 191 | return $category->name; |
192 | 192 | } |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param int|object $cat2 The child category. |
204 | 204 | * @return bool Whether $cat2 is child of $cat1 |
205 | 205 | */ |
206 | -function cat_is_ancestor_of( $cat1, $cat2 ) { |
|
207 | - return term_is_ancestor_of( $cat1, $cat2, 'category' ); |
|
206 | +function cat_is_ancestor_of($cat1, $cat2) { |
|
207 | + return term_is_ancestor_of($cat1, $cat2, 'category'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @param string $context Optional. Default is 'display'. |
217 | 217 | * @return object|array Same type as $category with sanitized data for safe use. |
218 | 218 | */ |
219 | -function sanitize_category( $category, $context = 'display' ) { |
|
220 | - return sanitize_term( $category, 'category', $context ); |
|
219 | +function sanitize_category($category, $context = 'display') { |
|
220 | + return sanitize_term($category, 'category', $context); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | * @param string $context What filter to use, 'raw', 'display', etc. |
232 | 232 | * @return mixed Same type as $value after $value has been sanitized. |
233 | 233 | */ |
234 | -function sanitize_category_field( $field, $value, $cat_id, $context ) { |
|
235 | - return sanitize_term_field( $field, $value, $cat_id, 'category', $context ); |
|
234 | +function sanitize_category_field($field, $value, $cat_id, $context) { |
|
235 | + return sanitize_term_field($field, $value, $cat_id, 'category', $context); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /* Tags */ |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | * @param string|array $args Tag arguments to use when retrieving tags. |
247 | 247 | * @return array List of tags. |
248 | 248 | */ |
249 | -function get_tags( $args = '' ) { |
|
250 | - $tags = get_terms( 'post_tag', $args ); |
|
249 | +function get_tags($args = '') { |
|
250 | + $tags = get_terms('post_tag', $args); |
|
251 | 251 | |
252 | - if ( empty( $tags ) ) { |
|
252 | + if (empty($tags)) { |
|
253 | 253 | $return = array(); |
254 | 254 | return $return; |
255 | 255 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param array $tags Array of 'post_tag' term objects. |
263 | 263 | * @param array $args An array of arguments. @see get_terms() |
264 | 264 | */ |
265 | - $tags = apply_filters( 'get_tags', $tags, $args ); |
|
265 | + $tags = apply_filters('get_tags', $tags, $args); |
|
266 | 266 | return $tags; |
267 | 267 | } |
268 | 268 | |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
286 | 286 | * @return object|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist. |
287 | 287 | */ |
288 | -function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { |
|
289 | - return get_term( $tag, 'post_tag', $output, $filter ); |
|
288 | +function get_tag($tag, $output = OBJECT, $filter = 'raw') { |
|
289 | + return get_term($tag, 'post_tag', $output, $filter); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /* Cache */ |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @param int $id Category ID |
300 | 300 | */ |
301 | -function clean_category_cache( $id ) { |
|
302 | - clean_term_cache( $id, 'category' ); |
|
301 | +function clean_category_cache($id) { |
|
302 | + clean_term_cache($id, 'category'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -321,15 +321,15 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param array|object $category Category Row object or array |
323 | 323 | */ |
324 | -function _make_cat_compat( &$category ) { |
|
325 | - if ( is_object( $category ) && ! is_wp_error( $category ) ) { |
|
324 | +function _make_cat_compat(&$category) { |
|
325 | + if (is_object($category) && ! is_wp_error($category)) { |
|
326 | 326 | $category->cat_ID = &$category->term_id; |
327 | 327 | $category->category_count = &$category->count; |
328 | 328 | $category->category_description = &$category->description; |
329 | 329 | $category->cat_name = &$category->name; |
330 | 330 | $category->category_nicename = &$category->slug; |
331 | 331 | $category->category_parent = &$category->parent; |
332 | - } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { |
|
332 | + } elseif (is_array($category) && isset($category['term_id'])) { |
|
333 | 333 | $category['cat_ID'] = &$category['term_id']; |
334 | 334 | $category['category_count'] = &$category['count']; |
335 | 335 | $category['category_description'] = &$category['description']; |
@@ -43,8 +43,9 @@ discard block |
||
43 | 43 | |
44 | 44 | $categories = (array) get_terms( $taxonomy, $args ); |
45 | 45 | |
46 | - foreach ( array_keys( $categories ) as $k ) |
|
47 | - _make_cat_compat( $categories[$k] ); |
|
46 | + foreach ( array_keys( $categories ) as $k ) { |
|
47 | + _make_cat_compat( $categories[$k] ); |
|
48 | + } |
|
48 | 49 | |
49 | 50 | return $categories; |
50 | 51 | } |
@@ -74,8 +75,9 @@ discard block |
||
74 | 75 | function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
75 | 76 | $category = get_term( $category, 'category', $output, $filter ); |
76 | 77 | |
77 | - if ( is_wp_error( $category ) ) |
|
78 | - return $category; |
|
78 | + if ( is_wp_error( $category ) ) { |
|
79 | + return $category; |
|
80 | + } |
|
79 | 81 | |
80 | 82 | _make_cat_compat( $category ); |
81 | 83 | |
@@ -154,8 +156,9 @@ discard block |
||
154 | 156 | */ |
155 | 157 | function get_category_by_slug( $slug ) { |
156 | 158 | $category = get_term_by( 'slug', $slug, 'category' ); |
157 | - if ( $category ) |
|
158 | - _make_cat_compat( $category ); |
|
159 | + if ( $category ) { |
|
160 | + _make_cat_compat( $category ); |
|
161 | + } |
|
159 | 162 | |
160 | 163 | return $category; |
161 | 164 | } |
@@ -170,8 +173,9 @@ discard block |
||
170 | 173 | */ |
171 | 174 | function get_cat_ID( $cat_name ) { |
172 | 175 | $cat = get_term_by( 'name', $cat_name, 'category' ); |
173 | - if ( $cat ) |
|
174 | - return $cat->term_id; |
|
176 | + if ( $cat ) { |
|
177 | + return $cat->term_id; |
|
178 | + } |
|
175 | 179 | return 0; |
176 | 180 | } |
177 | 181 | |
@@ -186,8 +190,9 @@ discard block |
||
186 | 190 | function get_cat_name( $cat_id ) { |
187 | 191 | $cat_id = (int) $cat_id; |
188 | 192 | $category = get_term( $cat_id, 'category' ); |
189 | - if ( ! $category || is_wp_error( $category ) ) |
|
190 | - return ''; |
|
193 | + if ( ! $category || is_wp_error( $category ) ) { |
|
194 | + return ''; |
|
195 | + } |
|
191 | 196 | return $category->name; |
192 | 197 | } |
193 | 198 |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Customize Panel classes |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Customize |
|
7 | - * @since 4.0.0 |
|
8 | - */ |
|
3 | + * WordPress Customize Panel classes |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Customize |
|
7 | + * @since 4.0.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Customize Panel class. |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | * @param string $id An specific ID for the panel. |
149 | 149 | * @param array $args Panel arguments. |
150 | 150 | */ |
151 | - public function __construct( $manager, $id, $args = array() ) { |
|
152 | - $keys = array_keys( get_object_vars( $this ) ); |
|
153 | - foreach ( $keys as $key ) { |
|
154 | - if ( isset( $args[ $key ] ) ) { |
|
155 | - $this->$key = $args[ $key ]; |
|
151 | + public function __construct($manager, $id, $args = array()) { |
|
152 | + $keys = array_keys(get_object_vars($this)); |
|
153 | + foreach ($keys as $key) { |
|
154 | + if (isset($args[$key])) { |
|
155 | + $this->$key = $args[$key]; |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | 159 | $this->manager = $manager; |
160 | 160 | $this->id = $id; |
161 | - if ( empty( $this->active_callback ) ) { |
|
162 | - $this->active_callback = array( $this, 'active_callback' ); |
|
161 | + if (empty($this->active_callback)) { |
|
162 | + $this->active_callback = array($this, 'active_callback'); |
|
163 | 163 | } |
164 | 164 | self::$instance_count += 1; |
165 | 165 | $this->instance_number = self::$instance_count; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | final public function active() { |
179 | 179 | $panel = $this; |
180 | - $active = call_user_func( $this->active_callback, $this ); |
|
180 | + $active = call_user_func($this->active_callback, $this); |
|
181 | 181 | |
182 | 182 | /** |
183 | 183 | * Filter response of WP_Customize_Panel::active(). |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param bool $active Whether the Customizer panel is active. |
188 | 188 | * @param WP_Customize_Panel $panel {@see WP_Customize_Panel} instance. |
189 | 189 | */ |
190 | - $active = apply_filters( 'customize_panel_active', $active, $panel ); |
|
190 | + $active = apply_filters('customize_panel_active', $active, $panel); |
|
191 | 191 | |
192 | 192 | return $active; |
193 | 193 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | * @return array The array to be exported to the client as JSON. |
216 | 216 | */ |
217 | 217 | public function json() { |
218 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'type' ) ); |
|
219 | - $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); |
|
218 | + $array = wp_array_slice_assoc((array) $this, array('id', 'description', 'priority', 'type')); |
|
219 | + $array['title'] = html_entity_decode($this->title, ENT_QUOTES, get_bloginfo('charset')); |
|
220 | 220 | $array['content'] = $this->get_content(); |
221 | 221 | $array['active'] = $this->active(); |
222 | 222 | $array['instanceNumber'] = $this->instance_number; |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | * @return bool False if theme doesn't support the panel or the user doesn't have the capability. |
233 | 233 | */ |
234 | 234 | final public function check_capabilities() { |
235 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
235 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | |
239 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
239 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | final public function get_content() { |
254 | 254 | ob_start(); |
255 | 255 | $this->maybe_render(); |
256 | - return trim( ob_get_clean() ); |
|
256 | + return trim(ob_get_clean()); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @since 4.0.0 |
263 | 263 | */ |
264 | 264 | final public function maybe_render() { |
265 | - if ( ! $this->check_capabilities() ) { |
|
265 | + if ( ! $this->check_capabilities()) { |
|
266 | 266 | return; |
267 | 267 | } |
268 | 268 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WP_Customize_Panel $this WP_Customize_Panel instance. |
275 | 275 | */ |
276 | - do_action( 'customize_render_panel', $this ); |
|
276 | + do_action('customize_render_panel', $this); |
|
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Fires before rendering a specific Customizer panel. |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @since 4.0.0 |
285 | 285 | */ |
286 | - do_action( "customize_render_panel_{$this->id}" ); |
|
286 | + do_action("customize_render_panel_{$this->id}"); |
|
287 | 287 | |
288 | 288 | $this->render(); |
289 | 289 | } |
@@ -320,10 +320,10 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function print_template() { |
322 | 322 | ?> |
323 | - <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>-content"> |
|
323 | + <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr($this->type); ?>-content"> |
|
324 | 324 | <?php $this->content_template(); ?> |
325 | 325 | </script> |
326 | - <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>"> |
|
326 | + <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr($this->type); ?>"> |
|
327 | 327 | <?php $this->render_template(); ?> |
328 | 328 | </script> |
329 | 329 | <?php |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | <li id="accordion-panel-{{ data.id }}" class="accordion-section control-section control-panel control-panel-{{ data.type }}"> |
346 | 346 | <h3 class="accordion-section-title" tabindex="0"> |
347 | 347 | {{ data.title }} |
348 | - <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span> |
|
348 | + <span class="screen-reader-text"><?php _e('Press return or enter to open this panel'); ?></span> |
|
349 | 349 | </h3> |
350 | 350 | <ul class="accordion-sub-container control-panel-content"></ul> |
351 | 351 | </li> |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | protected function content_template() { |
367 | 367 | ?> |
368 | 368 | <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> |
369 | - <button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></button> |
|
369 | + <button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e('Back'); ?></span></button> |
|
370 | 370 | <div class="accordion-section-title"> |
371 | 371 | <span class="preview-notice"><?php |
372 | 372 | /* translators: %s is the site/panel title in the Customizer */ |
373 | - echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); |
|
373 | + echo sprintf(__('You are customizing %s'), '<strong class="panel-title">{{ data.title }}</strong>'); |
|
374 | 374 | ?></span> |
375 | - <button class="customize-help-toggle dashicons dashicons-editor-help" tabindex="0" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button> |
|
375 | + <button class="customize-help-toggle dashicons dashicons-editor-help" tabindex="0" aria-expanded="false"><span class="screen-reader-text"><?php _e('Help'); ?></span></button> |
|
376 | 376 | </div> |
377 | 377 | <# if ( data.description ) { #> |
378 | 378 | <div class="description customize-panel-description"> |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | */ |
413 | 413 | public function render_screen_options() { |
414 | 414 | // Essentially adds the screen options. |
415 | - add_filter( 'manage_nav-menus_columns', array( $this, 'wp_nav_menu_manage_columns' ) ); |
|
415 | + add_filter('manage_nav-menus_columns', array($this, 'wp_nav_menu_manage_columns')); |
|
416 | 416 | |
417 | 417 | // Display screen options. |
418 | - $screen = WP_Screen::get( 'nav-menus.php' ); |
|
418 | + $screen = WP_Screen::get('nav-menus.php'); |
|
419 | 419 | $screen->render_screen_options(); |
420 | 420 | } |
421 | 421 | |
@@ -431,13 +431,13 @@ discard block |
||
431 | 431 | */ |
432 | 432 | public function wp_nav_menu_manage_columns() { |
433 | 433 | return array( |
434 | - '_title' => __( 'Show advanced menu properties' ), |
|
434 | + '_title' => __('Show advanced menu properties'), |
|
435 | 435 | 'cb' => '<input type="checkbox" />', |
436 | - 'link-target' => __( 'Link Target' ), |
|
437 | - 'attr-title' => __( 'Title Attribute' ), |
|
438 | - 'css-classes' => __( 'CSS Classes' ), |
|
439 | - 'xfn' => __( 'Link Relationship (XFN)' ), |
|
440 | - 'description' => __( 'Description' ), |
|
436 | + 'link-target' => __('Link Target'), |
|
437 | + 'attr-title' => __('Title Attribute'), |
|
438 | + 'css-classes' => __('CSS Classes'), |
|
439 | + 'xfn' => __('Link Relationship (XFN)'), |
|
440 | + 'description' => __('Description'), |
|
441 | 441 | ); |
442 | 442 | } |
443 | 443 | |
@@ -456,20 +456,20 @@ discard block |
||
456 | 456 | ?> |
457 | 457 | <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> |
458 | 458 | <button type="button" class="customize-panel-back" tabindex="-1"> |
459 | - <span class="screen-reader-text"><?php _e( 'Back' ); ?></span> |
|
459 | + <span class="screen-reader-text"><?php _e('Back'); ?></span> |
|
460 | 460 | </button> |
461 | 461 | <div class="accordion-section-title"> |
462 | 462 | <span class="preview-notice"> |
463 | 463 | <?php |
464 | 464 | /* Translators: %s is the site/panel title in the Customizer. */ |
465 | - printf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); |
|
465 | + printf(__('You are customizing %s'), '<strong class="panel-title">{{ data.title }}</strong>'); |
|
466 | 466 | ?> |
467 | 467 | </span> |
468 | 468 | <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"> |
469 | - <span class="screen-reader-text"><?php _e( 'Help' ); ?></span> |
|
469 | + <span class="screen-reader-text"><?php _e('Help'); ?></span> |
|
470 | 470 | </button> |
471 | 471 | <button type="button" class="customize-screen-options-toggle" aria-expanded="false"> |
472 | - <span class="screen-reader-text"><?php _e( 'Menu Options' ); ?></span> |
|
472 | + <span class="screen-reader-text"><?php _e('Menu Options'); ?></span> |
|
473 | 473 | </button> |
474 | 474 | </div> |
475 | 475 | <# if ( data.description ) { #> |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param string|array $args Optional. Will be passed to add() method. |
24 | 24 | */ |
25 | - public function __construct( $args = '' ) { |
|
26 | - if ( !empty($args) ) |
|
25 | + public function __construct($args = '') { |
|
26 | + if ( ! empty($args)) |
|
27 | 27 | $this->add($args); |
28 | 28 | } |
29 | 29 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param string|array $args Override defaults. |
51 | 51 | * @return string XML response. |
52 | 52 | */ |
53 | - public function add( $args = '' ) { |
|
53 | + public function add($args = '') { |
|
54 | 54 | $defaults = array( |
55 | 55 | 'what' => 'object', 'action' => false, |
56 | 56 | 'id' => '0', 'old_id' => false, |
@@ -58,39 +58,39 @@ discard block |
||
58 | 58 | 'data' => '', 'supplemental' => array() |
59 | 59 | ); |
60 | 60 | |
61 | - $r = wp_parse_args( $args, $defaults ); |
|
61 | + $r = wp_parse_args($args, $defaults); |
|
62 | 62 | |
63 | - $position = preg_replace( '/[^a-z0-9:_-]/i', '', $r['position'] ); |
|
63 | + $position = preg_replace('/[^a-z0-9:_-]/i', '', $r['position']); |
|
64 | 64 | $id = $r['id']; |
65 | 65 | $what = $r['what']; |
66 | 66 | $action = $r['action']; |
67 | 67 | $old_id = $r['old_id']; |
68 | 68 | $data = $r['data']; |
69 | 69 | |
70 | - if ( is_wp_error( $id ) ) { |
|
70 | + if (is_wp_error($id)) { |
|
71 | 71 | $data = $id; |
72 | 72 | $id = 0; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $response = ''; |
76 | - if ( is_wp_error( $data ) ) { |
|
77 | - foreach ( (array) $data->get_error_codes() as $code ) { |
|
78 | - $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . "]]></wp_error>"; |
|
79 | - if ( ! $error_data = $data->get_error_data( $code ) ) { |
|
76 | + if (is_wp_error($data)) { |
|
77 | + foreach ((array) $data->get_error_codes() as $code) { |
|
78 | + $response .= "<wp_error code='$code'><![CDATA[".$data->get_error_message($code)."]]></wp_error>"; |
|
79 | + if ( ! $error_data = $data->get_error_data($code)) { |
|
80 | 80 | continue; |
81 | 81 | } |
82 | 82 | $class = ''; |
83 | - if ( is_object( $error_data ) ) { |
|
84 | - $class = ' class="' . get_class( $error_data ) . '"'; |
|
85 | - $error_data = get_object_vars( $error_data ); |
|
83 | + if (is_object($error_data)) { |
|
84 | + $class = ' class="'.get_class($error_data).'"'; |
|
85 | + $error_data = get_object_vars($error_data); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $response .= "<wp_error_data code='$code'$class>"; |
89 | 89 | |
90 | - if ( is_scalar( $error_data ) ) { |
|
90 | + if (is_scalar($error_data)) { |
|
91 | 91 | $response .= "<![CDATA[$error_data]]>"; |
92 | - } elseif ( is_array( $error_data ) ) { |
|
93 | - foreach ( $error_data as $k => $v ) { |
|
92 | + } elseif (is_array($error_data)) { |
|
93 | + foreach ($error_data as $k => $v) { |
|
94 | 94 | $response .= "<$k><![CDATA[$v]]></$k>"; |
95 | 95 | } |
96 | 96 | } |
@@ -102,22 +102,22 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | $s = ''; |
105 | - if ( is_array( $r['supplemental'] ) ) { |
|
106 | - foreach ( $r['supplemental'] as $k => $v ) { |
|
105 | + if (is_array($r['supplemental'])) { |
|
106 | + foreach ($r['supplemental'] as $k => $v) { |
|
107 | 107 | $s .= "<$k><![CDATA[$v]]></$k>"; |
108 | 108 | } |
109 | 109 | $s = "<supplemental>$s</supplemental>"; |
110 | 110 | } |
111 | 111 | |
112 | - if ( false === $action ) { |
|
112 | + if (false === $action) { |
|
113 | 113 | $action = $_POST['action']; |
114 | 114 | } |
115 | 115 | $x = ''; |
116 | 116 | $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action |
117 | - $x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>"; |
|
118 | - $x .= $response; |
|
119 | - $x .= $s; |
|
120 | - $x .= "</$what>"; |
|
117 | + $x .= "<$what id='$id' ".(false === $old_id ? '' : "old_id='$old_id' ")."position='$position'>"; |
|
118 | + $x .= $response; |
|
119 | + $x .= $s; |
|
120 | + $x .= "</$what>"; |
|
121 | 121 | $x .= "</response>"; |
122 | 122 | |
123 | 123 | $this->responses[] = $x; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * @since 2.1.0 |
133 | 133 | */ |
134 | 134 | public function send() { |
135 | - header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) ); |
|
136 | - echo "<?xml version='1.0' encoding='" . get_option( 'blog_charset' ) . "' standalone='yes'?><wp_ajax>"; |
|
137 | - foreach ( (array) $this->responses as $response ) |
|
135 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
136 | + echo "<?xml version='1.0' encoding='".get_option('blog_charset')."' standalone='yes'?><wp_ajax>"; |
|
137 | + foreach ((array) $this->responses as $response) |
|
138 | 138 | echo $response; |
139 | 139 | echo '</wp_ajax>'; |
140 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
140 | + if (defined('DOING_AJAX') && DOING_AJAX) |
|
141 | 141 | wp_die(); |
142 | 142 | else |
143 | 143 | die(); |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | * @param string|array $args Optional. Will be passed to add() method. |
24 | 24 | */ |
25 | 25 | public function __construct( $args = '' ) { |
26 | - if ( !empty($args) ) |
|
27 | - $this->add($args); |
|
26 | + if ( !empty($args) ) { |
|
27 | + $this->add($args); |
|
28 | + } |
|
28 | 29 | } |
29 | 30 | |
30 | 31 | /** |
@@ -134,12 +135,14 @@ discard block |
||
134 | 135 | public function send() { |
135 | 136 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) ); |
136 | 137 | echo "<?xml version='1.0' encoding='" . get_option( 'blog_charset' ) . "' standalone='yes'?><wp_ajax>"; |
137 | - foreach ( (array) $this->responses as $response ) |
|
138 | - echo $response; |
|
138 | + foreach ( (array) $this->responses as $response ) { |
|
139 | + echo $response; |
|
140 | + } |
|
139 | 141 | echo '</wp_ajax>'; |
140 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
141 | - wp_die(); |
|
142 | - else |
|
143 | - die(); |
|
142 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
143 | + wp_die(); |
|
144 | + } else { |
|
145 | + die(); |
|
146 | + } |
|
144 | 147 | } |
145 | 148 | } |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Metadata API |
|
4 | - * |
|
5 | - * Functions for retrieving and manipulating metadata of various WordPress object types. Metadata |
|
6 | - * for an object is a represented by a simple key-value pair. Objects may contain multiple |
|
7 | - * metadata entries that share the same key and differ only in their value. |
|
8 | - * |
|
9 | - * @package WordPress |
|
10 | - * @subpackage Meta |
|
11 | - * @since 2.9.0 |
|
12 | - */ |
|
3 | + * Metadata API |
|
4 | + * |
|
5 | + * Functions for retrieving and manipulating metadata of various WordPress object types. Metadata |
|
6 | + * for an object is a represented by a simple key-value pair. Objects may contain multiple |
|
7 | + * metadata entries that share the same key and differ only in their value. |
|
8 | + * |
|
9 | + * @package WordPress |
|
10 | + * @subpackage Meta |
|
11 | + * @since 2.9.0 |
|
12 | + */ |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Add metadata for the specified object. |
@@ -31,26 +31,26 @@ discard block |
||
31 | 31 | function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) { |
32 | 32 | global $wpdb; |
33 | 33 | |
34 | - if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { |
|
34 | + if ( ! $meta_type || ! $meta_key || ! is_numeric($object_id)) { |
|
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | |
38 | - $object_id = absint( $object_id ); |
|
39 | - if ( ! $object_id ) { |
|
38 | + $object_id = absint($object_id); |
|
39 | + if ( ! $object_id) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $table = _get_meta_table( $meta_type ); |
|
44 | - if ( ! $table ) { |
|
43 | + $table = _get_meta_table($meta_type); |
|
44 | + if ( ! $table) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | - $column = sanitize_key($meta_type . '_id'); |
|
48 | + $column = sanitize_key($meta_type.'_id'); |
|
49 | 49 | |
50 | 50 | // expected_slashed ($meta_key) |
51 | 51 | $meta_key = wp_unslash($meta_key); |
52 | 52 | $meta_value = wp_unslash($meta_value); |
53 | - $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type ); |
|
53 | + $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Filter whether to add metadata of a specific type. |
@@ -68,17 +68,17 @@ discard block |
||
68 | 68 | * @param bool $unique Whether the specified meta key should be unique |
69 | 69 | * for the object. Optional. Default false. |
70 | 70 | */ |
71 | - $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); |
|
72 | - if ( null !== $check ) |
|
71 | + $check = apply_filters("add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique); |
|
72 | + if (null !== $check) |
|
73 | 73 | return $check; |
74 | 74 | |
75 | - if ( $unique && $wpdb->get_var( $wpdb->prepare( |
|
75 | + if ($unique && $wpdb->get_var($wpdb->prepare( |
|
76 | 76 | "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d", |
77 | - $meta_key, $object_id ) ) ) |
|
77 | + $meta_key, $object_id ))) |
|
78 | 78 | return false; |
79 | 79 | |
80 | 80 | $_meta_value = $meta_value; |
81 | - $meta_value = maybe_serialize( $meta_value ); |
|
81 | + $meta_value = maybe_serialize($meta_value); |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Fires immediately before meta of a specific type is added. |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | * @param string $meta_key Meta key. |
93 | 93 | * @param mixed $meta_value Meta value. |
94 | 94 | */ |
95 | - do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); |
|
95 | + do_action("add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value); |
|
96 | 96 | |
97 | - $result = $wpdb->insert( $table, array( |
|
97 | + $result = $wpdb->insert($table, array( |
|
98 | 98 | $column => $object_id, |
99 | 99 | 'meta_key' => $meta_key, |
100 | 100 | 'meta_value' => $meta_value |
101 | - ) ); |
|
101 | + )); |
|
102 | 102 | |
103 | - if ( ! $result ) |
|
103 | + if ( ! $result) |
|
104 | 104 | return false; |
105 | 105 | |
106 | 106 | $mid = (int) $wpdb->insert_id; |
107 | 107 | |
108 | - wp_cache_delete($object_id, $meta_type . '_meta'); |
|
108 | + wp_cache_delete($object_id, $meta_type.'_meta'); |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Fires immediately after meta of a specific type is added. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param string $meta_key Meta key. |
121 | 121 | * @param mixed $meta_value Meta value. |
122 | 122 | */ |
123 | - do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); |
|
123 | + do_action("added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value); |
|
124 | 124 | |
125 | 125 | return $mid; |
126 | 126 | } |
@@ -144,28 +144,28 @@ discard block |
||
144 | 144 | function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') { |
145 | 145 | global $wpdb; |
146 | 146 | |
147 | - if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { |
|
147 | + if ( ! $meta_type || ! $meta_key || ! is_numeric($object_id)) { |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | |
151 | - $object_id = absint( $object_id ); |
|
152 | - if ( ! $object_id ) { |
|
151 | + $object_id = absint($object_id); |
|
152 | + if ( ! $object_id) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $table = _get_meta_table( $meta_type ); |
|
157 | - if ( ! $table ) { |
|
156 | + $table = _get_meta_table($meta_type); |
|
157 | + if ( ! $table) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - $column = sanitize_key($meta_type . '_id'); |
|
161 | + $column = sanitize_key($meta_type.'_id'); |
|
162 | 162 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
163 | 163 | |
164 | 164 | // expected_slashed ($meta_key) |
165 | 165 | $meta_key = wp_unslash($meta_key); |
166 | 166 | $passed_value = $meta_value; |
167 | 167 | $meta_value = wp_unslash($meta_value); |
168 | - $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type ); |
|
168 | + $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type); |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Filter whether to update metadata of a specific type. |
@@ -184,36 +184,36 @@ discard block |
||
184 | 184 | * metadata entries with the specified value. |
185 | 185 | * Otherwise, update all entries. |
186 | 186 | */ |
187 | - $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value ); |
|
188 | - if ( null !== $check ) |
|
187 | + $check = apply_filters("update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value); |
|
188 | + if (null !== $check) |
|
189 | 189 | return (bool) $check; |
190 | 190 | |
191 | 191 | // Compare existing value to new value if no prev value given and the key exists only once. |
192 | - if ( empty($prev_value) ) { |
|
192 | + if (empty($prev_value)) { |
|
193 | 193 | $old_value = get_metadata($meta_type, $object_id, $meta_key); |
194 | - if ( count($old_value) == 1 ) { |
|
195 | - if ( $old_value[0] === $meta_value ) |
|
194 | + if (count($old_value) == 1) { |
|
195 | + if ($old_value[0] === $meta_value) |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ); |
|
201 | - if ( empty( $meta_ids ) ) { |
|
200 | + $meta_ids = $wpdb->get_col($wpdb->prepare("SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id)); |
|
201 | + if (empty($meta_ids)) { |
|
202 | 202 | return add_metadata($meta_type, $object_id, $meta_key, $passed_value); |
203 | 203 | } |
204 | 204 | |
205 | 205 | $_meta_value = $meta_value; |
206 | - $meta_value = maybe_serialize( $meta_value ); |
|
206 | + $meta_value = maybe_serialize($meta_value); |
|
207 | 207 | |
208 | - $data = compact( 'meta_value' ); |
|
209 | - $where = array( $column => $object_id, 'meta_key' => $meta_key ); |
|
208 | + $data = compact('meta_value'); |
|
209 | + $where = array($column => $object_id, 'meta_key' => $meta_key); |
|
210 | 210 | |
211 | - if ( !empty( $prev_value ) ) { |
|
211 | + if ( ! empty($prev_value)) { |
|
212 | 212 | $prev_value = maybe_serialize($prev_value); |
213 | 213 | $where['meta_value'] = $prev_value; |
214 | 214 | } |
215 | 215 | |
216 | - foreach ( $meta_ids as $meta_id ) { |
|
216 | + foreach ($meta_ids as $meta_id) { |
|
217 | 217 | /** |
218 | 218 | * Fires immediately before updating metadata of a specific type. |
219 | 219 | * |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | * @param string $meta_key Meta key. |
228 | 228 | * @param mixed $meta_value Meta value. |
229 | 229 | */ |
230 | - do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
230 | + do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value); |
|
231 | 231 | } |
232 | 232 | |
233 | - if ( 'post' == $meta_type ) { |
|
234 | - foreach ( $meta_ids as $meta_id ) { |
|
233 | + if ('post' == $meta_type) { |
|
234 | + foreach ($meta_ids as $meta_id) { |
|
235 | 235 | /** |
236 | 236 | * Fires immediately before updating a post's metadata. |
237 | 237 | * |
@@ -242,17 +242,17 @@ discard block |
||
242 | 242 | * @param string $meta_key Meta key. |
243 | 243 | * @param mixed $meta_value Meta value. |
244 | 244 | */ |
245 | - do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
245 | + do_action('update_postmeta', $meta_id, $object_id, $meta_key, $meta_value); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
249 | - $result = $wpdb->update( $table, $data, $where ); |
|
250 | - if ( ! $result ) |
|
249 | + $result = $wpdb->update($table, $data, $where); |
|
250 | + if ( ! $result) |
|
251 | 251 | return false; |
252 | 252 | |
253 | - wp_cache_delete($object_id, $meta_type . '_meta'); |
|
253 | + wp_cache_delete($object_id, $meta_type.'_meta'); |
|
254 | 254 | |
255 | - foreach ( $meta_ids as $meta_id ) { |
|
255 | + foreach ($meta_ids as $meta_id) { |
|
256 | 256 | /** |
257 | 257 | * Fires immediately after updating metadata of a specific type. |
258 | 258 | * |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | * @param string $meta_key Meta key. |
267 | 267 | * @param mixed $meta_value Meta value. |
268 | 268 | */ |
269 | - do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
269 | + do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value); |
|
270 | 270 | } |
271 | 271 | |
272 | - if ( 'post' == $meta_type ) { |
|
273 | - foreach ( $meta_ids as $meta_id ) { |
|
272 | + if ('post' == $meta_type) { |
|
273 | + foreach ($meta_ids as $meta_id) { |
|
274 | 274 | /** |
275 | 275 | * Fires immediately after updating a post's metadata. |
276 | 276 | * |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @param string $meta_key Meta key. |
282 | 282 | * @param mixed $meta_value Meta value. |
283 | 283 | */ |
284 | - do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
284 | + do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -311,21 +311,21 @@ discard block |
||
311 | 311 | function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) { |
312 | 312 | global $wpdb; |
313 | 313 | |
314 | - if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) { |
|
314 | + if ( ! $meta_type || ! $meta_key || ! is_numeric($object_id) && ! $delete_all) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | - $object_id = absint( $object_id ); |
|
319 | - if ( ! $object_id && ! $delete_all ) { |
|
318 | + $object_id = absint($object_id); |
|
319 | + if ( ! $object_id && ! $delete_all) { |
|
320 | 320 | return false; |
321 | 321 | } |
322 | 322 | |
323 | - $table = _get_meta_table( $meta_type ); |
|
324 | - if ( ! $table ) { |
|
323 | + $table = _get_meta_table($meta_type); |
|
324 | + if ( ! $table) { |
|
325 | 325 | return false; |
326 | 326 | } |
327 | 327 | |
328 | - $type_column = sanitize_key($meta_type . '_id'); |
|
328 | + $type_column = sanitize_key($meta_type.'_id'); |
|
329 | 329 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
330 | 330 | // expected_slashed ($meta_key) |
331 | 331 | $meta_key = wp_unslash($meta_key); |
@@ -348,27 +348,27 @@ discard block |
||
348 | 348 | * for all objects, ignoring the specified $object_id. |
349 | 349 | * Default false. |
350 | 350 | */ |
351 | - $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all ); |
|
352 | - if ( null !== $check ) |
|
351 | + $check = apply_filters("delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all); |
|
352 | + if (null !== $check) |
|
353 | 353 | return (bool) $check; |
354 | 354 | |
355 | 355 | $_meta_value = $meta_value; |
356 | - $meta_value = maybe_serialize( $meta_value ); |
|
356 | + $meta_value = maybe_serialize($meta_value); |
|
357 | 357 | |
358 | - $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); |
|
358 | + $query = $wpdb->prepare("SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key); |
|
359 | 359 | |
360 | - if ( !$delete_all ) |
|
361 | - $query .= $wpdb->prepare(" AND $type_column = %d", $object_id ); |
|
360 | + if ( ! $delete_all) |
|
361 | + $query .= $wpdb->prepare(" AND $type_column = %d", $object_id); |
|
362 | 362 | |
363 | - if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) |
|
364 | - $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value ); |
|
363 | + if ('' !== $meta_value && null !== $meta_value && false !== $meta_value) |
|
364 | + $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value); |
|
365 | 365 | |
366 | - $meta_ids = $wpdb->get_col( $query ); |
|
367 | - if ( !count( $meta_ids ) ) |
|
366 | + $meta_ids = $wpdb->get_col($query); |
|
367 | + if ( ! count($meta_ids)) |
|
368 | 368 | return false; |
369 | 369 | |
370 | - if ( $delete_all ) |
|
371 | - $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); |
|
370 | + if ($delete_all) |
|
371 | + $object_ids = $wpdb->get_col($wpdb->prepare("SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key)); |
|
372 | 372 | |
373 | 373 | /** |
374 | 374 | * Fires immediately before deleting metadata of a specific type. |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | * @param string $meta_key Meta key. |
384 | 384 | * @param mixed $meta_value Meta value. |
385 | 385 | */ |
386 | - do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
|
386 | + do_action("delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value); |
|
387 | 387 | |
388 | 388 | // Old-style action. |
389 | - if ( 'post' == $meta_type ) { |
|
389 | + if ('post' == $meta_type) { |
|
390 | 390 | /** |
391 | 391 | * Fires immediately before deleting metadata for a post. |
392 | 392 | * |
@@ -394,22 +394,22 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @param array $meta_ids An array of post metadata entry IDs to delete. |
396 | 396 | */ |
397 | - do_action( 'delete_postmeta', $meta_ids ); |
|
397 | + do_action('delete_postmeta', $meta_ids); |
|
398 | 398 | } |
399 | 399 | |
400 | - $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; |
|
400 | + $query = "DELETE FROM $table WHERE $id_column IN( ".implode(',', $meta_ids)." )"; |
|
401 | 401 | |
402 | 402 | $count = $wpdb->query($query); |
403 | 403 | |
404 | - if ( !$count ) |
|
404 | + if ( ! $count) |
|
405 | 405 | return false; |
406 | 406 | |
407 | - if ( $delete_all ) { |
|
408 | - foreach ( (array) $object_ids as $o_id ) { |
|
409 | - wp_cache_delete($o_id, $meta_type . '_meta'); |
|
407 | + if ($delete_all) { |
|
408 | + foreach ((array) $object_ids as $o_id) { |
|
409 | + wp_cache_delete($o_id, $meta_type.'_meta'); |
|
410 | 410 | } |
411 | 411 | } else { |
412 | - wp_cache_delete($object_id, $meta_type . '_meta'); |
|
412 | + wp_cache_delete($object_id, $meta_type.'_meta'); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -425,10 +425,10 @@ discard block |
||
425 | 425 | * @param string $meta_key Meta key. |
426 | 426 | * @param mixed $meta_value Meta value. |
427 | 427 | */ |
428 | - do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
|
428 | + do_action("deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value); |
|
429 | 429 | |
430 | 430 | // Old-style action. |
431 | - if ( 'post' == $meta_type ) { |
|
431 | + if ('post' == $meta_type) { |
|
432 | 432 | /** |
433 | 433 | * Fires immediately after deleting metadata for a post. |
434 | 434 | * |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @param array $meta_ids An array of deleted post metadata entry IDs. |
438 | 438 | */ |
439 | - do_action( 'deleted_postmeta', $meta_ids ); |
|
439 | + do_action('deleted_postmeta', $meta_ids); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | return true; |
@@ -457,12 +457,12 @@ discard block |
||
457 | 457 | * @return mixed Single metadata value, or array of values |
458 | 458 | */ |
459 | 459 | function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { |
460 | - if ( ! $meta_type || ! is_numeric( $object_id ) ) { |
|
460 | + if ( ! $meta_type || ! is_numeric($object_id)) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
464 | - $object_id = absint( $object_id ); |
|
465 | - if ( ! $object_id ) { |
|
464 | + $object_id = absint($object_id); |
|
465 | + if ( ! $object_id) { |
|
466 | 466 | return false; |
467 | 467 | } |
468 | 468 | |
@@ -481,28 +481,28 @@ discard block |
||
481 | 481 | * @param string $meta_key Meta key. |
482 | 482 | * @param bool $single Whether to return only the first value of the specified $meta_key. |
483 | 483 | */ |
484 | - $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); |
|
485 | - if ( null !== $check ) { |
|
486 | - if ( $single && is_array( $check ) ) |
|
484 | + $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single); |
|
485 | + if (null !== $check) { |
|
486 | + if ($single && is_array($check)) |
|
487 | 487 | return $check[0]; |
488 | 488 | else |
489 | 489 | return $check; |
490 | 490 | } |
491 | 491 | |
492 | - $meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); |
|
492 | + $meta_cache = wp_cache_get($object_id, $meta_type.'_meta'); |
|
493 | 493 | |
494 | - if ( !$meta_cache ) { |
|
495 | - $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); |
|
494 | + if ( ! $meta_cache) { |
|
495 | + $meta_cache = update_meta_cache($meta_type, array($object_id)); |
|
496 | 496 | $meta_cache = $meta_cache[$object_id]; |
497 | 497 | } |
498 | 498 | |
499 | - if ( ! $meta_key ) { |
|
499 | + if ( ! $meta_key) { |
|
500 | 500 | return $meta_cache; |
501 | 501 | } |
502 | 502 | |
503 | - if ( isset($meta_cache[$meta_key]) ) { |
|
504 | - if ( $single ) |
|
505 | - return maybe_unserialize( $meta_cache[$meta_key][0] ); |
|
503 | + if (isset($meta_cache[$meta_key])) { |
|
504 | + if ($single) |
|
505 | + return maybe_unserialize($meta_cache[$meta_key][0]); |
|
506 | 506 | else |
507 | 507 | return array_map('maybe_unserialize', $meta_cache[$meta_key]); |
508 | 508 | } |
@@ -523,29 +523,29 @@ discard block |
||
523 | 523 | * @param string $meta_key Metadata key. |
524 | 524 | * @return bool True of the key is set, false if not. |
525 | 525 | */ |
526 | -function metadata_exists( $meta_type, $object_id, $meta_key ) { |
|
527 | - if ( ! $meta_type || ! is_numeric( $object_id ) ) { |
|
526 | +function metadata_exists($meta_type, $object_id, $meta_key) { |
|
527 | + if ( ! $meta_type || ! is_numeric($object_id)) { |
|
528 | 528 | return false; |
529 | 529 | } |
530 | 530 | |
531 | - $object_id = absint( $object_id ); |
|
532 | - if ( ! $object_id ) { |
|
531 | + $object_id = absint($object_id); |
|
532 | + if ( ! $object_id) { |
|
533 | 533 | return false; |
534 | 534 | } |
535 | 535 | |
536 | 536 | /** This filter is documented in wp-includes/meta.php */ |
537 | - $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); |
|
538 | - if ( null !== $check ) |
|
537 | + $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, true); |
|
538 | + if (null !== $check) |
|
539 | 539 | return (bool) $check; |
540 | 540 | |
541 | - $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); |
|
541 | + $meta_cache = wp_cache_get($object_id, $meta_type.'_meta'); |
|
542 | 542 | |
543 | - if ( !$meta_cache ) { |
|
544 | - $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); |
|
543 | + if ( ! $meta_cache) { |
|
544 | + $meta_cache = update_meta_cache($meta_type, array($object_id)); |
|
545 | 545 | $meta_cache = $meta_cache[$object_id]; |
546 | 546 | } |
547 | 547 | |
548 | - if ( isset( $meta_cache[ $meta_key ] ) ) |
|
548 | + if (isset($meta_cache[$meta_key])) |
|
549 | 549 | return true; |
550 | 550 | |
551 | 551 | return false; |
@@ -562,32 +562,32 @@ discard block |
||
562 | 562 | * @param int $meta_id ID for a specific meta row |
563 | 563 | * @return object|false Meta object or false. |
564 | 564 | */ |
565 | -function get_metadata_by_mid( $meta_type, $meta_id ) { |
|
565 | +function get_metadata_by_mid($meta_type, $meta_id) { |
|
566 | 566 | global $wpdb; |
567 | 567 | |
568 | - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { |
|
568 | + if ( ! $meta_type || ! is_numeric($meta_id)) { |
|
569 | 569 | return false; |
570 | 570 | } |
571 | 571 | |
572 | - $meta_id = absint( $meta_id ); |
|
573 | - if ( ! $meta_id ) { |
|
572 | + $meta_id = absint($meta_id); |
|
573 | + if ( ! $meta_id) { |
|
574 | 574 | return false; |
575 | 575 | } |
576 | 576 | |
577 | - $table = _get_meta_table( $meta_type ); |
|
578 | - if ( ! $table ) { |
|
577 | + $table = _get_meta_table($meta_type); |
|
578 | + if ( ! $table) { |
|
579 | 579 | return false; |
580 | 580 | } |
581 | 581 | |
582 | - $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; |
|
582 | + $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id'; |
|
583 | 583 | |
584 | - $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); |
|
584 | + $meta = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE $id_column = %d", $meta_id)); |
|
585 | 585 | |
586 | - if ( empty( $meta ) ) |
|
586 | + if (empty($meta)) |
|
587 | 587 | return false; |
588 | 588 | |
589 | - if ( isset( $meta->meta_value ) ) |
|
590 | - $meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|
589 | + if (isset($meta->meta_value)) |
|
590 | + $meta->meta_value = maybe_unserialize($meta->meta_value); |
|
591 | 591 | |
592 | 592 | return $meta; |
593 | 593 | } |
@@ -605,44 +605,44 @@ discard block |
||
605 | 605 | * @param string $meta_key Optional, you can provide a meta key to update it |
606 | 606 | * @return bool True on successful update, false on failure. |
607 | 607 | */ |
608 | -function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) { |
|
608 | +function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false) { |
|
609 | 609 | global $wpdb; |
610 | 610 | |
611 | 611 | // Make sure everything is valid. |
612 | - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { |
|
612 | + if ( ! $meta_type || ! is_numeric($meta_id)) { |
|
613 | 613 | return false; |
614 | 614 | } |
615 | 615 | |
616 | - $meta_id = absint( $meta_id ); |
|
617 | - if ( ! $meta_id ) { |
|
616 | + $meta_id = absint($meta_id); |
|
617 | + if ( ! $meta_id) { |
|
618 | 618 | return false; |
619 | 619 | } |
620 | 620 | |
621 | - $table = _get_meta_table( $meta_type ); |
|
622 | - if ( ! $table ) { |
|
621 | + $table = _get_meta_table($meta_type); |
|
622 | + if ( ! $table) { |
|
623 | 623 | return false; |
624 | 624 | } |
625 | 625 | |
626 | - $column = sanitize_key($meta_type . '_id'); |
|
626 | + $column = sanitize_key($meta_type.'_id'); |
|
627 | 627 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
628 | 628 | |
629 | 629 | // Fetch the meta and go on if it's found. |
630 | - if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { |
|
630 | + if ($meta = get_metadata_by_mid($meta_type, $meta_id)) { |
|
631 | 631 | $original_key = $meta->meta_key; |
632 | 632 | $object_id = $meta->{$column}; |
633 | 633 | |
634 | 634 | // If a new meta_key (last parameter) was specified, change the meta key, |
635 | 635 | // otherwise use the original key in the update statement. |
636 | - if ( false === $meta_key ) { |
|
636 | + if (false === $meta_key) { |
|
637 | 637 | $meta_key = $original_key; |
638 | - } elseif ( ! is_string( $meta_key ) ) { |
|
638 | + } elseif ( ! is_string($meta_key)) { |
|
639 | 639 | return false; |
640 | 640 | } |
641 | 641 | |
642 | 642 | // Sanitize the meta |
643 | 643 | $_meta_value = $meta_value; |
644 | - $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type ); |
|
645 | - $meta_value = maybe_serialize( $meta_value ); |
|
644 | + $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type); |
|
645 | + $meta_value = maybe_serialize($meta_value); |
|
646 | 646 | |
647 | 647 | // Format the data query arguments. |
648 | 648 | $data = array( |
@@ -655,27 +655,27 @@ discard block |
||
655 | 655 | $where[$id_column] = $meta_id; |
656 | 656 | |
657 | 657 | /** This action is documented in wp-includes/meta.php */ |
658 | - do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
658 | + do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value); |
|
659 | 659 | |
660 | - if ( 'post' == $meta_type ) { |
|
660 | + if ('post' == $meta_type) { |
|
661 | 661 | /** This action is documented in wp-includes/meta.php */ |
662 | - do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
662 | + do_action('update_postmeta', $meta_id, $object_id, $meta_key, $meta_value); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | // Run the update query, all fields in $data are %s, $where is a %d. |
666 | - $result = $wpdb->update( $table, $data, $where, '%s', '%d' ); |
|
667 | - if ( ! $result ) |
|
666 | + $result = $wpdb->update($table, $data, $where, '%s', '%d'); |
|
667 | + if ( ! $result) |
|
668 | 668 | return false; |
669 | 669 | |
670 | 670 | // Clear the caches. |
671 | - wp_cache_delete($object_id, $meta_type . '_meta'); |
|
671 | + wp_cache_delete($object_id, $meta_type.'_meta'); |
|
672 | 672 | |
673 | 673 | /** This action is documented in wp-includes/meta.php */ |
674 | - do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|
674 | + do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value); |
|
675 | 675 | |
676 | - if ( 'post' == $meta_type ) { |
|
676 | + if ('post' == $meta_type) { |
|
677 | 677 | /** This action is documented in wp-includes/meta.php */ |
678 | - do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|
678 | + do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | return true; |
@@ -696,37 +696,37 @@ discard block |
||
696 | 696 | * @param int $meta_id ID for a specific meta row |
697 | 697 | * @return bool True on successful delete, false on failure. |
698 | 698 | */ |
699 | -function delete_metadata_by_mid( $meta_type, $meta_id ) { |
|
699 | +function delete_metadata_by_mid($meta_type, $meta_id) { |
|
700 | 700 | global $wpdb; |
701 | 701 | |
702 | 702 | // Make sure everything is valid. |
703 | - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { |
|
703 | + if ( ! $meta_type || ! is_numeric($meta_id)) { |
|
704 | 704 | return false; |
705 | 705 | } |
706 | 706 | |
707 | - $meta_id = absint( $meta_id ); |
|
708 | - if ( ! $meta_id ) { |
|
707 | + $meta_id = absint($meta_id); |
|
708 | + if ( ! $meta_id) { |
|
709 | 709 | return false; |
710 | 710 | } |
711 | 711 | |
712 | - $table = _get_meta_table( $meta_type ); |
|
713 | - if ( ! $table ) { |
|
712 | + $table = _get_meta_table($meta_type); |
|
713 | + if ( ! $table) { |
|
714 | 714 | return false; |
715 | 715 | } |
716 | 716 | |
717 | 717 | // object and id columns |
718 | - $column = sanitize_key($meta_type . '_id'); |
|
718 | + $column = sanitize_key($meta_type.'_id'); |
|
719 | 719 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
720 | 720 | |
721 | 721 | // Fetch the meta and go on if it's found. |
722 | - if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { |
|
722 | + if ($meta = get_metadata_by_mid($meta_type, $meta_id)) { |
|
723 | 723 | $object_id = $meta->{$column}; |
724 | 724 | |
725 | 725 | /** This action is documented in wp-includes/meta.php */ |
726 | - do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
|
726 | + do_action("delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value); |
|
727 | 727 | |
728 | 728 | // Old-style action. |
729 | - if ( 'post' == $meta_type || 'comment' == $meta_type ) { |
|
729 | + if ('post' == $meta_type || 'comment' == $meta_type) { |
|
730 | 730 | /** |
731 | 731 | * Fires immediately before deleting post or comment metadata of a specific type. |
732 | 732 | * |
@@ -737,20 +737,20 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @param int $meta_id ID of the metadata entry to delete. |
739 | 739 | */ |
740 | - do_action( "delete_{$meta_type}meta", $meta_id ); |
|
740 | + do_action("delete_{$meta_type}meta", $meta_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | // Run the query, will return true if deleted, false otherwise |
744 | - $result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) ); |
|
744 | + $result = (bool) $wpdb->delete($table, array($id_column => $meta_id)); |
|
745 | 745 | |
746 | 746 | // Clear the caches. |
747 | - wp_cache_delete($object_id, $meta_type . '_meta'); |
|
747 | + wp_cache_delete($object_id, $meta_type.'_meta'); |
|
748 | 748 | |
749 | 749 | /** This action is documented in wp-includes/meta.php */ |
750 | - do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
|
750 | + do_action("deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value); |
|
751 | 751 | |
752 | 752 | // Old-style action. |
753 | - if ( 'post' == $meta_type || 'comment' == $meta_type ) { |
|
753 | + if ('post' == $meta_type || 'comment' == $meta_type) { |
|
754 | 754 | /** |
755 | 755 | * Fires immediately after deleting post or comment metadata of a specific type. |
756 | 756 | * |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | * |
762 | 762 | * @param int $meta_ids Deleted metadata entry ID. |
763 | 763 | */ |
764 | - do_action( "deleted_{$meta_type}meta", $meta_id ); |
|
764 | + do_action("deleted_{$meta_type}meta", $meta_id); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | return $result; |
@@ -786,53 +786,53 @@ discard block |
||
786 | 786 | function update_meta_cache($meta_type, $object_ids) { |
787 | 787 | global $wpdb; |
788 | 788 | |
789 | - if ( ! $meta_type || ! $object_ids ) { |
|
789 | + if ( ! $meta_type || ! $object_ids) { |
|
790 | 790 | return false; |
791 | 791 | } |
792 | 792 | |
793 | - $table = _get_meta_table( $meta_type ); |
|
794 | - if ( ! $table ) { |
|
793 | + $table = _get_meta_table($meta_type); |
|
794 | + if ( ! $table) { |
|
795 | 795 | return false; |
796 | 796 | } |
797 | 797 | |
798 | - $column = sanitize_key($meta_type . '_id'); |
|
798 | + $column = sanitize_key($meta_type.'_id'); |
|
799 | 799 | |
800 | - if ( !is_array($object_ids) ) { |
|
800 | + if ( ! is_array($object_ids)) { |
|
801 | 801 | $object_ids = preg_replace('|[^0-9,]|', '', $object_ids); |
802 | 802 | $object_ids = explode(',', $object_ids); |
803 | 803 | } |
804 | 804 | |
805 | 805 | $object_ids = array_map('intval', $object_ids); |
806 | 806 | |
807 | - $cache_key = $meta_type . '_meta'; |
|
807 | + $cache_key = $meta_type.'_meta'; |
|
808 | 808 | $ids = array(); |
809 | 809 | $cache = array(); |
810 | - foreach ( $object_ids as $id ) { |
|
811 | - $cached_object = wp_cache_get( $id, $cache_key ); |
|
812 | - if ( false === $cached_object ) |
|
810 | + foreach ($object_ids as $id) { |
|
811 | + $cached_object = wp_cache_get($id, $cache_key); |
|
812 | + if (false === $cached_object) |
|
813 | 813 | $ids[] = $id; |
814 | 814 | else |
815 | 815 | $cache[$id] = $cached_object; |
816 | 816 | } |
817 | 817 | |
818 | - if ( empty( $ids ) ) |
|
818 | + if (empty($ids)) |
|
819 | 819 | return $cache; |
820 | 820 | |
821 | 821 | // Get meta info |
822 | - $id_list = join( ',', $ids ); |
|
822 | + $id_list = join(',', $ids); |
|
823 | 823 | $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; |
824 | - $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A ); |
|
824 | + $meta_list = $wpdb->get_results("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A); |
|
825 | 825 | |
826 | - if ( !empty($meta_list) ) { |
|
827 | - foreach ( $meta_list as $metarow) { |
|
826 | + if ( ! empty($meta_list)) { |
|
827 | + foreach ($meta_list as $metarow) { |
|
828 | 828 | $mpid = intval($metarow[$column]); |
829 | 829 | $mkey = $metarow['meta_key']; |
830 | 830 | $mval = $metarow['meta_value']; |
831 | 831 | |
832 | 832 | // Force subkeys to be array type: |
833 | - if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) |
|
833 | + if ( ! isset($cache[$mpid]) || ! is_array($cache[$mpid])) |
|
834 | 834 | $cache[$mpid] = array(); |
835 | - if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) |
|
835 | + if ( ! isset($cache[$mpid][$mkey]) || ! is_array($cache[$mpid][$mkey])) |
|
836 | 836 | $cache[$mpid][$mkey] = array(); |
837 | 837 | |
838 | 838 | // Add a value to the current pid/key: |
@@ -840,10 +840,10 @@ discard block |
||
840 | 840 | } |
841 | 841 | } |
842 | 842 | |
843 | - foreach ( $ids as $id ) { |
|
844 | - if ( ! isset($cache[$id]) ) |
|
843 | + foreach ($ids as $id) { |
|
844 | + if ( ! isset($cache[$id])) |
|
845 | 845 | $cache[$id] = array(); |
846 | - wp_cache_add( $id, $cache[$id], $cache_key ); |
|
846 | + wp_cache_add($id, $cache[$id], $cache_key); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | return $cache; |
@@ -863,9 +863,9 @@ discard block |
||
863 | 863 | * @param object $context Optional. The main query object |
864 | 864 | * @return array Associative array of `JOIN` and `WHERE` SQL. |
865 | 865 | */ |
866 | -function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) { |
|
867 | - $meta_query_obj = new WP_Meta_Query( $meta_query ); |
|
868 | - return $meta_query_obj->get_sql( $type, $primary_table, $primary_id_column, $context ); |
|
866 | +function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null) { |
|
867 | + $meta_query_obj = new WP_Meta_Query($meta_query); |
|
868 | + return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -991,17 +991,17 @@ discard block |
||
991 | 991 | * } |
992 | 992 | * } |
993 | 993 | */ |
994 | - public function __construct( $meta_query = false ) { |
|
995 | - if ( !$meta_query ) |
|
994 | + public function __construct($meta_query = false) { |
|
995 | + if ( ! $meta_query) |
|
996 | 996 | return; |
997 | 997 | |
998 | - if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { |
|
998 | + if (isset($meta_query['relation']) && strtoupper($meta_query['relation']) == 'OR') { |
|
999 | 999 | $this->relation = 'OR'; |
1000 | 1000 | } else { |
1001 | 1001 | $this->relation = 'AND'; |
1002 | 1002 | } |
1003 | 1003 | |
1004 | - $this->queries = $this->sanitize_query( $meta_query ); |
|
1004 | + $this->queries = $this->sanitize_query($meta_query); |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | /** |
@@ -1015,44 +1015,44 @@ discard block |
||
1015 | 1015 | * @param array $queries Array of query clauses. |
1016 | 1016 | * @return array Sanitized array of query clauses. |
1017 | 1017 | */ |
1018 | - public function sanitize_query( $queries ) { |
|
1018 | + public function sanitize_query($queries) { |
|
1019 | 1019 | $clean_queries = array(); |
1020 | 1020 | |
1021 | - if ( ! is_array( $queries ) ) { |
|
1021 | + if ( ! is_array($queries)) { |
|
1022 | 1022 | return $clean_queries; |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - foreach ( $queries as $key => $query ) { |
|
1026 | - if ( 'relation' === $key ) { |
|
1025 | + foreach ($queries as $key => $query) { |
|
1026 | + if ('relation' === $key) { |
|
1027 | 1027 | $relation = $query; |
1028 | 1028 | |
1029 | - } elseif ( ! is_array( $query ) ) { |
|
1029 | + } elseif ( ! is_array($query)) { |
|
1030 | 1030 | continue; |
1031 | 1031 | |
1032 | 1032 | // First-order clause. |
1033 | - } elseif ( $this->is_first_order_clause( $query ) ) { |
|
1034 | - if ( isset( $query['value'] ) && array() === $query['value'] ) { |
|
1035 | - unset( $query['value'] ); |
|
1033 | + } elseif ($this->is_first_order_clause($query)) { |
|
1034 | + if (isset($query['value']) && array() === $query['value']) { |
|
1035 | + unset($query['value']); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | - $clean_queries[ $key ] = $query; |
|
1038 | + $clean_queries[$key] = $query; |
|
1039 | 1039 | |
1040 | 1040 | // Otherwise, it's a nested query, so we recurse. |
1041 | 1041 | } else { |
1042 | - $cleaned_query = $this->sanitize_query( $query ); |
|
1042 | + $cleaned_query = $this->sanitize_query($query); |
|
1043 | 1043 | |
1044 | - if ( ! empty( $cleaned_query ) ) { |
|
1045 | - $clean_queries[ $key ] = $cleaned_query; |
|
1044 | + if ( ! empty($cleaned_query)) { |
|
1045 | + $clean_queries[$key] = $cleaned_query; |
|
1046 | 1046 | } |
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - if ( empty( $clean_queries ) ) { |
|
1050 | + if (empty($clean_queries)) { |
|
1051 | 1051 | return $clean_queries; |
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | // Sanitize the 'relation' key provided in the query. |
1055 | - if ( isset( $relation ) && 'OR' === strtoupper( $relation ) ) { |
|
1055 | + if (isset($relation) && 'OR' === strtoupper($relation)) { |
|
1056 | 1056 | $clean_queries['relation'] = 'OR'; |
1057 | 1057 | $this->has_or_relation = true; |
1058 | 1058 | |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | * This value will not actually be used to join clauses, but it |
1062 | 1062 | * simplifies the logic around combining key-only queries. |
1063 | 1063 | */ |
1064 | - } elseif ( 1 === count( $clean_queries ) ) { |
|
1064 | + } elseif (1 === count($clean_queries)) { |
|
1065 | 1065 | $clean_queries['relation'] = 'OR'; |
1066 | 1066 | |
1067 | 1067 | // Default to AND. |
@@ -1084,8 +1084,8 @@ discard block |
||
1084 | 1084 | * @param array $query Meta query arguments. |
1085 | 1085 | * @return bool Whether the query clause is a first-order clause. |
1086 | 1086 | */ |
1087 | - protected function is_first_order_clause( $query ) { |
|
1088 | - return isset( $query['key'] ) || isset( $query['value'] ); |
|
1087 | + protected function is_first_order_clause($query) { |
|
1088 | + return isset($query['key']) || isset($query['value']); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | /** |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | * |
1097 | 1097 | * @param array $qv The query variables |
1098 | 1098 | */ |
1099 | - public function parse_query_vars( $qv ) { |
|
1099 | + public function parse_query_vars($qv) { |
|
1100 | 1100 | $meta_query = array(); |
1101 | 1101 | |
1102 | 1102 | /* |
@@ -1106,34 +1106,34 @@ discard block |
||
1106 | 1106 | * the rest of the meta_query). |
1107 | 1107 | */ |
1108 | 1108 | $primary_meta_query = array(); |
1109 | - foreach ( array( 'key', 'compare', 'type' ) as $key ) { |
|
1110 | - if ( ! empty( $qv[ "meta_$key" ] ) ) { |
|
1111 | - $primary_meta_query[ $key ] = $qv[ "meta_$key" ]; |
|
1109 | + foreach (array('key', 'compare', 'type') as $key) { |
|
1110 | + if ( ! empty($qv["meta_$key"])) { |
|
1111 | + $primary_meta_query[$key] = $qv["meta_$key"]; |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | // WP_Query sets 'meta_value' = '' by default. |
1116 | - if ( isset( $qv['meta_value'] ) && '' !== $qv['meta_value'] && ( ! is_array( $qv['meta_value'] ) || $qv['meta_value'] ) ) { |
|
1116 | + if (isset($qv['meta_value']) && '' !== $qv['meta_value'] && ( ! is_array($qv['meta_value']) || $qv['meta_value'])) { |
|
1117 | 1117 | $primary_meta_query['value'] = $qv['meta_value']; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - $existing_meta_query = isset( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ? $qv['meta_query'] : array(); |
|
1120 | + $existing_meta_query = isset($qv['meta_query']) && is_array($qv['meta_query']) ? $qv['meta_query'] : array(); |
|
1121 | 1121 | |
1122 | - if ( ! empty( $primary_meta_query ) && ! empty( $existing_meta_query ) ) { |
|
1122 | + if ( ! empty($primary_meta_query) && ! empty($existing_meta_query)) { |
|
1123 | 1123 | $meta_query = array( |
1124 | 1124 | 'relation' => 'AND', |
1125 | 1125 | $primary_meta_query, |
1126 | 1126 | $existing_meta_query, |
1127 | 1127 | ); |
1128 | - } elseif ( ! empty( $primary_meta_query ) ) { |
|
1128 | + } elseif ( ! empty($primary_meta_query)) { |
|
1129 | 1129 | $meta_query = array( |
1130 | 1130 | $primary_meta_query, |
1131 | 1131 | ); |
1132 | - } elseif ( ! empty( $existing_meta_query ) ) { |
|
1132 | + } elseif ( ! empty($existing_meta_query)) { |
|
1133 | 1133 | $meta_query = $existing_meta_query; |
1134 | 1134 | } |
1135 | 1135 | |
1136 | - $this->__construct( $meta_query ); |
|
1136 | + $this->__construct($meta_query); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | /** |
@@ -1145,16 +1145,16 @@ discard block |
||
1145 | 1145 | * @param string $type MySQL type to cast meta_value. |
1146 | 1146 | * @return string MySQL type. |
1147 | 1147 | */ |
1148 | - public function get_cast_for_type( $type = '' ) { |
|
1149 | - if ( empty( $type ) ) |
|
1148 | + public function get_cast_for_type($type = '') { |
|
1149 | + if (empty($type)) |
|
1150 | 1150 | return 'CHAR'; |
1151 | 1151 | |
1152 | - $meta_type = strtoupper( $type ); |
|
1152 | + $meta_type = strtoupper($type); |
|
1153 | 1153 | |
1154 | - if ( ! preg_match( '/^(?:BINARY|CHAR|DATE|DATETIME|SIGNED|UNSIGNED|TIME|NUMERIC(?:\(\d+(?:,\s?\d+)?\))?|DECIMAL(?:\(\d+(?:,\s?\d+)?\))?)$/', $meta_type ) ) |
|
1154 | + if ( ! preg_match('/^(?:BINARY|CHAR|DATE|DATETIME|SIGNED|UNSIGNED|TIME|NUMERIC(?:\(\d+(?:,\s?\d+)?\))?|DECIMAL(?:\(\d+(?:,\s?\d+)?\))?)$/', $meta_type)) |
|
1155 | 1155 | return 'CHAR'; |
1156 | 1156 | |
1157 | - if ( 'NUMERIC' == $meta_type ) |
|
1157 | + if ('NUMERIC' == $meta_type) |
|
1158 | 1158 | $meta_type = 'SIGNED'; |
1159 | 1159 | |
1160 | 1160 | return $meta_type; |
@@ -1177,13 +1177,13 @@ discard block |
||
1177 | 1177 | * @type string $where SQL fragment to append to the main WHERE clause. |
1178 | 1178 | * } |
1179 | 1179 | */ |
1180 | - public function get_sql( $type, $primary_table, $primary_id_column, $context = null ) { |
|
1181 | - if ( ! $meta_table = _get_meta_table( $type ) ) { |
|
1180 | + public function get_sql($type, $primary_table, $primary_id_column, $context = null) { |
|
1181 | + if ( ! $meta_table = _get_meta_table($type)) { |
|
1182 | 1182 | return false; |
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | $this->meta_table = $meta_table; |
1186 | - $this->meta_id_column = sanitize_key( $type . '_id' ); |
|
1186 | + $this->meta_id_column = sanitize_key($type.'_id'); |
|
1187 | 1187 | |
1188 | 1188 | $this->primary_table = $primary_table; |
1189 | 1189 | $this->primary_id_column = $primary_id_column; |
@@ -1194,8 +1194,8 @@ discard block |
||
1194 | 1194 | * If any JOINs are LEFT JOINs (as in the case of NOT EXISTS), then all JOINs should |
1195 | 1195 | * be LEFT. Otherwise posts with no metadata will be excluded from results. |
1196 | 1196 | */ |
1197 | - if ( false !== strpos( $sql['join'], 'LEFT JOIN' ) ) { |
|
1198 | - $sql['join'] = str_replace( 'INNER JOIN', 'LEFT JOIN', $sql['join'] ); |
|
1197 | + if (false !== strpos($sql['join'], 'LEFT JOIN')) { |
|
1198 | + $sql['join'] = str_replace('INNER JOIN', 'LEFT JOIN', $sql['join']); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | /** |
@@ -1214,7 +1214,7 @@ discard block |
||
1214 | 1214 | * @type object $context The main query object. |
1215 | 1215 | * } |
1216 | 1216 | */ |
1217 | - return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type, $primary_table, $primary_id_column, $context ) ); |
|
1217 | + return apply_filters_ref_array('get_meta_sql', array($sql, $this->queries, $type, $primary_table, $primary_id_column, $context)); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | /** |
@@ -1239,10 +1239,10 @@ discard block |
||
1239 | 1239 | * To keep $this->queries unaltered, pass a copy. |
1240 | 1240 | */ |
1241 | 1241 | $queries = $this->queries; |
1242 | - $sql = $this->get_sql_for_query( $queries ); |
|
1242 | + $sql = $this->get_sql_for_query($queries); |
|
1243 | 1243 | |
1244 | - if ( ! empty( $sql['where'] ) ) { |
|
1245 | - $sql['where'] = ' AND ' . $sql['where']; |
|
1244 | + if ( ! empty($sql['where'])) { |
|
1245 | + $sql['where'] = ' AND '.$sql['where']; |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | 1248 | return $sql; |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | * @type string $where SQL fragment to append to the main WHERE clause. |
1268 | 1268 | * } |
1269 | 1269 | */ |
1270 | - protected function get_sql_for_query( &$query, $depth = 0 ) { |
|
1270 | + protected function get_sql_for_query(&$query, $depth = 0) { |
|
1271 | 1271 | $sql_chunks = array( |
1272 | 1272 | 'join' => array(), |
1273 | 1273 | 'where' => array(), |
@@ -1279,32 +1279,32 @@ discard block |
||
1279 | 1279 | ); |
1280 | 1280 | |
1281 | 1281 | $indent = ''; |
1282 | - for ( $i = 0; $i < $depth; $i++ ) { |
|
1282 | + for ($i = 0; $i < $depth; $i++) { |
|
1283 | 1283 | $indent .= " "; |
1284 | 1284 | } |
1285 | 1285 | |
1286 | - foreach ( $query as $key => &$clause ) { |
|
1287 | - if ( 'relation' === $key ) { |
|
1286 | + foreach ($query as $key => &$clause) { |
|
1287 | + if ('relation' === $key) { |
|
1288 | 1288 | $relation = $query['relation']; |
1289 | - } elseif ( is_array( $clause ) ) { |
|
1289 | + } elseif (is_array($clause)) { |
|
1290 | 1290 | |
1291 | 1291 | // This is a first-order clause. |
1292 | - if ( $this->is_first_order_clause( $clause ) ) { |
|
1293 | - $clause_sql = $this->get_sql_for_clause( $clause, $query, $key ); |
|
1292 | + if ($this->is_first_order_clause($clause)) { |
|
1293 | + $clause_sql = $this->get_sql_for_clause($clause, $query, $key); |
|
1294 | 1294 | |
1295 | - $where_count = count( $clause_sql['where'] ); |
|
1296 | - if ( ! $where_count ) { |
|
1295 | + $where_count = count($clause_sql['where']); |
|
1296 | + if ( ! $where_count) { |
|
1297 | 1297 | $sql_chunks['where'][] = ''; |
1298 | - } elseif ( 1 === $where_count ) { |
|
1298 | + } elseif (1 === $where_count) { |
|
1299 | 1299 | $sql_chunks['where'][] = $clause_sql['where'][0]; |
1300 | 1300 | } else { |
1301 | - $sql_chunks['where'][] = '( ' . implode( ' AND ', $clause_sql['where'] ) . ' )'; |
|
1301 | + $sql_chunks['where'][] = '( '.implode(' AND ', $clause_sql['where']).' )'; |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | - $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] ); |
|
1304 | + $sql_chunks['join'] = array_merge($sql_chunks['join'], $clause_sql['join']); |
|
1305 | 1305 | // This is a subquery, so we recurse. |
1306 | 1306 | } else { |
1307 | - $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 ); |
|
1307 | + $clause_sql = $this->get_sql_for_query($clause, $depth + 1); |
|
1308 | 1308 | |
1309 | 1309 | $sql_chunks['where'][] = $clause_sql['where']; |
1310 | 1310 | $sql_chunks['join'][] = $clause_sql['join']; |
@@ -1313,21 +1313,21 @@ discard block |
||
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | // Filter to remove empties. |
1316 | - $sql_chunks['join'] = array_filter( $sql_chunks['join'] ); |
|
1317 | - $sql_chunks['where'] = array_filter( $sql_chunks['where'] ); |
|
1316 | + $sql_chunks['join'] = array_filter($sql_chunks['join']); |
|
1317 | + $sql_chunks['where'] = array_filter($sql_chunks['where']); |
|
1318 | 1318 | |
1319 | - if ( empty( $relation ) ) { |
|
1319 | + if (empty($relation)) { |
|
1320 | 1320 | $relation = 'AND'; |
1321 | 1321 | } |
1322 | 1322 | |
1323 | 1323 | // Filter duplicate JOIN clauses and combine into a single string. |
1324 | - if ( ! empty( $sql_chunks['join'] ) ) { |
|
1325 | - $sql['join'] = implode( ' ', array_unique( $sql_chunks['join'] ) ); |
|
1324 | + if ( ! empty($sql_chunks['join'])) { |
|
1325 | + $sql['join'] = implode(' ', array_unique($sql_chunks['join'])); |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | // Generate a single WHERE clause with proper brackets and indentation. |
1329 | - if ( ! empty( $sql_chunks['where'] ) ) { |
|
1330 | - $sql['where'] = '( ' . "\n " . $indent . implode( ' ' . "\n " . $indent . $relation . ' ' . "\n " . $indent, $sql_chunks['where'] ) . "\n" . $indent . ')'; |
|
1329 | + if ( ! empty($sql_chunks['where'])) { |
|
1330 | + $sql['where'] = '( '."\n ".$indent.implode(' '."\n ".$indent.$relation.' '."\n ".$indent, $sql_chunks['where'])."\n".$indent.')'; |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | return $sql; |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | * @type string $where SQL fragment to append to the main WHERE clause. |
1355 | 1355 | * } |
1356 | 1356 | */ |
1357 | - public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { |
|
1357 | + public function get_sql_for_clause(&$clause, $parent_query, $clause_key = '') { |
|
1358 | 1358 | global $wpdb; |
1359 | 1359 | |
1360 | 1360 | $sql_chunks = array( |
@@ -1362,20 +1362,20 @@ discard block |
||
1362 | 1362 | 'join' => array(), |
1363 | 1363 | ); |
1364 | 1364 | |
1365 | - if ( isset( $clause['compare'] ) ) { |
|
1366 | - $clause['compare'] = strtoupper( $clause['compare'] ); |
|
1365 | + if (isset($clause['compare'])) { |
|
1366 | + $clause['compare'] = strtoupper($clause['compare']); |
|
1367 | 1367 | } else { |
1368 | - $clause['compare'] = isset( $clause['value'] ) && is_array( $clause['value'] ) ? 'IN' : '='; |
|
1368 | + $clause['compare'] = isset($clause['value']) && is_array($clause['value']) ? 'IN' : '='; |
|
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if ( ! in_array( $clause['compare'], array( |
|
1371 | + if ( ! in_array($clause['compare'], array( |
|
1372 | 1372 | '=', '!=', '>', '>=', '<', '<=', |
1373 | 1373 | 'LIKE', 'NOT LIKE', |
1374 | 1374 | 'IN', 'NOT IN', |
1375 | 1375 | 'BETWEEN', 'NOT BETWEEN', |
1376 | 1376 | 'EXISTS', 'NOT EXISTS', |
1377 | 1377 | 'REGEXP', 'NOT REGEXP', 'RLIKE' |
1378 | - ) ) ) { |
|
1378 | + ))) { |
|
1379 | 1379 | $clause['compare'] = '='; |
1380 | 1380 | } |
1381 | 1381 | |
@@ -1385,16 +1385,16 @@ discard block |
||
1385 | 1385 | $join = ''; |
1386 | 1386 | |
1387 | 1387 | // We prefer to avoid joins if possible. Look for an existing join compatible with this clause. |
1388 | - $alias = $this->find_compatible_table_alias( $clause, $parent_query ); |
|
1389 | - if ( false === $alias ) { |
|
1390 | - $i = count( $this->table_aliases ); |
|
1391 | - $alias = $i ? 'mt' . $i : $this->meta_table; |
|
1388 | + $alias = $this->find_compatible_table_alias($clause, $parent_query); |
|
1389 | + if (false === $alias) { |
|
1390 | + $i = count($this->table_aliases); |
|
1391 | + $alias = $i ? 'mt'.$i : $this->meta_table; |
|
1392 | 1392 | |
1393 | 1393 | // JOIN clauses for NOT EXISTS have their own syntax. |
1394 | - if ( 'NOT EXISTS' === $meta_compare ) { |
|
1394 | + if ('NOT EXISTS' === $meta_compare) { |
|
1395 | 1395 | $join .= " LEFT JOIN $this->meta_table"; |
1396 | 1396 | $join .= $i ? " AS $alias" : ''; |
1397 | - $join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] ); |
|
1397 | + $join .= $wpdb->prepare(" ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key']); |
|
1398 | 1398 | |
1399 | 1399 | // All other JOIN clauses. |
1400 | 1400 | } else { |
@@ -1411,72 +1411,72 @@ discard block |
||
1411 | 1411 | $clause['alias'] = $alias; |
1412 | 1412 | |
1413 | 1413 | // Determine the data type. |
1414 | - $_meta_type = isset( $clause['type'] ) ? $clause['type'] : ''; |
|
1415 | - $meta_type = $this->get_cast_for_type( $_meta_type ); |
|
1414 | + $_meta_type = isset($clause['type']) ? $clause['type'] : ''; |
|
1415 | + $meta_type = $this->get_cast_for_type($_meta_type); |
|
1416 | 1416 | $clause['cast'] = $meta_type; |
1417 | 1417 | |
1418 | 1418 | // Fallback for clause keys is the table alias. |
1419 | - if ( ! $clause_key ) { |
|
1419 | + if ( ! $clause_key) { |
|
1420 | 1420 | $clause_key = $clause['alias']; |
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | // Ensure unique clause keys, so none are overwritten. |
1424 | 1424 | $iterator = 1; |
1425 | 1425 | $clause_key_base = $clause_key; |
1426 | - while ( isset( $this->clauses[ $clause_key ] ) ) { |
|
1427 | - $clause_key = $clause_key_base . '-' . $iterator; |
|
1426 | + while (isset($this->clauses[$clause_key])) { |
|
1427 | + $clause_key = $clause_key_base.'-'.$iterator; |
|
1428 | 1428 | $iterator++; |
1429 | 1429 | } |
1430 | 1430 | |
1431 | 1431 | // Store the clause in our flat array. |
1432 | - $this->clauses[ $clause_key ] =& $clause; |
|
1432 | + $this->clauses[$clause_key] = & $clause; |
|
1433 | 1433 | |
1434 | 1434 | // Next, build the WHERE clause. |
1435 | 1435 | |
1436 | 1436 | // meta_key. |
1437 | - if ( array_key_exists( 'key', $clause ) ) { |
|
1438 | - if ( 'NOT EXISTS' === $meta_compare ) { |
|
1439 | - $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; |
|
1437 | + if (array_key_exists('key', $clause)) { |
|
1438 | + if ('NOT EXISTS' === $meta_compare) { |
|
1439 | + $sql_chunks['where'][] = $alias.'.'.$this->meta_id_column.' IS NULL'; |
|
1440 | 1440 | } else { |
1441 | - $sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) ); |
|
1441 | + $sql_chunks['where'][] = $wpdb->prepare("$alias.meta_key = %s", trim($clause['key'])); |
|
1442 | 1442 | } |
1443 | 1443 | } |
1444 | 1444 | |
1445 | 1445 | // meta_value. |
1446 | - if ( array_key_exists( 'value', $clause ) ) { |
|
1446 | + if (array_key_exists('value', $clause)) { |
|
1447 | 1447 | $meta_value = $clause['value']; |
1448 | 1448 | |
1449 | - if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { |
|
1450 | - if ( ! is_array( $meta_value ) ) { |
|
1451 | - $meta_value = preg_split( '/[,\s]+/', $meta_value ); |
|
1449 | + if (in_array($meta_compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) { |
|
1450 | + if ( ! is_array($meta_value)) { |
|
1451 | + $meta_value = preg_split('/[,\s]+/', $meta_value); |
|
1452 | 1452 | } |
1453 | 1453 | } else { |
1454 | - $meta_value = trim( $meta_value ); |
|
1454 | + $meta_value = trim($meta_value); |
|
1455 | 1455 | } |
1456 | 1456 | |
1457 | - switch ( $meta_compare ) { |
|
1457 | + switch ($meta_compare) { |
|
1458 | 1458 | case 'IN' : |
1459 | 1459 | case 'NOT IN' : |
1460 | - $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')'; |
|
1461 | - $where = $wpdb->prepare( $meta_compare_string, $meta_value ); |
|
1460 | + $meta_compare_string = '('.substr(str_repeat(',%s', count($meta_value)), 1).')'; |
|
1461 | + $where = $wpdb->prepare($meta_compare_string, $meta_value); |
|
1462 | 1462 | break; |
1463 | 1463 | |
1464 | 1464 | case 'BETWEEN' : |
1465 | 1465 | case 'NOT BETWEEN' : |
1466 | - $meta_value = array_slice( $meta_value, 0, 2 ); |
|
1467 | - $where = $wpdb->prepare( '%s AND %s', $meta_value ); |
|
1466 | + $meta_value = array_slice($meta_value, 0, 2); |
|
1467 | + $where = $wpdb->prepare('%s AND %s', $meta_value); |
|
1468 | 1468 | break; |
1469 | 1469 | |
1470 | 1470 | case 'LIKE' : |
1471 | 1471 | case 'NOT LIKE' : |
1472 | - $meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%'; |
|
1473 | - $where = $wpdb->prepare( '%s', $meta_value ); |
|
1472 | + $meta_value = '%'.$wpdb->esc_like($meta_value).'%'; |
|
1473 | + $where = $wpdb->prepare('%s', $meta_value); |
|
1474 | 1474 | break; |
1475 | 1475 | |
1476 | 1476 | // EXISTS with a value is interpreted as '='. |
1477 | 1477 | case 'EXISTS' : |
1478 | 1478 | $meta_compare = '='; |
1479 | - $where = $wpdb->prepare( '%s', $meta_value ); |
|
1479 | + $where = $wpdb->prepare('%s', $meta_value); |
|
1480 | 1480 | break; |
1481 | 1481 | |
1482 | 1482 | // 'value' is ignored for NOT EXISTS. |
@@ -1485,12 +1485,12 @@ discard block |
||
1485 | 1485 | break; |
1486 | 1486 | |
1487 | 1487 | default : |
1488 | - $where = $wpdb->prepare( '%s', $meta_value ); |
|
1488 | + $where = $wpdb->prepare('%s', $meta_value); |
|
1489 | 1489 | break; |
1490 | 1490 | |
1491 | 1491 | } |
1492 | 1492 | |
1493 | - if ( $where ) { |
|
1493 | + if ($where) { |
|
1494 | 1494 | $sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}"; |
1495 | 1495 | } |
1496 | 1496 | } |
@@ -1499,8 +1499,8 @@ discard block |
||
1499 | 1499 | * Multiple WHERE clauses (for meta_key and meta_value) should |
1500 | 1500 | * be joined in parentheses. |
1501 | 1501 | */ |
1502 | - if ( 1 < count( $sql_chunks['where'] ) ) { |
|
1503 | - $sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' ); |
|
1502 | + if (1 < count($sql_chunks['where'])) { |
|
1503 | + $sql_chunks['where'] = array('( '.implode(' AND ', $sql_chunks['where']).' )'); |
|
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | return $sql_chunks; |
@@ -1542,34 +1542,34 @@ discard block |
||
1542 | 1542 | * @param array $parent_query Parent query of $clause. |
1543 | 1543 | * @return string|bool Table alias if found, otherwise false. |
1544 | 1544 | */ |
1545 | - protected function find_compatible_table_alias( $clause, $parent_query ) { |
|
1545 | + protected function find_compatible_table_alias($clause, $parent_query) { |
|
1546 | 1546 | $alias = false; |
1547 | 1547 | |
1548 | - foreach ( $parent_query as $sibling ) { |
|
1548 | + foreach ($parent_query as $sibling) { |
|
1549 | 1549 | // If the sibling has no alias yet, there's nothing to check. |
1550 | - if ( empty( $sibling['alias'] ) ) { |
|
1550 | + if (empty($sibling['alias'])) { |
|
1551 | 1551 | continue; |
1552 | 1552 | } |
1553 | 1553 | |
1554 | 1554 | // We're only interested in siblings that are first-order clauses. |
1555 | - if ( ! is_array( $sibling ) || ! $this->is_first_order_clause( $sibling ) ) { |
|
1555 | + if ( ! is_array($sibling) || ! $this->is_first_order_clause($sibling)) { |
|
1556 | 1556 | continue; |
1557 | 1557 | } |
1558 | 1558 | |
1559 | 1559 | $compatible_compares = array(); |
1560 | 1560 | |
1561 | 1561 | // Clauses connected by OR can share joins as long as they have "positive" operators. |
1562 | - if ( 'OR' === $parent_query['relation'] ) { |
|
1563 | - $compatible_compares = array( '=', 'IN', 'BETWEEN', 'LIKE', 'REGEXP', 'RLIKE', '>', '>=', '<', '<=' ); |
|
1562 | + if ('OR' === $parent_query['relation']) { |
|
1563 | + $compatible_compares = array('=', 'IN', 'BETWEEN', 'LIKE', 'REGEXP', 'RLIKE', '>', '>=', '<', '<='); |
|
1564 | 1564 | |
1565 | 1565 | // Clauses joined by AND with "negative" operators share a join only if they also share a key. |
1566 | - } elseif ( isset( $sibling['key'] ) && isset( $clause['key'] ) && $sibling['key'] === $clause['key'] ) { |
|
1567 | - $compatible_compares = array( '!=', 'NOT IN', 'NOT LIKE' ); |
|
1566 | + } elseif (isset($sibling['key']) && isset($clause['key']) && $sibling['key'] === $clause['key']) { |
|
1567 | + $compatible_compares = array('!=', 'NOT IN', 'NOT LIKE'); |
|
1568 | 1568 | } |
1569 | 1569 | |
1570 | - $clause_compare = strtoupper( $clause['compare'] ); |
|
1571 | - $sibling_compare = strtoupper( $sibling['compare'] ); |
|
1572 | - if ( in_array( $clause_compare, $compatible_compares ) && in_array( $sibling_compare, $compatible_compares ) ) { |
|
1570 | + $clause_compare = strtoupper($clause['compare']); |
|
1571 | + $sibling_compare = strtoupper($sibling['compare']); |
|
1572 | + if (in_array($clause_compare, $compatible_compares) && in_array($sibling_compare, $compatible_compares)) { |
|
1573 | 1573 | $alias = $sibling['alias']; |
1574 | 1574 | break; |
1575 | 1575 | } |
@@ -1585,7 +1585,7 @@ discard block |
||
1585 | 1585 | * @param array $parent_query Parent of $clause. |
1586 | 1586 | * @param object $this WP_Meta_Query object. |
1587 | 1587 | */ |
1588 | - return apply_filters( 'meta_query_find_compatible_table_alias', $alias, $clause, $parent_query, $this ) ; |
|
1588 | + return apply_filters('meta_query_find_compatible_table_alias', $alias, $clause, $parent_query, $this); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | /** |
@@ -1617,9 +1617,9 @@ discard block |
||
1617 | 1617 | function _get_meta_table($type) { |
1618 | 1618 | global $wpdb; |
1619 | 1619 | |
1620 | - $table_name = $type . 'meta'; |
|
1620 | + $table_name = $type.'meta'; |
|
1621 | 1621 | |
1622 | - if ( empty($wpdb->$table_name) ) |
|
1622 | + if (empty($wpdb->$table_name)) |
|
1623 | 1623 | return false; |
1624 | 1624 | |
1625 | 1625 | return $wpdb->$table_name; |
@@ -1634,8 +1634,8 @@ discard block |
||
1634 | 1634 | * @param string|null $meta_type |
1635 | 1635 | * @return bool True if the key is protected, false otherwise. |
1636 | 1636 | */ |
1637 | -function is_protected_meta( $meta_key, $meta_type = null ) { |
|
1638 | - $protected = ( '_' == $meta_key[0] ); |
|
1637 | +function is_protected_meta($meta_key, $meta_type = null) { |
|
1638 | + $protected = ('_' == $meta_key[0]); |
|
1639 | 1639 | |
1640 | 1640 | /** |
1641 | 1641 | * Filter whether a meta key is protected. |
@@ -1646,7 +1646,7 @@ discard block |
||
1646 | 1646 | * @param string $meta_key Meta key. |
1647 | 1647 | * @param string $meta_type Meta type. |
1648 | 1648 | */ |
1649 | - return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type ); |
|
1649 | + return apply_filters('is_protected_meta', $protected, $meta_key, $meta_type); |
|
1650 | 1650 | } |
1651 | 1651 | |
1652 | 1652 | /** |
@@ -1659,7 +1659,7 @@ discard block |
||
1659 | 1659 | * @param string $meta_type Type of meta |
1660 | 1660 | * @return mixed Sanitized $meta_value |
1661 | 1661 | */ |
1662 | -function sanitize_meta( $meta_key, $meta_value, $meta_type ) { |
|
1662 | +function sanitize_meta($meta_key, $meta_value, $meta_type) { |
|
1663 | 1663 | |
1664 | 1664 | /** |
1665 | 1665 | * Filter the sanitization of a specific meta key of a specific meta type. |
@@ -1675,7 +1675,7 @@ discard block |
||
1675 | 1675 | * @param string $meta_key Meta key. |
1676 | 1676 | * @param string $meta_type Meta type. |
1677 | 1677 | */ |
1678 | - return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type ); |
|
1678 | + return apply_filters("sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type); |
|
1679 | 1679 | } |
1680 | 1680 | |
1681 | 1681 | /** |
@@ -1688,17 +1688,17 @@ discard block |
||
1688 | 1688 | * @param string|array $sanitize_callback A function or method to call when sanitizing the value of $meta_key. |
1689 | 1689 | * @param string|array $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. |
1690 | 1690 | */ |
1691 | -function register_meta( $meta_type, $meta_key, $sanitize_callback, $auth_callback = null ) { |
|
1692 | - if ( is_callable( $sanitize_callback ) ) |
|
1693 | - add_filter( "sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3 ); |
|
1691 | +function register_meta($meta_type, $meta_key, $sanitize_callback, $auth_callback = null) { |
|
1692 | + if (is_callable($sanitize_callback)) |
|
1693 | + add_filter("sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3); |
|
1694 | 1694 | |
1695 | - if ( empty( $auth_callback ) ) { |
|
1696 | - if ( is_protected_meta( $meta_key, $meta_type ) ) |
|
1695 | + if (empty($auth_callback)) { |
|
1696 | + if (is_protected_meta($meta_key, $meta_type)) |
|
1697 | 1697 | $auth_callback = '__return_false'; |
1698 | 1698 | else |
1699 | 1699 | $auth_callback = '__return_true'; |
1700 | 1700 | } |
1701 | 1701 | |
1702 | - if ( is_callable( $auth_callback ) ) |
|
1703 | - add_filter( "auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6 ); |
|
1702 | + if (is_callable($auth_callback)) |
|
1703 | + add_filter("auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6); |
|
1704 | 1704 | } |
@@ -69,13 +69,15 @@ discard block |
||
69 | 69 | * for the object. Optional. Default false. |
70 | 70 | */ |
71 | 71 | $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique ); |
72 | - if ( null !== $check ) |
|
73 | - return $check; |
|
72 | + if ( null !== $check ) { |
|
73 | + return $check; |
|
74 | + } |
|
74 | 75 | |
75 | 76 | if ( $unique && $wpdb->get_var( $wpdb->prepare( |
76 | 77 | "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d", |
77 | - $meta_key, $object_id ) ) ) |
|
78 | - return false; |
|
78 | + $meta_key, $object_id ) ) ) { |
|
79 | + return false; |
|
80 | + } |
|
79 | 81 | |
80 | 82 | $_meta_value = $meta_value; |
81 | 83 | $meta_value = maybe_serialize( $meta_value ); |
@@ -100,8 +102,9 @@ discard block |
||
100 | 102 | 'meta_value' => $meta_value |
101 | 103 | ) ); |
102 | 104 | |
103 | - if ( ! $result ) |
|
104 | - return false; |
|
105 | + if ( ! $result ) { |
|
106 | + return false; |
|
107 | + } |
|
105 | 108 | |
106 | 109 | $mid = (int) $wpdb->insert_id; |
107 | 110 | |
@@ -185,15 +188,17 @@ discard block |
||
185 | 188 | * Otherwise, update all entries. |
186 | 189 | */ |
187 | 190 | $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value ); |
188 | - if ( null !== $check ) |
|
189 | - return (bool) $check; |
|
191 | + if ( null !== $check ) { |
|
192 | + return (bool) $check; |
|
193 | + } |
|
190 | 194 | |
191 | 195 | // Compare existing value to new value if no prev value given and the key exists only once. |
192 | 196 | if ( empty($prev_value) ) { |
193 | 197 | $old_value = get_metadata($meta_type, $object_id, $meta_key); |
194 | 198 | if ( count($old_value) == 1 ) { |
195 | - if ( $old_value[0] === $meta_value ) |
|
196 | - return false; |
|
199 | + if ( $old_value[0] === $meta_value ) { |
|
200 | + return false; |
|
201 | + } |
|
197 | 202 | } |
198 | 203 | } |
199 | 204 | |
@@ -247,8 +252,9 @@ discard block |
||
247 | 252 | } |
248 | 253 | |
249 | 254 | $result = $wpdb->update( $table, $data, $where ); |
250 | - if ( ! $result ) |
|
251 | - return false; |
|
255 | + if ( ! $result ) { |
|
256 | + return false; |
|
257 | + } |
|
252 | 258 | |
253 | 259 | wp_cache_delete($object_id, $meta_type . '_meta'); |
254 | 260 | |
@@ -349,26 +355,31 @@ discard block |
||
349 | 355 | * Default false. |
350 | 356 | */ |
351 | 357 | $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all ); |
352 | - if ( null !== $check ) |
|
353 | - return (bool) $check; |
|
358 | + if ( null !== $check ) { |
|
359 | + return (bool) $check; |
|
360 | + } |
|
354 | 361 | |
355 | 362 | $_meta_value = $meta_value; |
356 | 363 | $meta_value = maybe_serialize( $meta_value ); |
357 | 364 | |
358 | 365 | $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); |
359 | 366 | |
360 | - if ( !$delete_all ) |
|
361 | - $query .= $wpdb->prepare(" AND $type_column = %d", $object_id ); |
|
367 | + if ( !$delete_all ) { |
|
368 | + $query .= $wpdb->prepare(" AND $type_column = %d", $object_id ); |
|
369 | + } |
|
362 | 370 | |
363 | - if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) |
|
364 | - $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value ); |
|
371 | + if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) { |
|
372 | + $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value ); |
|
373 | + } |
|
365 | 374 | |
366 | 375 | $meta_ids = $wpdb->get_col( $query ); |
367 | - if ( !count( $meta_ids ) ) |
|
368 | - return false; |
|
376 | + if ( !count( $meta_ids ) ) { |
|
377 | + return false; |
|
378 | + } |
|
369 | 379 | |
370 | - if ( $delete_all ) |
|
371 | - $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); |
|
380 | + if ( $delete_all ) { |
|
381 | + $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); |
|
382 | + } |
|
372 | 383 | |
373 | 384 | /** |
374 | 385 | * Fires immediately before deleting metadata of a specific type. |
@@ -401,8 +412,9 @@ discard block |
||
401 | 412 | |
402 | 413 | $count = $wpdb->query($query); |
403 | 414 | |
404 | - if ( !$count ) |
|
405 | - return false; |
|
415 | + if ( !$count ) { |
|
416 | + return false; |
|
417 | + } |
|
406 | 418 | |
407 | 419 | if ( $delete_all ) { |
408 | 420 | foreach ( (array) $object_ids as $o_id ) { |
@@ -483,10 +495,11 @@ discard block |
||
483 | 495 | */ |
484 | 496 | $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); |
485 | 497 | if ( null !== $check ) { |
486 | - if ( $single && is_array( $check ) ) |
|
487 | - return $check[0]; |
|
488 | - else |
|
489 | - return $check; |
|
498 | + if ( $single && is_array( $check ) ) { |
|
499 | + return $check[0]; |
|
500 | + } else { |
|
501 | + return $check; |
|
502 | + } |
|
490 | 503 | } |
491 | 504 | |
492 | 505 | $meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); |
@@ -501,17 +514,19 @@ discard block |
||
501 | 514 | } |
502 | 515 | |
503 | 516 | if ( isset($meta_cache[$meta_key]) ) { |
504 | - if ( $single ) |
|
505 | - return maybe_unserialize( $meta_cache[$meta_key][0] ); |
|
506 | - else |
|
507 | - return array_map('maybe_unserialize', $meta_cache[$meta_key]); |
|
517 | + if ( $single ) { |
|
518 | + return maybe_unserialize( $meta_cache[$meta_key][0] ); |
|
519 | + } else { |
|
520 | + return array_map('maybe_unserialize', $meta_cache[$meta_key]); |
|
521 | + } |
|
508 | 522 | } |
509 | 523 | |
510 | - if ($single) |
|
511 | - return ''; |
|
512 | - else |
|
513 | - return array(); |
|
514 | -} |
|
524 | + if ($single) { |
|
525 | + return ''; |
|
526 | + } else { |
|
527 | + return array(); |
|
528 | + } |
|
529 | + } |
|
515 | 530 | |
516 | 531 | /** |
517 | 532 | * Determine if a meta key is set for a given object |
@@ -535,8 +550,9 @@ discard block |
||
535 | 550 | |
536 | 551 | /** This filter is documented in wp-includes/meta.php */ |
537 | 552 | $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); |
538 | - if ( null !== $check ) |
|
539 | - return (bool) $check; |
|
553 | + if ( null !== $check ) { |
|
554 | + return (bool) $check; |
|
555 | + } |
|
540 | 556 | |
541 | 557 | $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); |
542 | 558 | |
@@ -545,8 +561,9 @@ discard block |
||
545 | 561 | $meta_cache = $meta_cache[$object_id]; |
546 | 562 | } |
547 | 563 | |
548 | - if ( isset( $meta_cache[ $meta_key ] ) ) |
|
549 | - return true; |
|
564 | + if ( isset( $meta_cache[ $meta_key ] ) ) { |
|
565 | + return true; |
|
566 | + } |
|
550 | 567 | |
551 | 568 | return false; |
552 | 569 | } |
@@ -583,11 +600,13 @@ discard block |
||
583 | 600 | |
584 | 601 | $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); |
585 | 602 | |
586 | - if ( empty( $meta ) ) |
|
587 | - return false; |
|
603 | + if ( empty( $meta ) ) { |
|
604 | + return false; |
|
605 | + } |
|
588 | 606 | |
589 | - if ( isset( $meta->meta_value ) ) |
|
590 | - $meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|
607 | + if ( isset( $meta->meta_value ) ) { |
|
608 | + $meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|
609 | + } |
|
591 | 610 | |
592 | 611 | return $meta; |
593 | 612 | } |
@@ -664,8 +683,9 @@ discard block |
||
664 | 683 | |
665 | 684 | // Run the update query, all fields in $data are %s, $where is a %d. |
666 | 685 | $result = $wpdb->update( $table, $data, $where, '%s', '%d' ); |
667 | - if ( ! $result ) |
|
668 | - return false; |
|
686 | + if ( ! $result ) { |
|
687 | + return false; |
|
688 | + } |
|
669 | 689 | |
670 | 690 | // Clear the caches. |
671 | 691 | wp_cache_delete($object_id, $meta_type . '_meta'); |
@@ -809,14 +829,16 @@ discard block |
||
809 | 829 | $cache = array(); |
810 | 830 | foreach ( $object_ids as $id ) { |
811 | 831 | $cached_object = wp_cache_get( $id, $cache_key ); |
812 | - if ( false === $cached_object ) |
|
813 | - $ids[] = $id; |
|
814 | - else |
|
815 | - $cache[$id] = $cached_object; |
|
832 | + if ( false === $cached_object ) { |
|
833 | + $ids[] = $id; |
|
834 | + } else { |
|
835 | + $cache[$id] = $cached_object; |
|
836 | + } |
|
816 | 837 | } |
817 | 838 | |
818 | - if ( empty( $ids ) ) |
|
819 | - return $cache; |
|
839 | + if ( empty( $ids ) ) { |
|
840 | + return $cache; |
|
841 | + } |
|
820 | 842 | |
821 | 843 | // Get meta info |
822 | 844 | $id_list = join( ',', $ids ); |
@@ -830,10 +852,12 @@ discard block |
||
830 | 852 | $mval = $metarow['meta_value']; |
831 | 853 | |
832 | 854 | // Force subkeys to be array type: |
833 | - if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) |
|
834 | - $cache[$mpid] = array(); |
|
835 | - if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) |
|
836 | - $cache[$mpid][$mkey] = array(); |
|
855 | + if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) { |
|
856 | + $cache[$mpid] = array(); |
|
857 | + } |
|
858 | + if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) { |
|
859 | + $cache[$mpid][$mkey] = array(); |
|
860 | + } |
|
837 | 861 | |
838 | 862 | // Add a value to the current pid/key: |
839 | 863 | $cache[$mpid][$mkey][] = $mval; |
@@ -841,8 +865,9 @@ discard block |
||
841 | 865 | } |
842 | 866 | |
843 | 867 | foreach ( $ids as $id ) { |
844 | - if ( ! isset($cache[$id]) ) |
|
845 | - $cache[$id] = array(); |
|
868 | + if ( ! isset($cache[$id]) ) { |
|
869 | + $cache[$id] = array(); |
|
870 | + } |
|
846 | 871 | wp_cache_add( $id, $cache[$id], $cache_key ); |
847 | 872 | } |
848 | 873 | |
@@ -992,8 +1017,9 @@ discard block |
||
992 | 1017 | * } |
993 | 1018 | */ |
994 | 1019 | public function __construct( $meta_query = false ) { |
995 | - if ( !$meta_query ) |
|
996 | - return; |
|
1020 | + if ( !$meta_query ) { |
|
1021 | + return; |
|
1022 | + } |
|
997 | 1023 | |
998 | 1024 | if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { |
999 | 1025 | $this->relation = 'OR'; |
@@ -1146,16 +1172,19 @@ discard block |
||
1146 | 1172 | * @return string MySQL type. |
1147 | 1173 | */ |
1148 | 1174 | public function get_cast_for_type( $type = '' ) { |
1149 | - if ( empty( $type ) ) |
|
1150 | - return 'CHAR'; |
|
1175 | + if ( empty( $type ) ) { |
|
1176 | + return 'CHAR'; |
|
1177 | + } |
|
1151 | 1178 | |
1152 | 1179 | $meta_type = strtoupper( $type ); |
1153 | 1180 | |
1154 | - if ( ! preg_match( '/^(?:BINARY|CHAR|DATE|DATETIME|SIGNED|UNSIGNED|TIME|NUMERIC(?:\(\d+(?:,\s?\d+)?\))?|DECIMAL(?:\(\d+(?:,\s?\d+)?\))?)$/', $meta_type ) ) |
|
1155 | - return 'CHAR'; |
|
1181 | + if ( ! preg_match( '/^(?:BINARY|CHAR|DATE|DATETIME|SIGNED|UNSIGNED|TIME|NUMERIC(?:\(\d+(?:,\s?\d+)?\))?|DECIMAL(?:\(\d+(?:,\s?\d+)?\))?)$/', $meta_type ) ) { |
|
1182 | + return 'CHAR'; |
|
1183 | + } |
|
1156 | 1184 | |
1157 | - if ( 'NUMERIC' == $meta_type ) |
|
1158 | - $meta_type = 'SIGNED'; |
|
1185 | + if ( 'NUMERIC' == $meta_type ) { |
|
1186 | + $meta_type = 'SIGNED'; |
|
1187 | + } |
|
1159 | 1188 | |
1160 | 1189 | return $meta_type; |
1161 | 1190 | } |
@@ -1619,8 +1648,9 @@ discard block |
||
1619 | 1648 | |
1620 | 1649 | $table_name = $type . 'meta'; |
1621 | 1650 | |
1622 | - if ( empty($wpdb->$table_name) ) |
|
1623 | - return false; |
|
1651 | + if ( empty($wpdb->$table_name) ) { |
|
1652 | + return false; |
|
1653 | + } |
|
1624 | 1654 | |
1625 | 1655 | return $wpdb->$table_name; |
1626 | 1656 | } |
@@ -1689,16 +1719,19 @@ discard block |
||
1689 | 1719 | * @param string|array $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. |
1690 | 1720 | */ |
1691 | 1721 | function register_meta( $meta_type, $meta_key, $sanitize_callback, $auth_callback = null ) { |
1692 | - if ( is_callable( $sanitize_callback ) ) |
|
1693 | - add_filter( "sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3 ); |
|
1722 | + if ( is_callable( $sanitize_callback ) ) { |
|
1723 | + add_filter( "sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3 ); |
|
1724 | + } |
|
1694 | 1725 | |
1695 | 1726 | if ( empty( $auth_callback ) ) { |
1696 | - if ( is_protected_meta( $meta_key, $meta_type ) ) |
|
1697 | - $auth_callback = '__return_false'; |
|
1698 | - else |
|
1699 | - $auth_callback = '__return_true'; |
|
1727 | + if ( is_protected_meta( $meta_key, $meta_type ) ) { |
|
1728 | + $auth_callback = '__return_false'; |
|
1729 | + } else { |
|
1730 | + $auth_callback = '__return_true'; |
|
1731 | + } |
|
1700 | 1732 | } |
1701 | 1733 | |
1702 | - if ( is_callable( $auth_callback ) ) |
|
1703 | - add_filter( "auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6 ); |
|
1704 | -} |
|
1734 | + if ( is_callable( $auth_callback ) ) { |
|
1735 | + add_filter( "auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6 ); |
|
1736 | + } |
|
1737 | + } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Deprecated. No longer needed. |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - */ |
|
3 | + * Deprecated. No longer needed. |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + */ |
|
7 | 7 | _deprecated_file( basename(__FILE__), '3.1', null, __( 'This file no longer needs to be included.' ) ); |
@@ -4,4 +4,4 @@ |
||
4 | 4 | * |
5 | 5 | * @package WordPress |
6 | 6 | */ |
7 | -_deprecated_file( basename(__FILE__), '3.1', null, __( 'This file no longer needs to be included.' ) ); |
|
7 | +_deprecated_file(basename(__FILE__), '3.1', null, __('This file no longer needs to be included.')); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( !class_exists('SimplePie') ) |
|
4 | - require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
|
3 | +if ( ! class_exists('SimplePie')) |
|
4 | + require_once(ABSPATH.WPINC.'/class-simplepie.php'); |
|
5 | 5 | |
6 | 6 | class WP_Feed_Cache extends SimplePie_Cache { |
7 | 7 | /** |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | public $lifetime = 43200; //Default lifetime in cache of 12 hours |
22 | 22 | |
23 | 23 | public function __construct($location, $filename, $extension) { |
24 | - $this->name = 'feed_' . $filename; |
|
25 | - $this->mod_name = 'feed_mod_' . $filename; |
|
24 | + $this->name = 'feed_'.$filename; |
|
25 | + $this->mod_name = 'feed_mod_'.$filename; |
|
26 | 26 | |
27 | 27 | $lifetime = $this->lifetime; |
28 | 28 | /** |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). |
34 | 34 | * @param string $filename Unique identifier for the cache object. |
35 | 35 | */ |
36 | - $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename); |
|
36 | + $this->lifetime = apply_filters('wp_feed_cache_transient_lifetime', $lifetime, $filename); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @access public |
41 | 41 | */ |
42 | 42 | public function save($data) { |
43 | - if ( $data instanceof SimplePie ) { |
|
43 | + if ($data instanceof SimplePie) { |
|
44 | 44 | $data = $data->data; |
45 | 45 | } |
46 | 46 | |
@@ -91,27 +91,27 @@ discard block |
||
91 | 91 | |
92 | 92 | $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; |
93 | 93 | |
94 | - if ( preg_match('/^http(s)?:\/\//i', $url) ) { |
|
94 | + if (preg_match('/^http(s)?:\/\//i', $url)) { |
|
95 | 95 | $args = array( |
96 | 96 | 'timeout' => $this->timeout, |
97 | 97 | 'redirection' => $this->redirects, |
98 | 98 | ); |
99 | 99 | |
100 | - if ( !empty($this->headers) ) |
|
100 | + if ( ! empty($this->headers)) |
|
101 | 101 | $args['headers'] = $this->headers; |
102 | 102 | |
103 | - if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified |
|
103 | + if (SIMPLEPIE_USERAGENT != $this->useragent) //Use default WP user agent unless custom has been specified |
|
104 | 104 | $args['user-agent'] = $this->useragent; |
105 | 105 | |
106 | 106 | $res = wp_safe_remote_request($url, $args); |
107 | 107 | |
108 | - if ( is_wp_error($res) ) { |
|
109 | - $this->error = 'WP HTTP Error: ' . $res->get_error_message(); |
|
108 | + if (is_wp_error($res)) { |
|
109 | + $this->error = 'WP HTTP Error: '.$res->get_error_message(); |
|
110 | 110 | $this->success = false; |
111 | 111 | } else { |
112 | - $this->headers = wp_remote_retrieve_headers( $res ); |
|
113 | - $this->body = wp_remote_retrieve_body( $res ); |
|
114 | - $this->status_code = wp_remote_retrieve_response_code( $res ); |
|
112 | + $this->headers = wp_remote_retrieve_headers($res); |
|
113 | + $this->body = wp_remote_retrieve_body($res); |
|
114 | + $this->status_code = wp_remote_retrieve_response_code($res); |
|
115 | 115 | } |
116 | 116 | } else { |
117 | 117 | $this->error = ''; |
@@ -130,27 +130,27 @@ discard block |
||
130 | 130 | * @since 3.5.0 |
131 | 131 | */ |
132 | 132 | class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize { |
133 | - public function sanitize( $data, $type, $base = '' ) { |
|
134 | - $data = trim( $data ); |
|
135 | - if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) { |
|
136 | - if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) { |
|
133 | + public function sanitize($data, $type, $base = '') { |
|
134 | + $data = trim($data); |
|
135 | + if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) { |
|
136 | + if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*'.SIMPLEPIE_PCRE_HTML_ATTRIBUTE.'>)/', $data)) { |
|
137 | 137 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
138 | 138 | } |
139 | 139 | else { |
140 | 140 | $type |= SIMPLEPIE_CONSTRUCT_TEXT; |
141 | 141 | } |
142 | 142 | } |
143 | - if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) { |
|
144 | - $data = base64_decode( $data ); |
|
143 | + if ($type & SIMPLEPIE_CONSTRUCT_BASE64) { |
|
144 | + $data = base64_decode($data); |
|
145 | 145 | } |
146 | - if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) { |
|
147 | - $data = wp_kses_post( $data ); |
|
148 | - if ( $this->output_encoding !== 'UTF-8' ) { |
|
149 | - $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) ); |
|
146 | + if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) { |
|
147 | + $data = wp_kses_post($data); |
|
148 | + if ($this->output_encoding !== 'UTF-8') { |
|
149 | + $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding)); |
|
150 | 150 | } |
151 | 151 | return $data; |
152 | 152 | } else { |
153 | - return parent::sanitize( $data, $type, $base ); |
|
153 | + return parent::sanitize($data, $type, $base); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( !class_exists('SimplePie') ) |
|
3 | +if ( !class_exists('SimplePie') ) { |
|
4 | 4 | require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
5 | +} |
|
5 | 6 | |
6 | 7 | class WP_Feed_Cache extends SimplePie_Cache { |
7 | 8 | /** |
@@ -97,11 +98,14 @@ discard block |
||
97 | 98 | 'redirection' => $this->redirects, |
98 | 99 | ); |
99 | 100 | |
100 | - if ( !empty($this->headers) ) |
|
101 | - $args['headers'] = $this->headers; |
|
101 | + if ( !empty($this->headers) ) { |
|
102 | + $args['headers'] = $this->headers; |
|
103 | + } |
|
102 | 104 | |
103 | - if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified |
|
105 | + if ( SIMPLEPIE_USERAGENT != $this->useragent ) { |
|
106 | + //Use default WP user agent unless custom has been specified |
|
104 | 107 | $args['user-agent'] = $this->useragent; |
108 | + } |
|
105 | 109 | |
106 | 110 | $res = wp_safe_remote_request($url, $args); |
107 | 111 | |
@@ -135,8 +139,7 @@ discard block |
||
135 | 139 | if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) { |
136 | 140 | if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) { |
137 | 141 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
138 | - } |
|
139 | - else { |
|
142 | + } else { |
|
140 | 143 | $type |= SIMPLEPIE_CONSTRUCT_TEXT; |
141 | 144 | } |
142 | 145 | } |