@@ -25,8 +25,8 @@ |
||
25 | 25 | */ |
26 | 26 | public function _splitOnWords($string, $newlineEscape = "\n") { |
27 | 27 | $string = str_replace("\0", '', $string); |
28 | - $words = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
29 | - $words = str_replace( "\n", $newlineEscape, $words ); |
|
28 | + $words = preg_split('/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
29 | + $words = str_replace("\n", $newlineEscape, $words); |
|
30 | 30 | return $words; |
31 | 31 | } |
32 | 32 |
@@ -166,27 +166,27 @@ discard block |
||
166 | 166 | * @param int $site_id The ID of the site to retrieve. |
167 | 167 | * @return WP_Site|false The site's object if found. False if not. |
168 | 168 | */ |
169 | - public static function get_instance( $site_id ) { |
|
169 | + public static function get_instance($site_id) { |
|
170 | 170 | global $wpdb; |
171 | 171 | |
172 | 172 | $site_id = (int) $site_id; |
173 | - if ( ! $site_id ) { |
|
173 | + if ( ! $site_id) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
177 | - $_site = wp_cache_get( $site_id, 'sites' ); |
|
177 | + $_site = wp_cache_get($site_id, 'sites'); |
|
178 | 178 | |
179 | - if ( ! $_site ) { |
|
180 | - $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) ); |
|
179 | + if ( ! $_site) { |
|
180 | + $_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id)); |
|
181 | 181 | |
182 | - if ( empty( $_site ) || is_wp_error( $_site ) ) { |
|
182 | + if (empty($_site) || is_wp_error($_site)) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
186 | - wp_cache_add( $site_id, $_site, 'sites' ); |
|
186 | + wp_cache_add($site_id, $_site, 'sites'); |
|
187 | 187 | } |
188 | 188 | |
189 | - return new WP_Site( $_site ); |
|
189 | + return new WP_Site($_site); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param WP_Site|object $site A site object. |
202 | 202 | */ |
203 | - public function __construct( $site ) { |
|
204 | - foreach( get_object_vars( $site ) as $key => $value ) { |
|
203 | + public function __construct($site) { |
|
204 | + foreach (get_object_vars($site) as $key => $value) { |
|
205 | 205 | $this->$key = $value; |
206 | 206 | } |
207 | 207 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return array Object as array. |
216 | 216 | */ |
217 | 217 | public function to_array() { |
218 | - return get_object_vars( $this ); |
|
218 | + return get_object_vars($this); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @param string $key Property to get. |
231 | 231 | * @return mixed Value of the property. Null if not available. |
232 | 232 | */ |
233 | - public function __get( $key ) { |
|
234 | - switch ( $key ) { |
|
233 | + public function __get($key) { |
|
234 | + switch ($key) { |
|
235 | 235 | case 'id': |
236 | 236 | return (int) $this->blog_id; |
237 | 237 | case 'network_id': |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | case 'siteurl': |
241 | 241 | case 'post_count': |
242 | 242 | case 'home': |
243 | - if ( ! did_action( 'ms_loaded' ) ) { |
|
243 | + if ( ! did_action('ms_loaded')) { |
|
244 | 244 | return null; |
245 | 245 | } |
246 | 246 | $details = $this->get_details(); |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * @param string $key Property to check if set. |
263 | 263 | * @return bool Whether the property is set. |
264 | 264 | */ |
265 | - public function __isset( $key ) { |
|
266 | - switch ( $key ) { |
|
265 | + public function __isset($key) { |
|
266 | + switch ($key) { |
|
267 | 267 | case 'id': |
268 | 268 | case 'network_id': |
269 | 269 | return true; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | case 'siteurl': |
272 | 272 | case 'post_count': |
273 | 273 | case 'home': |
274 | - if ( ! did_action( 'ms_loaded' ) ) { |
|
274 | + if ( ! did_action('ms_loaded')) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | return true; |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param string $key Property to set. |
292 | 292 | * @param mixed $value Value to assign to the property. |
293 | 293 | */ |
294 | - public function __set( $key, $value ) { |
|
295 | - switch ( $key ) { |
|
294 | + public function __set($key, $value) { |
|
295 | + switch ($key) { |
|
296 | 296 | case 'id': |
297 | 297 | $this->blog_id = (string) $value; |
298 | 298 | break; |
@@ -317,37 +317,37 @@ discard block |
||
317 | 317 | * @return stdClass A raw site object with all details included. |
318 | 318 | */ |
319 | 319 | private function get_details() { |
320 | - $details = wp_cache_get( $this->blog_id, 'site-details' ); |
|
320 | + $details = wp_cache_get($this->blog_id, 'site-details'); |
|
321 | 321 | |
322 | - if ( false === $details ) { |
|
322 | + if (false === $details) { |
|
323 | 323 | |
324 | - switch_to_blog( $this->blog_id ); |
|
324 | + switch_to_blog($this->blog_id); |
|
325 | 325 | // Create a raw copy of the object for backwards compatibility with the filter below. |
326 | 326 | $details = new stdClass(); |
327 | - foreach ( get_object_vars( $this ) as $key => $value ) { |
|
327 | + foreach (get_object_vars($this) as $key => $value) { |
|
328 | 328 | $details->$key = $value; |
329 | 329 | } |
330 | - $details->blogname = get_option( 'blogname' ); |
|
331 | - $details->siteurl = get_option( 'siteurl' ); |
|
332 | - $details->post_count = get_option( 'post_count' ); |
|
333 | - $details->home = get_option( 'home' ); |
|
330 | + $details->blogname = get_option('blogname'); |
|
331 | + $details->siteurl = get_option('siteurl'); |
|
332 | + $details->post_count = get_option('post_count'); |
|
333 | + $details->home = get_option('home'); |
|
334 | 334 | restore_current_blog(); |
335 | 335 | |
336 | 336 | $cache_details = true; |
337 | - foreach ( array( 'blogname', 'siteurl', 'post_count', 'home' ) as $field ) { |
|
338 | - if ( false === $details->$field ) { |
|
337 | + foreach (array('blogname', 'siteurl', 'post_count', 'home') as $field) { |
|
338 | + if (false === $details->$field) { |
|
339 | 339 | $cache_details = false; |
340 | 340 | break; |
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | - if ( $cache_details ) { |
|
345 | - wp_cache_set( $this->blog_id, $details, 'site-details' ); |
|
344 | + if ($cache_details) { |
|
345 | + wp_cache_set($this->blog_id, $details, 'site-details'); |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | 349 | /** This filter is documented in wp-includes/ms-blogs.php */ |
350 | - $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' ); |
|
350 | + $details = apply_filters_deprecated('blog_details', array($details), '4.7.0', 'site_details'); |
|
351 | 351 | |
352 | 352 | /** |
353 | 353 | * Filters a site's extended properties. |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @param stdClass $details The site details. |
358 | 358 | */ |
359 | - $details = apply_filters( 'site_details', $details ); |
|
359 | + $details = apply_filters('site_details', $details); |
|
360 | 360 | |
361 | 361 | return $details; |
362 | 362 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function wp_styles() { |
21 | 21 | global $wp_styles; |
22 | - if ( ! ( $wp_styles instanceof WP_Styles ) ) { |
|
22 | + if ( ! ($wp_styles instanceof WP_Styles)) { |
|
23 | 23 | $wp_styles = new WP_Styles(); |
24 | 24 | } |
25 | 25 | return $wp_styles; |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | * @param string|bool|array $handles Styles to be printed. Default 'false'. |
40 | 40 | * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. |
41 | 41 | */ |
42 | -function wp_print_styles( $handles = false ) { |
|
43 | - if ( '' === $handles ) { // for wp_head |
|
42 | +function wp_print_styles($handles = false) { |
|
43 | + if ('' === $handles) { // for wp_head |
|
44 | 44 | $handles = false; |
45 | 45 | } |
46 | 46 | /** |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @since 2.6.0 |
50 | 50 | */ |
51 | - if ( ! $handles ) { |
|
52 | - do_action( 'wp_print_styles' ); |
|
51 | + if ( ! $handles) { |
|
52 | + do_action('wp_print_styles'); |
|
53 | 53 | } |
54 | 54 | |
55 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
55 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
56 | 56 | |
57 | 57 | global $wp_styles; |
58 | - if ( ! ( $wp_styles instanceof WP_Styles ) ) { |
|
59 | - if ( ! $handles ) { |
|
58 | + if ( ! ($wp_styles instanceof WP_Styles)) { |
|
59 | + if ( ! $handles) { |
|
60 | 60 | return array(); // No need to instantiate if nothing is there. |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - return wp_styles()->do_items( $handles ); |
|
64 | + return wp_styles()->do_items($handles); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -80,20 +80,20 @@ discard block |
||
80 | 80 | * @param string $data String containing the CSS styles to be added. |
81 | 81 | * @return bool True on success, false on failure. |
82 | 82 | */ |
83 | -function wp_add_inline_style( $handle, $data ) { |
|
84 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
83 | +function wp_add_inline_style($handle, $data) { |
|
84 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
85 | 85 | |
86 | - if ( false !== stripos( $data, '</style>' ) ) { |
|
87 | - _doing_it_wrong( __FUNCTION__, sprintf( |
|
86 | + if (false !== stripos($data, '</style>')) { |
|
87 | + _doing_it_wrong(__FUNCTION__, sprintf( |
|
88 | 88 | /* translators: 1: <style>, 2: wp_add_inline_style() */ |
89 | - __( 'Do not pass %1$s tags to %2$s.' ), |
|
89 | + __('Do not pass %1$s tags to %2$s.'), |
|
90 | 90 | '<code><style></code>', |
91 | 91 | '<code>wp_add_inline_style()</code>' |
92 | - ), '3.7.0' ); |
|
93 | - $data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); |
|
92 | + ), '3.7.0'); |
|
93 | + $data = trim(preg_replace('#<style[^>]*>(.*)</style>#is', '$1', $data)); |
|
94 | 94 | } |
95 | 95 | |
96 | - return wp_styles()->add_inline_style( $handle, $data ); |
|
96 | + return wp_styles()->add_inline_style($handle, $data); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | * '(orientation: portrait)' and '(max-width: 640px)'. |
118 | 118 | * @return bool Whether the style has been registered. True on success, false on failure. |
119 | 119 | */ |
120 | -function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { |
|
121 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
120 | +function wp_register_style($handle, $src, $deps = array(), $ver = false, $media = 'all') { |
|
121 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
122 | 122 | |
123 | - return wp_styles()->add( $handle, $src, $deps, $ver, $media ); |
|
123 | + return wp_styles()->add($handle, $src, $deps, $ver, $media); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param string $handle Name of the stylesheet to be removed. |
134 | 134 | */ |
135 | -function wp_deregister_style( $handle ) { |
|
136 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
135 | +function wp_deregister_style($handle) { |
|
136 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
137 | 137 | |
138 | - wp_styles()->remove( $handle ); |
|
138 | + wp_styles()->remove($handle); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like |
162 | 162 | * '(orientation: portrait)' and '(max-width: 640px)'. |
163 | 163 | */ |
164 | -function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) { |
|
165 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
164 | +function wp_enqueue_style($handle, $src = '', $deps = array(), $ver = false, $media = 'all') { |
|
165 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
166 | 166 | |
167 | 167 | $wp_styles = wp_styles(); |
168 | 168 | |
169 | - if ( $src ) { |
|
169 | + if ($src) { |
|
170 | 170 | $_handle = explode('?', $handle); |
171 | - $wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); |
|
171 | + $wp_styles->add($_handle[0], $src, $deps, $ver, $media); |
|
172 | 172 | } |
173 | - $wp_styles->enqueue( $handle ); |
|
173 | + $wp_styles->enqueue($handle); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @param string $handle Name of the stylesheet to be removed. |
184 | 184 | */ |
185 | -function wp_dequeue_style( $handle ) { |
|
186 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
185 | +function wp_dequeue_style($handle) { |
|
186 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
187 | 187 | |
188 | - wp_styles()->dequeue( $handle ); |
|
188 | + wp_styles()->dequeue($handle); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | * Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
199 | 199 | * @return bool Whether style is queued. |
200 | 200 | */ |
201 | -function wp_style_is( $handle, $list = 'enqueued' ) { |
|
202 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
201 | +function wp_style_is($handle, $list = 'enqueued') { |
|
202 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
203 | 203 | |
204 | - return (bool) wp_styles()->query( $handle, $list ); |
|
204 | + return (bool) wp_styles()->query($handle, $list); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -226,6 +226,6 @@ discard block |
||
226 | 226 | * @param mixed $value String containing the CSS data to be added. |
227 | 227 | * @return bool True on success, false on failure. |
228 | 228 | */ |
229 | -function wp_style_add_data( $handle, $key, $value ) { |
|
230 | - return wp_styles()->add_data( $handle, $key, $value ); |
|
229 | +function wp_style_add_data($handle, $key, $value) { |
|
230 | + return wp_styles()->add_data($handle, $key, $value); |
|
231 | 231 | } |
@@ -7,4 +7,4 @@ |
||
7 | 7 | * @since 1.2.0 |
8 | 8 | */ |
9 | 9 | |
10 | -_deprecated_file( basename( __FILE__ ), '4.7.0' ); |
|
10 | +_deprecated_file(basename(__FILE__), '4.7.0'); |
@@ -24,12 +24,12 @@ |
||
24 | 24 | * @return WP_Site Current site object. |
25 | 25 | */ |
26 | 26 | function get_dashboard_blog() { |
27 | - _deprecated_function( __FUNCTION__, '3.1.0' ); |
|
28 | - if ( $blog = get_site_option( 'dashboard_blog' ) ) { |
|
29 | - return get_site( $blog ); |
|
30 | - } |
|
27 | + _deprecated_function( __FUNCTION__, '3.1.0' ); |
|
28 | + if ( $blog = get_site_option( 'dashboard_blog' ) ) { |
|
29 | + return get_site( $blog ); |
|
30 | + } |
|
31 | 31 | |
32 | - return get_site( get_network()->site_id ); |
|
32 | + return get_site( get_network()->site_id ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -24,12 +24,12 @@ discard block |
||
24 | 24 | * @return WP_Site Current site object. |
25 | 25 | */ |
26 | 26 | function get_dashboard_blog() { |
27 | - _deprecated_function( __FUNCTION__, '3.1.0' ); |
|
28 | - if ( $blog = get_site_option( 'dashboard_blog' ) ) { |
|
29 | - return get_site( $blog ); |
|
27 | + _deprecated_function(__FUNCTION__, '3.1.0'); |
|
28 | + if ($blog = get_site_option('dashboard_blog')) { |
|
29 | + return get_site($blog); |
|
30 | 30 | } |
31 | 31 | |
32 | - return get_site( get_network()->site_id ); |
|
32 | + return get_site(get_network()->site_id); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param int $len Optional. The length of password to generate. Default 8. |
43 | 43 | */ |
44 | -function generate_random_password( $len = 8 ) { |
|
45 | - _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' ); |
|
46 | - return wp_generate_password( $len ); |
|
44 | +function generate_random_password($len = 8) { |
|
45 | + _deprecated_function(__FUNCTION__, '3.0.0', 'wp_generate_password()'); |
|
46 | + return wp_generate_password($len); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @param string $user_login Optional. Username for the user to check. Default empty. |
63 | 63 | */ |
64 | -function is_site_admin( $user_login = '' ) { |
|
65 | - _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' ); |
|
64 | +function is_site_admin($user_login = '') { |
|
65 | + _deprecated_function(__FUNCTION__, '3.0.0', 'is_super_admin()'); |
|
66 | 66 | |
67 | - if ( empty( $user_login ) ) { |
|
67 | + if (empty($user_login)) { |
|
68 | 68 | $user_id = get_current_user_id(); |
69 | - if ( !$user_id ) |
|
69 | + if ( ! $user_id) |
|
70 | 70 | return false; |
71 | 71 | } else { |
72 | - $user = get_user_by( 'login', $user_login ); |
|
73 | - if ( ! $user->exists() ) |
|
72 | + $user = get_user_by('login', $user_login); |
|
73 | + if ( ! $user->exists()) |
|
74 | 74 | return false; |
75 | 75 | $user_id = $user->ID; |
76 | 76 | } |
77 | 77 | |
78 | - return is_super_admin( $user_id ); |
|
78 | + return is_super_admin($user_id); |
|
79 | 79 | } |
80 | 80 | |
81 | -if ( !function_exists( 'graceful_fail' ) ) : |
|
81 | +if ( ! function_exists('graceful_fail')) : |
|
82 | 82 | /** |
83 | 83 | * Deprecated functionality to gracefully fail. |
84 | 84 | * |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | * @deprecated 3.0.0 Use wp_die() |
87 | 87 | * @see wp_die() |
88 | 88 | */ |
89 | -function graceful_fail( $message ) { |
|
90 | - _deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' ); |
|
91 | - $message = apply_filters( 'graceful_fail', $message ); |
|
92 | - $message_template = apply_filters( 'graceful_fail_template', |
|
89 | +function graceful_fail($message) { |
|
90 | + _deprecated_function(__FUNCTION__, '3.0.0', 'wp_die()'); |
|
91 | + $message = apply_filters('graceful_fail', $message); |
|
92 | + $message_template = apply_filters('graceful_fail_template', |
|
93 | 93 | '<!DOCTYPE html> |
94 | 94 | <html xmlns="http://www.w3.org/1999/xhtml"><head> |
95 | 95 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | <p class="message">%s</p> |
114 | 114 | </body> |
115 | 115 | </html>' ); |
116 | - die( sprintf( $message_template, $message ) ); |
|
116 | + die(sprintf($message_template, $message)); |
|
117 | 117 | } |
118 | 118 | endif; |
119 | 119 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @param string $username Username. |
128 | 128 | */ |
129 | -function get_user_details( $username ) { |
|
130 | - _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' ); |
|
129 | +function get_user_details($username) { |
|
130 | + _deprecated_function(__FUNCTION__, '3.0.0', 'get_user_by()'); |
|
131 | 131 | return get_user_by('login', $username); |
132 | 132 | } |
133 | 133 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @param int $post_id Post ID. |
142 | 142 | */ |
143 | -function clear_global_post_cache( $post_id ) { |
|
144 | - _deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' ); |
|
143 | +function clear_global_post_cache($post_id) { |
|
144 | + _deprecated_function(__FUNCTION__, '3.0.0', 'clean_post_cache()'); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @see is_main_site() |
153 | 153 | */ |
154 | 154 | function is_main_blog() { |
155 | - _deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' ); |
|
155 | + _deprecated_function(__FUNCTION__, '3.0.0', 'is_main_site()'); |
|
156 | 156 | return is_main_site(); |
157 | 157 | } |
158 | 158 | |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | * @param bool $check_domain Deprecated. |
168 | 168 | * @return string|bool Either false or the valid email address. |
169 | 169 | */ |
170 | -function validate_email( $email, $check_domain = true) { |
|
171 | - _deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' ); |
|
172 | - return is_email( $email, $check_domain ); |
|
170 | +function validate_email($email, $check_domain = true) { |
|
171 | + _deprecated_function(__FUNCTION__, '3.0.0', 'is_email()'); |
|
172 | + return is_email($email, $check_domain); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -183,26 +183,26 @@ discard block |
||
183 | 183 | * @param int $num Optional. Number of blogs to list. Default 10. |
184 | 184 | * @param string $deprecated Unused. |
185 | 185 | */ |
186 | -function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) { |
|
187 | - _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' ); |
|
186 | +function get_blog_list($start = 0, $num = 10, $deprecated = '') { |
|
187 | + _deprecated_function(__FUNCTION__, '3.0.0', 'wp_get_sites()'); |
|
188 | 188 | |
189 | 189 | global $wpdb; |
190 | - $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); |
|
190 | + $blogs = $wpdb->get_results($wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A); |
|
191 | 191 | |
192 | 192 | $blog_list = array(); |
193 | - foreach ( (array) $blogs as $details ) { |
|
194 | - $blog_list[ $details['blog_id'] ] = $details; |
|
195 | - $blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" ); |
|
193 | + foreach ((array) $blogs as $details) { |
|
194 | + $blog_list[$details['blog_id']] = $details; |
|
195 | + $blog_list[$details['blog_id']]['postcount'] = $wpdb->get_var("SELECT COUNT(ID) FROM ".$wpdb->get_blog_prefix($details['blog_id'])."posts WHERE post_status='publish' AND post_type='post'"); |
|
196 | 196 | } |
197 | 197 | |
198 | - if ( ! $blog_list ) { |
|
198 | + if ( ! $blog_list) { |
|
199 | 199 | return array(); |
200 | 200 | } |
201 | 201 | |
202 | - if ( $num == 'all' ) { |
|
203 | - return array_slice( $blog_list, $start, count( $blog_list ) ); |
|
202 | + if ($num == 'all') { |
|
203 | + return array_slice($blog_list, $start, count($blog_list)); |
|
204 | 204 | } else { |
205 | - return array_slice( $blog_list, $start, $num ); |
|
205 | + return array_slice($blog_list, $start, $num); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -216,38 +216,38 @@ discard block |
||
216 | 216 | * @param bool $display Optional. Whether or not to display the most active blogs list. Default true. |
217 | 217 | * @return array List of "most active" sites. |
218 | 218 | */ |
219 | -function get_most_active_blogs( $num = 10, $display = true ) { |
|
220 | - _deprecated_function( __FUNCTION__, '3.0.0' ); |
|
219 | +function get_most_active_blogs($num = 10, $display = true) { |
|
220 | + _deprecated_function(__FUNCTION__, '3.0.0'); |
|
221 | 221 | |
222 | - $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details |
|
223 | - if ( is_array( $blogs ) ) { |
|
224 | - reset( $blogs ); |
|
222 | + $blogs = get_blog_list(0, 'all', false); // $blog_id -> $details |
|
223 | + if (is_array($blogs)) { |
|
224 | + reset($blogs); |
|
225 | 225 | $most_active = array(); |
226 | 226 | $blog_list = array(); |
227 | - foreach ( (array) $blogs as $key => $details ) { |
|
228 | - $most_active[ $details['blog_id'] ] = $details['postcount']; |
|
229 | - $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!! |
|
227 | + foreach ((array) $blogs as $key => $details) { |
|
228 | + $most_active[$details['blog_id']] = $details['postcount']; |
|
229 | + $blog_list[$details['blog_id']] = $details; // array_slice() removes keys!! |
|
230 | 230 | } |
231 | - arsort( $most_active ); |
|
232 | - reset( $most_active ); |
|
231 | + arsort($most_active); |
|
232 | + reset($most_active); |
|
233 | 233 | $t = array(); |
234 | - foreach ( (array) $most_active as $key => $details ) { |
|
235 | - $t[ $key ] = $blog_list[ $key ]; |
|
234 | + foreach ((array) $most_active as $key => $details) { |
|
235 | + $t[$key] = $blog_list[$key]; |
|
236 | 236 | } |
237 | - unset( $most_active ); |
|
237 | + unset($most_active); |
|
238 | 238 | $most_active = $t; |
239 | 239 | } |
240 | 240 | |
241 | - if ( $display ) { |
|
242 | - if ( is_array( $most_active ) ) { |
|
243 | - reset( $most_active ); |
|
244 | - foreach ( (array) $most_active as $key => $details ) { |
|
245 | - $url = esc_url('http://' . $details['domain'] . $details['path']); |
|
246 | - echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>"; |
|
241 | + if ($display) { |
|
242 | + if (is_array($most_active)) { |
|
243 | + reset($most_active); |
|
244 | + foreach ((array) $most_active as $key => $details) { |
|
245 | + $url = esc_url('http://'.$details['domain'].$details['path']); |
|
246 | + echo '<li>'.$details['postcount']." <a href='$url'>$url</a></li>"; |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
250 | - return array_slice( $most_active, 0, $num ); |
|
250 | + return array_slice($most_active, 0, $num); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -267,33 +267,33 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @param string $url Optional. Redirect URL. Default empty. |
269 | 269 | */ |
270 | -function wpmu_admin_do_redirect( $url = '' ) { |
|
271 | - _deprecated_function( __FUNCTION__, '3.3.0' ); |
|
270 | +function wpmu_admin_do_redirect($url = '') { |
|
271 | + _deprecated_function(__FUNCTION__, '3.3.0'); |
|
272 | 272 | |
273 | 273 | $ref = ''; |
274 | - if ( isset( $_GET['ref'] ) ) |
|
274 | + if (isset($_GET['ref'])) |
|
275 | 275 | $ref = $_GET['ref']; |
276 | - if ( isset( $_POST['ref'] ) ) |
|
276 | + if (isset($_POST['ref'])) |
|
277 | 277 | $ref = $_POST['ref']; |
278 | 278 | |
279 | - if ( $ref ) { |
|
280 | - $ref = wpmu_admin_redirect_add_updated_param( $ref ); |
|
281 | - wp_redirect( $ref ); |
|
279 | + if ($ref) { |
|
280 | + $ref = wpmu_admin_redirect_add_updated_param($ref); |
|
281 | + wp_redirect($ref); |
|
282 | 282 | exit(); |
283 | 283 | } |
284 | - if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { |
|
285 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
284 | + if ( ! empty($_SERVER['HTTP_REFERER'])) { |
|
285 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
286 | 286 | exit(); |
287 | 287 | } |
288 | 288 | |
289 | - $url = wpmu_admin_redirect_add_updated_param( $url ); |
|
290 | - if ( isset( $_GET['redirect'] ) ) { |
|
291 | - if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) |
|
292 | - $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) ); |
|
293 | - } elseif ( isset( $_POST['redirect'] ) ) { |
|
294 | - $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] ); |
|
289 | + $url = wpmu_admin_redirect_add_updated_param($url); |
|
290 | + if (isset($_GET['redirect'])) { |
|
291 | + if (substr($_GET['redirect'], 0, 2) == 's_') |
|
292 | + $url .= '&action=blogs&s='.esc_html(substr($_GET['redirect'], 2)); |
|
293 | + } elseif (isset($_POST['redirect'])) { |
|
294 | + $url = wpmu_admin_redirect_add_updated_param($_POST['redirect']); |
|
295 | 295 | } |
296 | - wp_redirect( $url ); |
|
296 | + wp_redirect($url); |
|
297 | 297 | exit(); |
298 | 298 | } |
299 | 299 | |
@@ -307,14 +307,14 @@ discard block |
||
307 | 307 | * @param string $url Optional. Redirect URL. Default empty. |
308 | 308 | * @return string |
309 | 309 | */ |
310 | -function wpmu_admin_redirect_add_updated_param( $url = '' ) { |
|
311 | - _deprecated_function( __FUNCTION__, '3.3.0' ); |
|
310 | +function wpmu_admin_redirect_add_updated_param($url = '') { |
|
311 | + _deprecated_function(__FUNCTION__, '3.3.0'); |
|
312 | 312 | |
313 | - if ( strpos( $url, 'updated=true' ) === false ) { |
|
314 | - if ( strpos( $url, '?' ) === false ) |
|
315 | - return $url . '?updated=true'; |
|
313 | + if (strpos($url, 'updated=true') === false) { |
|
314 | + if (strpos($url, '?') === false) |
|
315 | + return $url.'?updated=true'; |
|
316 | 316 | else |
317 | - return $url . '&updated=true'; |
|
317 | + return $url.'&updated=true'; |
|
318 | 318 | } |
319 | 319 | return $url; |
320 | 320 | } |
@@ -332,17 +332,17 @@ discard block |
||
332 | 332 | * @param string $string Either an email address or a login. |
333 | 333 | * @return int |
334 | 334 | */ |
335 | -function get_user_id_from_string( $string ) { |
|
336 | - _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' ); |
|
335 | +function get_user_id_from_string($string) { |
|
336 | + _deprecated_function(__FUNCTION__, '3.6.0', 'get_user_by()'); |
|
337 | 337 | |
338 | - if ( is_email( $string ) ) |
|
339 | - $user = get_user_by( 'email', $string ); |
|
340 | - elseif ( is_numeric( $string ) ) |
|
338 | + if (is_email($string)) |
|
339 | + $user = get_user_by('email', $string); |
|
340 | + elseif (is_numeric($string)) |
|
341 | 341 | return $string; |
342 | 342 | else |
343 | - $user = get_user_by( 'login', $string ); |
|
343 | + $user = get_user_by('login', $string); |
|
344 | 344 | |
345 | - if ( $user ) |
|
345 | + if ($user) |
|
346 | 346 | return $user->ID; |
347 | 347 | return 0; |
348 | 348 | } |
@@ -357,23 +357,23 @@ discard block |
||
357 | 357 | * @param string $path |
358 | 358 | * @return string |
359 | 359 | */ |
360 | -function get_blogaddress_by_domain( $domain, $path ) { |
|
361 | - _deprecated_function( __FUNCTION__, '3.7.0' ); |
|
360 | +function get_blogaddress_by_domain($domain, $path) { |
|
361 | + _deprecated_function(__FUNCTION__, '3.7.0'); |
|
362 | 362 | |
363 | - if ( is_subdomain_install() ) { |
|
364 | - $url = "http://" . $domain.$path; |
|
363 | + if (is_subdomain_install()) { |
|
364 | + $url = "http://".$domain.$path; |
|
365 | 365 | } else { |
366 | - if ( $domain != $_SERVER['HTTP_HOST'] ) { |
|
367 | - $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); |
|
368 | - $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path; |
|
366 | + if ($domain != $_SERVER['HTTP_HOST']) { |
|
367 | + $blogname = substr($domain, 0, strpos($domain, '.')); |
|
368 | + $url = 'http://'.substr($domain, strpos($domain, '.') + 1).$path; |
|
369 | 369 | // we're not installing the main blog |
370 | - if ( $blogname != 'www.' ) |
|
371 | - $url .= $blogname . '/'; |
|
370 | + if ($blogname != 'www.') |
|
371 | + $url .= $blogname.'/'; |
|
372 | 372 | } else { // main blog |
373 | - $url = 'http://' . $domain . $path; |
|
373 | + $url = 'http://'.$domain.$path; |
|
374 | 374 | } |
375 | 375 | } |
376 | - return esc_url_raw( $url ); |
|
376 | + return esc_url_raw($url); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -388,22 +388,22 @@ discard block |
||
388 | 388 | * @param int $site_id Optional. Defaults to 1. |
389 | 389 | * @return string|int The ID of the newly created blog |
390 | 390 | */ |
391 | -function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { |
|
392 | - _deprecated_function( __FUNCTION__, '4.4.0' ); |
|
391 | +function create_empty_blog($domain, $path, $weblog_title, $site_id = 1) { |
|
392 | + _deprecated_function(__FUNCTION__, '4.4.0'); |
|
393 | 393 | |
394 | - if ( empty($path) ) |
|
394 | + if (empty($path)) |
|
395 | 395 | $path = '/'; |
396 | 396 | |
397 | 397 | // Check if the domain has been used already. We should return an error message. |
398 | - if ( domain_exists($domain, $path, $site_id) ) |
|
399 | - return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
398 | + if (domain_exists($domain, $path, $site_id)) |
|
399 | + return __('<strong>ERROR</strong>: Site URL already taken.'); |
|
400 | 400 | |
401 | 401 | // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. |
402 | 402 | // Need to get blog_id from wp_blogs, and create new table names. |
403 | 403 | // Must restore table names at the end of function. |
404 | 404 | |
405 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
406 | - return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
405 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id)) |
|
406 | + return __('<strong>ERROR</strong>: problem creating site entry.'); |
|
407 | 407 | |
408 | 408 | switch_to_blog($blog_id); |
409 | 409 | install_blog($blog_id); |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | * @param string $path Optional. Site path. |
425 | 425 | * @return array|false The network admins |
426 | 426 | */ |
427 | -function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { |
|
428 | - _deprecated_function( __FUNCTION__, '4.4.0' ); |
|
427 | +function get_admin_users_for_domain($sitedomain = '', $path = '') { |
|
428 | + _deprecated_function(__FUNCTION__, '4.4.0'); |
|
429 | 429 | |
430 | 430 | global $wpdb; |
431 | 431 | |
432 | - if ( ! $sitedomain ) |
|
432 | + if ( ! $sitedomain) |
|
433 | 433 | $site_id = $wpdb->siteid; |
434 | 434 | else |
435 | - $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
435 | + $site_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path)); |
|
436 | 436 | |
437 | - if ( $site_id ) |
|
438 | - return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
437 | + if ($site_id) |
|
438 | + return $wpdb->get_results($wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id), ARRAY_A); |
|
439 | 439 | |
440 | 440 | return false; |
441 | 441 | } |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | * site domain and path, dates registered and modified, and the language ID. Also, boolean |
468 | 468 | * values for whether the site is public, archived, mature, spam, and/or deleted. |
469 | 469 | */ |
470 | -function wp_get_sites( $args = array() ) { |
|
470 | +function wp_get_sites($args = array()) { |
|
471 | 471 | global $wpdb; |
472 | 472 | |
473 | - _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); |
|
473 | + _deprecated_function(__FUNCTION__, '4.6.0', 'get_sites()'); |
|
474 | 474 | |
475 | - if ( wp_is_large_network() ) |
|
475 | + if (wp_is_large_network()) |
|
476 | 476 | return array(); |
477 | 477 | |
478 | 478 | $defaults = array( |
@@ -486,15 +486,15 @@ discard block |
||
486 | 486 | 'offset' => 0, |
487 | 487 | ); |
488 | 488 | |
489 | - $args = wp_parse_args( $args, $defaults ); |
|
489 | + $args = wp_parse_args($args, $defaults); |
|
490 | 490 | |
491 | 491 | // Backwards compatibility |
492 | - if( is_array( $args['network_id'] ) ){ |
|
492 | + if (is_array($args['network_id'])) { |
|
493 | 493 | $args['network__in'] = $args['network_id']; |
494 | 494 | $args['network_id'] = null; |
495 | 495 | } |
496 | 496 | |
497 | - if( is_numeric( $args['limit'] ) ){ |
|
497 | + if (is_numeric($args['limit'])) { |
|
498 | 498 | $args['number'] = $args['limit']; |
499 | 499 | $args['limit'] = null; |
500 | 500 | } |
@@ -502,12 +502,12 @@ discard block |
||
502 | 502 | // Make sure count is disabled. |
503 | 503 | $args['count'] = false; |
504 | 504 | |
505 | - $_sites = get_sites( $args ); |
|
505 | + $_sites = get_sites($args); |
|
506 | 506 | |
507 | 507 | $results = array(); |
508 | 508 | |
509 | - foreach ( $_sites as $_site ) { |
|
510 | - $_site = get_site( $_site ); |
|
509 | + foreach ($_sites as $_site) { |
|
510 | + $_site = get_site($_site); |
|
511 | 511 | $results[] = $_site->to_array(); |
512 | 512 | } |
513 | 513 |
@@ -66,12 +66,14 @@ discard block |
||
66 | 66 | |
67 | 67 | if ( empty( $user_login ) ) { |
68 | 68 | $user_id = get_current_user_id(); |
69 | - if ( !$user_id ) |
|
70 | - return false; |
|
69 | + if ( !$user_id ) { |
|
70 | + return false; |
|
71 | + } |
|
71 | 72 | } else { |
72 | 73 | $user = get_user_by( 'login', $user_login ); |
73 | - if ( ! $user->exists() ) |
|
74 | - return false; |
|
74 | + if ( ! $user->exists() ) { |
|
75 | + return false; |
|
76 | + } |
|
75 | 77 | $user_id = $user->ID; |
76 | 78 | } |
77 | 79 | |
@@ -271,10 +273,12 @@ discard block |
||
271 | 273 | _deprecated_function( __FUNCTION__, '3.3.0' ); |
272 | 274 | |
273 | 275 | $ref = ''; |
274 | - if ( isset( $_GET['ref'] ) ) |
|
275 | - $ref = $_GET['ref']; |
|
276 | - if ( isset( $_POST['ref'] ) ) |
|
277 | - $ref = $_POST['ref']; |
|
276 | + if ( isset( $_GET['ref'] ) ) { |
|
277 | + $ref = $_GET['ref']; |
|
278 | + } |
|
279 | + if ( isset( $_POST['ref'] ) ) { |
|
280 | + $ref = $_POST['ref']; |
|
281 | + } |
|
278 | 282 | |
279 | 283 | if ( $ref ) { |
280 | 284 | $ref = wpmu_admin_redirect_add_updated_param( $ref ); |
@@ -288,8 +292,9 @@ discard block |
||
288 | 292 | |
289 | 293 | $url = wpmu_admin_redirect_add_updated_param( $url ); |
290 | 294 | if ( isset( $_GET['redirect'] ) ) { |
291 | - if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) |
|
292 | - $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) ); |
|
295 | + if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) { |
|
296 | + $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) ); |
|
297 | + } |
|
293 | 298 | } elseif ( isset( $_POST['redirect'] ) ) { |
294 | 299 | $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] ); |
295 | 300 | } |
@@ -311,10 +316,11 @@ discard block |
||
311 | 316 | _deprecated_function( __FUNCTION__, '3.3.0' ); |
312 | 317 | |
313 | 318 | if ( strpos( $url, 'updated=true' ) === false ) { |
314 | - if ( strpos( $url, '?' ) === false ) |
|
315 | - return $url . '?updated=true'; |
|
316 | - else |
|
317 | - return $url . '&updated=true'; |
|
319 | + if ( strpos( $url, '?' ) === false ) { |
|
320 | + return $url . '?updated=true'; |
|
321 | + } else { |
|
322 | + return $url . '&updated=true'; |
|
323 | + } |
|
318 | 324 | } |
319 | 325 | return $url; |
320 | 326 | } |
@@ -335,15 +341,17 @@ discard block |
||
335 | 341 | function get_user_id_from_string( $string ) { |
336 | 342 | _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' ); |
337 | 343 | |
338 | - if ( is_email( $string ) ) |
|
339 | - $user = get_user_by( 'email', $string ); |
|
340 | - elseif ( is_numeric( $string ) ) |
|
341 | - return $string; |
|
342 | - else |
|
343 | - $user = get_user_by( 'login', $string ); |
|
344 | + if ( is_email( $string ) ) { |
|
345 | + $user = get_user_by( 'email', $string ); |
|
346 | + } elseif ( is_numeric( $string ) ) { |
|
347 | + return $string; |
|
348 | + } else { |
|
349 | + $user = get_user_by( 'login', $string ); |
|
350 | + } |
|
344 | 351 | |
345 | - if ( $user ) |
|
346 | - return $user->ID; |
|
352 | + if ( $user ) { |
|
353 | + return $user->ID; |
|
354 | + } |
|
347 | 355 | return 0; |
348 | 356 | } |
349 | 357 | |
@@ -367,8 +375,9 @@ discard block |
||
367 | 375 | $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); |
368 | 376 | $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path; |
369 | 377 | // we're not installing the main blog |
370 | - if ( $blogname != 'www.' ) |
|
371 | - $url .= $blogname . '/'; |
|
378 | + if ( $blogname != 'www.' ) { |
|
379 | + $url .= $blogname . '/'; |
|
380 | + } |
|
372 | 381 | } else { // main blog |
373 | 382 | $url = 'http://' . $domain . $path; |
374 | 383 | } |
@@ -391,19 +400,22 @@ discard block |
||
391 | 400 | function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { |
392 | 401 | _deprecated_function( __FUNCTION__, '4.4.0' ); |
393 | 402 | |
394 | - if ( empty($path) ) |
|
395 | - $path = '/'; |
|
403 | + if ( empty($path) ) { |
|
404 | + $path = '/'; |
|
405 | + } |
|
396 | 406 | |
397 | 407 | // Check if the domain has been used already. We should return an error message. |
398 | - if ( domain_exists($domain, $path, $site_id) ) |
|
399 | - return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
408 | + if ( domain_exists($domain, $path, $site_id) ) { |
|
409 | + return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
410 | + } |
|
400 | 411 | |
401 | 412 | // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. |
402 | 413 | // Need to get blog_id from wp_blogs, and create new table names. |
403 | 414 | // Must restore table names at the end of function. |
404 | 415 | |
405 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
406 | - return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
416 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) { |
|
417 | + return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
418 | + } |
|
407 | 419 | |
408 | 420 | switch_to_blog($blog_id); |
409 | 421 | install_blog($blog_id); |
@@ -429,13 +441,15 @@ discard block |
||
429 | 441 | |
430 | 442 | global $wpdb; |
431 | 443 | |
432 | - if ( ! $sitedomain ) |
|
433 | - $site_id = $wpdb->siteid; |
|
434 | - else |
|
435 | - $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
444 | + if ( ! $sitedomain ) { |
|
445 | + $site_id = $wpdb->siteid; |
|
446 | + } else { |
|
447 | + $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
448 | + } |
|
436 | 449 | |
437 | - if ( $site_id ) |
|
438 | - return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
450 | + if ( $site_id ) { |
|
451 | + return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
452 | + } |
|
439 | 453 | |
440 | 454 | return false; |
441 | 455 | } |
@@ -472,8 +486,9 @@ discard block |
||
472 | 486 | |
473 | 487 | _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); |
474 | 488 | |
475 | - if ( wp_is_large_network() ) |
|
476 | - return array(); |
|
489 | + if ( wp_is_large_network() ) { |
|
490 | + return array(); |
|
491 | + } |
|
477 | 492 | |
478 | 493 | $defaults = array( |
479 | 494 | 'network_id' => $wpdb->siteid, |
@@ -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,18 +33,18 @@ 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' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) { |
|
36 | +function _wp_scripts_maybe_doing_it_wrong($function) { |
|
37 | + if (did_action('init') || did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts') || did_action('login_enqueue_scripts')) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - _doing_it_wrong( $function, sprintf( |
|
41 | + _doing_it_wrong($function, sprintf( |
|
42 | 42 | /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ |
43 | - __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
43 | + __('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), |
|
44 | 44 | '<code>wp_enqueue_scripts</code>', |
45 | 45 | '<code>admin_enqueue_scripts</code>', |
46 | 46 | '<code>login_enqueue_scripts</code>' |
47 | - ), '3.3.0' ); |
|
47 | + ), '3.3.0'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -63,27 +63,27 @@ discard block |
||
63 | 63 | * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'. |
64 | 64 | * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. |
65 | 65 | */ |
66 | -function wp_print_scripts( $handles = false ) { |
|
66 | +function wp_print_scripts($handles = false) { |
|
67 | 67 | /** |
68 | 68 | * Fires before scripts in the $handles queue are printed. |
69 | 69 | * |
70 | 70 | * @since 2.1.0 |
71 | 71 | */ |
72 | - do_action( 'wp_print_scripts' ); |
|
73 | - if ( '' === $handles ) { // for wp_head |
|
72 | + do_action('wp_print_scripts'); |
|
73 | + if ('' === $handles) { // for wp_head |
|
74 | 74 | $handles = false; |
75 | 75 | } |
76 | 76 | |
77 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
77 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
78 | 78 | |
79 | 79 | global $wp_scripts; |
80 | - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
81 | - if ( ! $handles ) { |
|
80 | + if ( ! ($wp_scripts instanceof WP_Scripts)) { |
|
81 | + if ( ! $handles) { |
|
82 | 82 | return array(); // No need to instantiate if nothing is there. |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return wp_scripts()->do_items( $handles ); |
|
86 | + return wp_scripts()->do_items($handles); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | * or after. Default 'after'. |
105 | 105 | * @return bool True on success, false on failure. |
106 | 106 | */ |
107 | -function wp_add_inline_script( $handle, $data, $position = 'after' ) { |
|
108 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
107 | +function wp_add_inline_script($handle, $data, $position = 'after') { |
|
108 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
109 | 109 | |
110 | - if ( false !== stripos( $data, '</script>' ) ) { |
|
111 | - _doing_it_wrong( __FUNCTION__, sprintf( |
|
110 | + if (false !== stripos($data, '</script>')) { |
|
111 | + _doing_it_wrong(__FUNCTION__, sprintf( |
|
112 | 112 | /* translators: 1: <script>, 2: wp_add_inline_script() */ |
113 | - __( 'Do not pass %1$s tags to %2$s.' ), |
|
113 | + __('Do not pass %1$s tags to %2$s.'), |
|
114 | 114 | '<code><script></code>', |
115 | 115 | '<code>wp_add_inline_script()</code>' |
116 | - ), '4.5.0' ); |
|
117 | - $data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) ); |
|
116 | + ), '4.5.0'); |
|
117 | + $data = trim(preg_replace('#<script[^>]*>(.*)</script>#is', '$1', $data)); |
|
118 | 118 | } |
119 | 119 | |
120 | - return wp_scripts()->add_inline_script( $handle, $data, $position ); |
|
120 | + return wp_scripts()->add_inline_script($handle, $data, $position); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | * Default 'false'. |
143 | 143 | * @return bool Whether the script has been registered. True on success, false on failure. |
144 | 144 | */ |
145 | -function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
|
145 | +function wp_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false) { |
|
146 | 146 | $wp_scripts = wp_scripts(); |
147 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
147 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
148 | 148 | |
149 | - $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); |
|
150 | - if ( $in_footer ) { |
|
151 | - $wp_scripts->add_data( $handle, 'group', 1 ); |
|
149 | + $registered = $wp_scripts->add($handle, $src, $deps, $ver); |
|
150 | + if ($in_footer) { |
|
151 | + $wp_scripts->add_data($handle, 'group', 1); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $registered; |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | * @param array $l10n The data itself. The data can be either a single or multi-dimensional array. |
183 | 183 | * @return bool True if the script was successfully localized, false otherwise. |
184 | 184 | */ |
185 | -function wp_localize_script( $handle, $object_name, $l10n ) { |
|
185 | +function wp_localize_script($handle, $object_name, $l10n) { |
|
186 | 186 | global $wp_scripts; |
187 | - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
188 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
187 | + if ( ! ($wp_scripts instanceof WP_Scripts)) { |
|
188 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - return $wp_scripts->localize( $handle, $object_name, $l10n ); |
|
192 | + return $wp_scripts->localize($handle, $object_name, $l10n); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @param string $handle Name of the script to be removed. |
206 | 206 | */ |
207 | -function wp_deregister_script( $handle ) { |
|
208 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
207 | +function wp_deregister_script($handle) { |
|
208 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Do not allow accidental or negligent de-registering of critical scripts in the admin. |
212 | 212 | * Show minimal remorse if the correct hook is used. |
213 | 213 | */ |
214 | 214 | $current_filter = current_filter(); |
215 | - if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || |
|
216 | - ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) |
|
215 | + if ((is_admin() && 'admin_enqueue_scripts' !== $current_filter) || |
|
216 | + ('wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter) |
|
217 | 217 | ) { |
218 | 218 | $no = array( |
219 | 219 | 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', |
@@ -224,19 +224,19 @@ discard block |
||
224 | 224 | 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', |
225 | 225 | ); |
226 | 226 | |
227 | - if ( in_array( $handle, $no ) ) { |
|
227 | + if (in_array($handle, $no)) { |
|
228 | 228 | $message = sprintf( |
229 | 229 | /* translators: 1: script name, 2: wp_enqueue_scripts */ |
230 | - __( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ), |
|
230 | + __('Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.'), |
|
231 | 231 | "<code>$handle</code>", |
232 | 232 | '<code>wp_enqueue_scripts</code>' |
233 | 233 | ); |
234 | - _doing_it_wrong( __FUNCTION__, $message, '3.6.0' ); |
|
234 | + _doing_it_wrong(__FUNCTION__, $message, '3.6.0'); |
|
235 | 235 | return; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - wp_scripts()->remove( $handle ); |
|
239 | + wp_scripts()->remove($handle); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -261,25 +261,25 @@ discard block |
||
261 | 261 | * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. |
262 | 262 | * Default 'false'. |
263 | 263 | */ |
264 | -function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { |
|
264 | +function wp_enqueue_script($handle, $src = '', $deps = array(), $ver = false, $in_footer = false) { |
|
265 | 265 | $wp_scripts = wp_scripts(); |
266 | 266 | |
267 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
267 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
268 | 268 | |
269 | 269 | |
270 | - if ( $src || $in_footer ) { |
|
271 | - $_handle = explode( '?', $handle ); |
|
270 | + if ($src || $in_footer) { |
|
271 | + $_handle = explode('?', $handle); |
|
272 | 272 | |
273 | - if ( $src ) { |
|
274 | - $wp_scripts->add( $_handle[0], $src, $deps, $ver ); |
|
273 | + if ($src) { |
|
274 | + $wp_scripts->add($_handle[0], $src, $deps, $ver); |
|
275 | 275 | } |
276 | 276 | |
277 | - if ( $in_footer ) { |
|
278 | - $wp_scripts->add_data( $_handle[0], 'group', 1 ); |
|
277 | + if ($in_footer) { |
|
278 | + $wp_scripts->add_data($_handle[0], 'group', 1); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - $wp_scripts->enqueue( $handle ); |
|
282 | + $wp_scripts->enqueue($handle); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -291,10 +291,10 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @param string $handle Name of the script to be removed. |
293 | 293 | */ |
294 | -function wp_dequeue_script( $handle ) { |
|
295 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
294 | +function wp_dequeue_script($handle) { |
|
295 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
296 | 296 | |
297 | - wp_scripts()->dequeue( $handle ); |
|
297 | + wp_scripts()->dequeue($handle); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | * Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
309 | 309 | * @return bool Whether the script is queued. |
310 | 310 | */ |
311 | -function wp_script_is( $handle, $list = 'enqueued' ) { |
|
312 | - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
311 | +function wp_script_is($handle, $list = 'enqueued') { |
|
312 | + _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); |
|
313 | 313 | |
314 | - return (bool) wp_scripts()->query( $handle, $list ); |
|
314 | + return (bool) wp_scripts()->query($handle, $list); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -331,6 +331,6 @@ discard block |
||
331 | 331 | * @param mixed $value String containing the data to be added. |
332 | 332 | * @return bool True on success, false on failure. |
333 | 333 | */ |
334 | -function wp_script_add_data( $handle, $key, $value ){ |
|
335 | - return wp_scripts()->add_data( $handle, $key, $value ); |
|
334 | +function wp_script_add_data($handle, $key, $value) { |
|
335 | + return wp_scripts()->add_data($handle, $key, $value); |
|
336 | 336 | } |
@@ -39,22 +39,22 @@ |
||
39 | 39 | * @license http://www.opensource.org/licenses/bsd-license.php BSD |
40 | 40 | */ |
41 | 41 | |
42 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-server.php' ); |
|
42 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-server.php'); |
|
43 | 43 | |
44 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-base64.php' ); |
|
44 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-base64.php'); |
|
45 | 45 | |
46 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-client.php' ); |
|
46 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-client.php'); |
|
47 | 47 | |
48 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-clientmulticall.php' ); |
|
48 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-clientmulticall.php'); |
|
49 | 49 | |
50 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-date.php' ); |
|
50 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-date.php'); |
|
51 | 51 | |
52 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-error.php' ); |
|
52 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-error.php'); |
|
53 | 53 | |
54 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-introspectionserver.php' ); |
|
54 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-introspectionserver.php'); |
|
55 | 55 | |
56 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-message.php' ); |
|
56 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-message.php'); |
|
57 | 57 | |
58 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-request.php' ); |
|
58 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-request.php'); |
|
59 | 59 | |
60 | -require_once( ABSPATH . WPINC . '/IXR/class-IXR-value.php' ); |
|
61 | 60 | \ No newline at end of file |
61 | +require_once(ABSPATH.WPINC.'/IXR/class-IXR-value.php'); |
|
62 | 62 | \ No newline at end of file |
@@ -122,74 +122,74 @@ discard block |
||
122 | 122 | * there's insufficient data to distinguish which term is intended. |
123 | 123 | * False for other failures. |
124 | 124 | */ |
125 | - public static function get_instance( $term_id, $taxonomy = null ) { |
|
125 | + public static function get_instance($term_id, $taxonomy = null) { |
|
126 | 126 | global $wpdb; |
127 | 127 | |
128 | - if ( ! is_numeric( $term_id ) || $term_id != floor( $term_id ) || ! $term_id ) { |
|
128 | + if ( ! is_numeric($term_id) || $term_id != floor($term_id) || ! $term_id) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $term_id = (int) $term_id; |
133 | 133 | |
134 | - $_term = wp_cache_get( $term_id, 'terms' ); |
|
134 | + $_term = wp_cache_get($term_id, 'terms'); |
|
135 | 135 | |
136 | 136 | // If there isn't a cached version, hit the database. |
137 | - if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) { |
|
137 | + if ( ! $_term || ($taxonomy && $taxonomy !== $_term->taxonomy)) { |
|
138 | 138 | // Grab all matching terms, in case any are shared between taxonomies. |
139 | - $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) ); |
|
140 | - if ( ! $terms ) { |
|
139 | + $terms = $wpdb->get_results($wpdb->prepare("SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id)); |
|
140 | + if ( ! $terms) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // If a taxonomy was specified, find a match. |
145 | - if ( $taxonomy ) { |
|
146 | - foreach ( $terms as $match ) { |
|
147 | - if ( $taxonomy === $match->taxonomy ) { |
|
145 | + if ($taxonomy) { |
|
146 | + foreach ($terms as $match) { |
|
147 | + if ($taxonomy === $match->taxonomy) { |
|
148 | 148 | $_term = $match; |
149 | 149 | break; |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | 153 | // If only one match was found, it's the one we want. |
154 | - } elseif ( 1 === count( $terms ) ) { |
|
155 | - $_term = reset( $terms ); |
|
154 | + } elseif (1 === count($terms)) { |
|
155 | + $_term = reset($terms); |
|
156 | 156 | |
157 | 157 | // Otherwise, the term must be shared between taxonomies. |
158 | 158 | } else { |
159 | 159 | // If the term is shared only with invalid taxonomies, return the one valid term. |
160 | - foreach ( $terms as $t ) { |
|
161 | - if ( ! taxonomy_exists( $t->taxonomy ) ) { |
|
160 | + foreach ($terms as $t) { |
|
161 | + if ( ! taxonomy_exists($t->taxonomy)) { |
|
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Only hit if we've already identified a term in a valid taxonomy. |
166 | - if ( $_term ) { |
|
167 | - return new WP_Error( 'ambiguous_term_id', __( 'Term ID is shared between multiple taxonomies' ), $term_id ); |
|
166 | + if ($_term) { |
|
167 | + return new WP_Error('ambiguous_term_id', __('Term ID is shared between multiple taxonomies'), $term_id); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | $_term = $t; |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - if ( ! $_term ) { |
|
174 | + if ( ! $_term) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
178 | 178 | // Don't return terms from invalid taxonomies. |
179 | - if ( ! taxonomy_exists( $_term->taxonomy ) ) { |
|
180 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); |
|
179 | + if ( ! taxonomy_exists($_term->taxonomy)) { |
|
180 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.')); |
|
181 | 181 | } |
182 | 182 | |
183 | - $_term = sanitize_term( $_term, $_term->taxonomy, 'raw' ); |
|
183 | + $_term = sanitize_term($_term, $_term->taxonomy, 'raw'); |
|
184 | 184 | |
185 | 185 | // Don't cache terms that are shared between taxonomies. |
186 | - if ( 1 === count( $terms ) ) { |
|
187 | - wp_cache_add( $term_id, $_term, 'terms' ); |
|
186 | + if (1 === count($terms)) { |
|
187 | + wp_cache_add($term_id, $_term, 'terms'); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - $term_obj = new WP_Term( $_term ); |
|
192 | - $term_obj->filter( $term_obj->filter ); |
|
191 | + $term_obj = new WP_Term($_term); |
|
192 | + $term_obj->filter($term_obj->filter); |
|
193 | 193 | |
194 | 194 | return $term_obj; |
195 | 195 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @param WP_Term|object $term Term object. |
204 | 204 | */ |
205 | - public function __construct( $term ) { |
|
206 | - foreach ( get_object_vars( $term ) as $key => $value ) { |
|
205 | + public function __construct($term) { |
|
206 | + foreach (get_object_vars($term) as $key => $value) { |
|
207 | 207 | $this->$key = $value; |
208 | 208 | } |
209 | 209 | } |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param string $filter Filter context. Accepts 'edit', 'db', 'display', 'attribute', 'js', 'raw'. |
218 | 218 | */ |
219 | - public function filter( $filter ) { |
|
220 | - sanitize_term( $this, $this->taxonomy, $filter ); |
|
219 | + public function filter($filter) { |
|
220 | + sanitize_term($this, $this->taxonomy, $filter); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return array Object as array. |
230 | 230 | */ |
231 | 231 | public function to_array() { |
232 | - return get_object_vars( $this ); |
|
232 | + return get_object_vars($this); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | * @param string $key Property to get. |
242 | 242 | * @return mixed Property value. |
243 | 243 | */ |
244 | - public function __get( $key ) { |
|
245 | - switch ( $key ) { |
|
244 | + public function __get($key) { |
|
245 | + switch ($key) { |
|
246 | 246 | case 'data' : |
247 | 247 | $data = new stdClass(); |
248 | - $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' ); |
|
249 | - foreach ( $columns as $column ) { |
|
250 | - $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null; |
|
248 | + $columns = array('term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count'); |
|
249 | + foreach ($columns as $column) { |
|
250 | + $data->{$column} = isset($this->{$column} ) ? $this->{$column} : null; |
|
251 | 251 | } |
252 | 252 | |
253 | - return sanitize_term( $data, $data->taxonomy, 'raw' ); |
|
253 | + return sanitize_term($data, $data->taxonomy, 'raw'); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | * @param int|string|WP_Term $menu Menu ID, slug, or name - or the menu object. |
16 | 16 | * @return WP_Term|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 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * @param string $location The menu location identifier. |
103 | 103 | * @return bool True on success, false on failure. |
104 | 104 | */ |
105 | -function unregister_nav_menu( $location ) { |
|
105 | +function unregister_nav_menu($location) { |
|
106 | 106 | global $_wp_registered_nav_menus; |
107 | 107 | |
108 | - if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) { |
|
109 | - unset( $_wp_registered_nav_menus[$location] ); |
|
110 | - if ( empty( $_wp_registered_nav_menus ) ) { |
|
111 | - _remove_theme_support( 'menus' ); |
|
108 | + if (is_array($_wp_registered_nav_menus) && isset($_wp_registered_nav_menus[$location])) { |
|
109 | + unset($_wp_registered_nav_menus[$location]); |
|
110 | + if (empty($_wp_registered_nav_menus)) { |
|
111 | + _remove_theme_support('menus'); |
|
112 | 112 | } |
113 | 113 | return true; |
114 | 114 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @param string $location Menu location identifier, like a slug. |
124 | 124 | * @param string $description Menu location descriptive text. |
125 | 125 | */ |
126 | -function register_nav_menu( $location, $description ) { |
|
127 | - register_nav_menus( array( $location => $description ) ); |
|
126 | +function register_nav_menu($location, $description) { |
|
127 | + register_nav_menus(array($location => $description)); |
|
128 | 128 | } |
129 | 129 | /** |
130 | 130 | * Retrieves all registered navigation menu locations in a theme. |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function get_registered_nav_menus() { |
139 | 139 | global $_wp_registered_nav_menus; |
140 | - if ( isset( $_wp_registered_nav_menus ) ) |
|
140 | + if (isset($_wp_registered_nav_menus)) |
|
141 | 141 | return $_wp_registered_nav_menus; |
142 | 142 | return array(); |
143 | 143 | } |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | */ |
153 | 153 | |
154 | 154 | function get_nav_menu_locations() { |
155 | - $locations = get_theme_mod( 'nav_menu_locations' ); |
|
156 | - return ( is_array( $locations ) ) ? $locations : array(); |
|
155 | + $locations = get_theme_mod('nav_menu_locations'); |
|
156 | + return (is_array($locations)) ? $locations : array(); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | * @param string $location Menu location identifier. |
165 | 165 | * @return bool Whether location has a menu. |
166 | 166 | */ |
167 | -function has_nav_menu( $location ) { |
|
167 | +function has_nav_menu($location) { |
|
168 | 168 | $has_nav_menu = false; |
169 | 169 | |
170 | 170 | $registered_nav_menus = get_registered_nav_menus(); |
171 | - if ( isset( $registered_nav_menus[ $location ] ) ) { |
|
171 | + if (isset($registered_nav_menus[$location])) { |
|
172 | 172 | $locations = get_nav_menu_locations(); |
173 | - $has_nav_menu = ! empty( $locations[ $location ] ); |
|
173 | + $has_nav_menu = ! empty($locations[$location]); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param bool $has_nav_menu Whether there is a menu assigned to a location. |
182 | 182 | * @param string $location Menu location. |
183 | 183 | */ |
184 | - return apply_filters( 'has_nav_menu', $has_nav_menu, $location ); |
|
184 | + return apply_filters('has_nav_menu', $has_nav_menu, $location); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * @param int $menu_item_id The ID of the potential nav menu item. |
193 | 193 | * @return bool Whether the given ID is that of a nav menu item. |
194 | 194 | */ |
195 | -function is_nav_menu_item( $menu_item_id = 0 ) { |
|
196 | - return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) ); |
|
195 | +function is_nav_menu_item($menu_item_id = 0) { |
|
196 | + return ( ! is_wp_error($menu_item_id) && ('nav_menu_item' == get_post_type($menu_item_id))); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | * @param string $menu_name Menu name. |
207 | 207 | * @return int|WP_Error Menu ID on success, WP_Error object on failure. |
208 | 208 | */ |
209 | -function wp_create_nav_menu( $menu_name ) { |
|
209 | +function wp_create_nav_menu($menu_name) { |
|
210 | 210 | // expected_slashed ($menu_name) |
211 | - return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) ); |
|
211 | + return wp_update_nav_menu_object(0, array('menu-name' => $menu_name)); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -219,29 +219,29 @@ discard block |
||
219 | 219 | * @param string $menu Menu ID, slug, or name. |
220 | 220 | * @return bool|WP_Error True on success, false or WP_Error object on failure. |
221 | 221 | */ |
222 | -function wp_delete_nav_menu( $menu ) { |
|
223 | - $menu = wp_get_nav_menu_object( $menu ); |
|
224 | - if ( ! $menu ) |
|
222 | +function wp_delete_nav_menu($menu) { |
|
223 | + $menu = wp_get_nav_menu_object($menu); |
|
224 | + if ( ! $menu) |
|
225 | 225 | return false; |
226 | 226 | |
227 | - $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
|
228 | - if ( ! empty( $menu_objects ) ) { |
|
229 | - foreach ( $menu_objects as $item ) { |
|
230 | - wp_delete_post( $item ); |
|
227 | + $menu_objects = get_objects_in_term($menu->term_id, 'nav_menu'); |
|
228 | + if ( ! empty($menu_objects)) { |
|
229 | + foreach ($menu_objects as $item) { |
|
230 | + wp_delete_post($item); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - $result = wp_delete_term( $menu->term_id, 'nav_menu' ); |
|
234 | + $result = wp_delete_term($menu->term_id, 'nav_menu'); |
|
235 | 235 | |
236 | 236 | // Remove this menu from any locations. |
237 | 237 | $locations = get_nav_menu_locations(); |
238 | - foreach ( $locations as $location => $menu_id ) { |
|
239 | - if ( $menu_id == $menu->term_id ) |
|
240 | - $locations[ $location ] = 0; |
|
238 | + foreach ($locations as $location => $menu_id) { |
|
239 | + if ($menu_id == $menu->term_id) |
|
240 | + $locations[$location] = 0; |
|
241 | 241 | } |
242 | - set_theme_mod( 'nav_menu_locations', $locations ); |
|
242 | + set_theme_mod('nav_menu_locations', $locations); |
|
243 | 243 | |
244 | - if ( $result && !is_wp_error($result) ) |
|
244 | + if ($result && ! is_wp_error($result)) |
|
245 | 245 | |
246 | 246 | /** |
247 | 247 | * Fires after a navigation menu has been successfully deleted. |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @param int $term_id ID of the deleted menu. |
252 | 252 | */ |
253 | - do_action( 'wp_delete_nav_menu', $menu->term_id ); |
|
253 | + do_action('wp_delete_nav_menu', $menu->term_id); |
|
254 | 254 | |
255 | 255 | return $result; |
256 | 256 | } |
@@ -266,51 +266,51 @@ discard block |
||
266 | 266 | * @param array $menu_data The array of menu data. |
267 | 267 | * @return int|WP_Error Menu ID on success, WP_Error object on failure. |
268 | 268 | */ |
269 | -function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { |
|
269 | +function wp_update_nav_menu_object($menu_id = 0, $menu_data = array()) { |
|
270 | 270 | // expected_slashed ($menu_data) |
271 | 271 | $menu_id = (int) $menu_id; |
272 | 272 | |
273 | - $_menu = wp_get_nav_menu_object( $menu_id ); |
|
273 | + $_menu = wp_get_nav_menu_object($menu_id); |
|
274 | 274 | |
275 | 275 | $args = array( |
276 | - 'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ), |
|
277 | - 'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ), |
|
278 | - 'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ), |
|
276 | + 'description' => (isset($menu_data['description']) ? $menu_data['description'] : ''), |
|
277 | + 'name' => (isset($menu_data['menu-name']) ? $menu_data['menu-name'] : ''), |
|
278 | + 'parent' => (isset($menu_data['parent']) ? (int) $menu_data['parent'] : 0), |
|
279 | 279 | 'slug' => null, |
280 | 280 | ); |
281 | 281 | |
282 | 282 | // double-check that we're not going to have one menu take the name of another |
283 | - $_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' ); |
|
283 | + $_possible_existing = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); |
|
284 | 284 | if ( |
285 | 285 | $_possible_existing && |
286 | - ! is_wp_error( $_possible_existing ) && |
|
287 | - isset( $_possible_existing->term_id ) && |
|
286 | + ! is_wp_error($_possible_existing) && |
|
287 | + isset($_possible_existing->term_id) && |
|
288 | 288 | $_possible_existing->term_id != $menu_id |
289 | 289 | ) { |
290 | - return new WP_Error( 'menu_exists', |
|
290 | + return new WP_Error('menu_exists', |
|
291 | 291 | /* translators: %s: menu name */ |
292 | - sprintf( __( 'The menu name %s conflicts with another menu name. Please try another.' ), |
|
293 | - '<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>' |
|
292 | + sprintf(__('The menu name %s conflicts with another menu name. Please try another.'), |
|
293 | + '<strong>'.esc_html($menu_data['menu-name']).'</strong>' |
|
294 | 294 | ) |
295 | 295 | ); |
296 | 296 | } |
297 | 297 | |
298 | 298 | // menu doesn't already exist, so create a new menu |
299 | - if ( ! $_menu || is_wp_error( $_menu ) ) { |
|
300 | - $menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' ); |
|
299 | + if ( ! $_menu || is_wp_error($_menu)) { |
|
300 | + $menu_exists = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); |
|
301 | 301 | |
302 | - if ( $menu_exists ) { |
|
303 | - return new WP_Error( 'menu_exists', |
|
302 | + if ($menu_exists) { |
|
303 | + return new WP_Error('menu_exists', |
|
304 | 304 | /* translators: %s: menu name */ |
305 | - sprintf( __( 'The menu name %s conflicts with another menu name. Please try another.' ), |
|
306 | - '<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>' |
|
305 | + sprintf(__('The menu name %s conflicts with another menu name. Please try another.'), |
|
306 | + '<strong>'.esc_html($menu_data['menu-name']).'</strong>' |
|
307 | 307 | ) |
308 | 308 | ); |
309 | 309 | } |
310 | 310 | |
311 | - $_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args ); |
|
311 | + $_menu = wp_insert_term($menu_data['menu-name'], 'nav_menu', $args); |
|
312 | 312 | |
313 | - if ( is_wp_error( $_menu ) ) |
|
313 | + if (is_wp_error($_menu)) |
|
314 | 314 | return $_menu; |
315 | 315 | |
316 | 316 | /** |
@@ -321,19 +321,19 @@ discard block |
||
321 | 321 | * @param int $term_id ID of the new menu. |
322 | 322 | * @param array $menu_data An array of menu data. |
323 | 323 | */ |
324 | - do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data ); |
|
324 | + do_action('wp_create_nav_menu', $_menu['term_id'], $menu_data); |
|
325 | 325 | |
326 | 326 | return (int) $_menu['term_id']; |
327 | 327 | } |
328 | 328 | |
329 | - if ( ! $_menu || ! isset( $_menu->term_id ) ) |
|
329 | + if ( ! $_menu || ! isset($_menu->term_id)) |
|
330 | 330 | return 0; |
331 | 331 | |
332 | 332 | $menu_id = (int) $_menu->term_id; |
333 | 333 | |
334 | - $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); |
|
334 | + $update_response = wp_update_term($menu_id, 'nav_menu', $args); |
|
335 | 335 | |
336 | - if ( is_wp_error( $update_response ) ) |
|
336 | + if (is_wp_error($update_response)) |
|
337 | 337 | return $update_response; |
338 | 338 | |
339 | 339 | $menu_id = (int) $update_response['term_id']; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param int $menu_id ID of the updated menu. |
347 | 347 | * @param array $menu_data An array of menu data. |
348 | 348 | */ |
349 | - do_action( 'wp_update_nav_menu', $menu_id, $menu_data ); |
|
349 | + do_action('wp_update_nav_menu', $menu_id, $menu_data); |
|
350 | 350 | return $menu_id; |
351 | 351 | } |
352 | 352 | |
@@ -363,21 +363,21 @@ discard block |
||
363 | 363 | * @param array $menu_item_data The menu item's data. |
364 | 364 | * @return int|WP_Error The menu item's database ID or WP_Error object on failure. |
365 | 365 | */ |
366 | -function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) { |
|
366 | +function wp_update_nav_menu_item($menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array()) { |
|
367 | 367 | $menu_id = (int) $menu_id; |
368 | 368 | $menu_item_db_id = (int) $menu_item_db_id; |
369 | 369 | |
370 | 370 | // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects |
371 | - if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) |
|
372 | - return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
371 | + if ( ! empty($menu_item_db_id) && ! is_nav_menu_item($menu_item_db_id)) |
|
372 | + return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.')); |
|
373 | 373 | |
374 | - $menu = wp_get_nav_menu_object( $menu_id ); |
|
374 | + $menu = wp_get_nav_menu_object($menu_id); |
|
375 | 375 | |
376 | - if ( ! $menu && 0 !== $menu_id ) { |
|
377 | - return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) ); |
|
376 | + if ( ! $menu && 0 !== $menu_id) { |
|
377 | + return new WP_Error('invalid_menu_id', __('Invalid menu ID.')); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( is_wp_error( $menu ) ) { |
|
380 | + if (is_wp_error($menu)) { |
|
381 | 381 | return $menu; |
382 | 382 | } |
383 | 383 | |
@@ -398,19 +398,19 @@ discard block |
||
398 | 398 | 'menu-item-status' => '', |
399 | 399 | ); |
400 | 400 | |
401 | - $args = wp_parse_args( $menu_item_data, $defaults ); |
|
401 | + $args = wp_parse_args($menu_item_data, $defaults); |
|
402 | 402 | |
403 | - if ( 0 == $menu_id ) { |
|
403 | + if (0 == $menu_id) { |
|
404 | 404 | $args['menu-item-position'] = 1; |
405 | - } elseif ( 0 == (int) $args['menu-item-position'] ) { |
|
406 | - $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
|
407 | - $last_item = array_pop( $menu_items ); |
|
408 | - $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items ); |
|
405 | + } elseif (0 == (int) $args['menu-item-position']) { |
|
406 | + $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft')); |
|
407 | + $last_item = array_pop($menu_items); |
|
408 | + $args['menu-item-position'] = ($last_item && isset($last_item->menu_order)) ? 1 + $last_item->menu_order : count($menu_items); |
|
409 | 409 | } |
410 | 410 | |
411 | - $original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0; |
|
411 | + $original_parent = 0 < $menu_item_db_id ? get_post_field('post_parent', $menu_item_db_id) : 0; |
|
412 | 412 | |
413 | - if ( 'custom' != $args['menu-item-type'] ) { |
|
413 | + if ('custom' != $args['menu-item-type']) { |
|
414 | 414 | /* if non-custom menu item, then: |
415 | 415 | * use original object's URL |
416 | 416 | * blank default title to sync with original object's |
@@ -419,26 +419,26 @@ discard block |
||
419 | 419 | $args['menu-item-url'] = ''; |
420 | 420 | |
421 | 421 | $original_title = ''; |
422 | - if ( 'taxonomy' == $args['menu-item-type'] ) { |
|
423 | - $original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); |
|
424 | - $original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); |
|
425 | - } elseif ( 'post_type' == $args['menu-item-type'] ) { |
|
422 | + if ('taxonomy' == $args['menu-item-type']) { |
|
423 | + $original_parent = get_term_field('parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); |
|
424 | + $original_title = get_term_field('name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); |
|
425 | + } elseif ('post_type' == $args['menu-item-type']) { |
|
426 | 426 | |
427 | - $original_object = get_post( $args['menu-item-object-id'] ); |
|
427 | + $original_object = get_post($args['menu-item-object-id']); |
|
428 | 428 | $original_parent = (int) $original_object->post_parent; |
429 | 429 | $original_title = $original_object->post_title; |
430 | - } elseif ( 'post_type_archive' == $args['menu-item-type'] ) { |
|
431 | - $original_object = get_post_type_object( $args['menu-item-object'] ); |
|
432 | - if ( $original_object ) { |
|
430 | + } elseif ('post_type_archive' == $args['menu-item-type']) { |
|
431 | + $original_object = get_post_type_object($args['menu-item-object']); |
|
432 | + if ($original_object) { |
|
433 | 433 | $original_title = $original_object->labels->archives; |
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | - if ( $args['menu-item-title'] == $original_title ) |
|
437 | + if ($args['menu-item-title'] == $original_title) |
|
438 | 438 | $args['menu-item-title'] = ''; |
439 | 439 | |
440 | 440 | // hack to get wp to create a post object when too many properties are empty |
441 | - if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) |
|
441 | + if ('' == $args['menu-item-title'] && '' == $args['menu-item-description']) |
|
442 | 442 | $args['menu-item-description'] = ' '; |
443 | 443 | } |
444 | 444 | |
@@ -456,11 +456,11 @@ discard block |
||
456 | 456 | $update = 0 != $menu_item_db_id; |
457 | 457 | |
458 | 458 | // New menu item. Default is draft status |
459 | - if ( ! $update ) { |
|
459 | + if ( ! $update) { |
|
460 | 460 | $post['ID'] = 0; |
461 | 461 | $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; |
462 | - $menu_item_db_id = wp_insert_post( $post ); |
|
463 | - if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) |
|
462 | + $menu_item_db_id = wp_insert_post($post); |
|
463 | + if ( ! $menu_item_db_id || is_wp_error($menu_item_db_id)) |
|
464 | 464 | return $menu_item_db_id; |
465 | 465 | |
466 | 466 | /** |
@@ -474,44 +474,44 @@ discard block |
||
474 | 474 | * @param int $menu_item_db_id ID of the new menu item. |
475 | 475 | * @param array $args An array of arguments used to update/add the menu item. |
476 | 476 | */ |
477 | - do_action( 'wp_add_nav_menu_item', $menu_id, $menu_item_db_id, $args ); |
|
477 | + do_action('wp_add_nav_menu_item', $menu_id, $menu_item_db_id, $args); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | // Associate the menu item with the menu term |
481 | 481 | // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms() |
482 | - if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) { |
|
483 | - wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' ); |
|
482 | + if ($menu_id && ( ! $update || ! is_object_in_term($menu_item_db_id, 'nav_menu', (int) $menu->term_id))) { |
|
483 | + wp_set_object_terms($menu_item_db_id, array($menu->term_id), 'nav_menu'); |
|
484 | 484 | } |
485 | 485 | |
486 | - if ( 'custom' == $args['menu-item-type'] ) { |
|
486 | + if ('custom' == $args['menu-item-type']) { |
|
487 | 487 | $args['menu-item-object-id'] = $menu_item_db_id; |
488 | 488 | $args['menu-item-object'] = 'custom'; |
489 | 489 | } |
490 | 490 | |
491 | 491 | $menu_item_db_id = (int) $menu_item_db_id; |
492 | 492 | |
493 | - update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) ); |
|
494 | - update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) ); |
|
495 | - update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) ); |
|
496 | - update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) ); |
|
497 | - update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) ); |
|
493 | + update_post_meta($menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type'])); |
|
494 | + update_post_meta($menu_item_db_id, '_menu_item_menu_item_parent', strval((int) $args['menu-item-parent-id'])); |
|
495 | + update_post_meta($menu_item_db_id, '_menu_item_object_id', strval((int) $args['menu-item-object-id'])); |
|
496 | + update_post_meta($menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object'])); |
|
497 | + update_post_meta($menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target'])); |
|
498 | 498 | |
499 | - $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) ); |
|
500 | - $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) ); |
|
501 | - update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] ); |
|
502 | - update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); |
|
503 | - update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); |
|
499 | + $args['menu-item-classes'] = array_map('sanitize_html_class', explode(' ', $args['menu-item-classes'])); |
|
500 | + $args['menu-item-xfn'] = implode(' ', array_map('sanitize_html_class', explode(' ', $args['menu-item-xfn']))); |
|
501 | + update_post_meta($menu_item_db_id, '_menu_item_classes', $args['menu-item-classes']); |
|
502 | + update_post_meta($menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn']); |
|
503 | + update_post_meta($menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url'])); |
|
504 | 504 | |
505 | - if ( 0 == $menu_id ) |
|
506 | - update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
507 | - elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) |
|
508 | - delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
505 | + if (0 == $menu_id) |
|
506 | + update_post_meta($menu_item_db_id, '_menu_item_orphaned', (string) time()); |
|
507 | + elseif (get_post_meta($menu_item_db_id, '_menu_item_orphaned')) |
|
508 | + delete_post_meta($menu_item_db_id, '_menu_item_orphaned'); |
|
509 | 509 | |
510 | 510 | // Update existing menu item. Default is publish status |
511 | - if ( $update ) { |
|
511 | + if ($update) { |
|
512 | 512 | $post['ID'] = $menu_item_db_id; |
513 | 513 | $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; |
514 | - wp_update_post( $post ); |
|
514 | + wp_update_post($post); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | * @param int $menu_item_db_id ID of the updated menu item. |
526 | 526 | * @param array $args An array of arguments used to update a menu item. |
527 | 527 | */ |
528 | - do_action( 'wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args ); |
|
528 | + do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args); |
|
529 | 529 | |
530 | 530 | return $menu_item_db_id; |
531 | 531 | } |
@@ -541,9 +541,9 @@ discard block |
||
541 | 541 | * Default empty array. |
542 | 542 | * @return array Menu objects. |
543 | 543 | */ |
544 | -function wp_get_nav_menus( $args = array() ) { |
|
545 | - $defaults = array( 'hide_empty' => false, 'orderby' => 'name' ); |
|
546 | - $args = wp_parse_args( $args, $defaults ); |
|
544 | +function wp_get_nav_menus($args = array()) { |
|
545 | + $defaults = array('hide_empty' => false, 'orderby' => 'name'); |
|
546 | + $args = wp_parse_args($args, $defaults); |
|
547 | 547 | |
548 | 548 | /** |
549 | 549 | * Filters the navigation menu objects being returned. |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @param array $menus An array of menu objects. |
556 | 556 | * @param array $args An array of arguments used to retrieve menu objects. |
557 | 557 | */ |
558 | - return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu', $args), $args ); |
|
558 | + return apply_filters('wp_get_nav_menus', get_terms('nav_menu', $args), $args); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | * @param object $item The menu item to check. |
570 | 570 | * @return bool False if invalid, otherwise true. |
571 | 571 | */ |
572 | -function _is_valid_nav_menu_item( $item ) { |
|
573 | - return empty( $item->_invalid ); |
|
572 | +function _is_valid_nav_menu_item($item) { |
|
573 | + return empty($item->_invalid); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -585,77 +585,77 @@ discard block |
||
585 | 585 | * @param array $args Optional. Arguments to pass to get_posts(). |
586 | 586 | * @return false|array $items Array of menu items, otherwise false. |
587 | 587 | */ |
588 | -function wp_get_nav_menu_items( $menu, $args = array() ) { |
|
589 | - $menu = wp_get_nav_menu_object( $menu ); |
|
588 | +function wp_get_nav_menu_items($menu, $args = array()) { |
|
589 | + $menu = wp_get_nav_menu_object($menu); |
|
590 | 590 | |
591 | - if ( ! $menu ) { |
|
591 | + if ( ! $menu) { |
|
592 | 592 | return false; |
593 | 593 | } |
594 | 594 | |
595 | 595 | static $fetched = array(); |
596 | 596 | |
597 | - $items = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
|
598 | - if ( is_wp_error( $items ) ) { |
|
597 | + $items = get_objects_in_term($menu->term_id, 'nav_menu'); |
|
598 | + if (is_wp_error($items)) { |
|
599 | 599 | return false; |
600 | 600 | } |
601 | 601 | |
602 | - $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', |
|
603 | - 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true ); |
|
604 | - $args = wp_parse_args( $args, $defaults ); |
|
602 | + $defaults = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', |
|
603 | + 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true); |
|
604 | + $args = wp_parse_args($args, $defaults); |
|
605 | 605 | $args['include'] = $items; |
606 | 606 | |
607 | - if ( ! empty( $items ) ) { |
|
608 | - $items = get_posts( $args ); |
|
607 | + if ( ! empty($items)) { |
|
608 | + $items = get_posts($args); |
|
609 | 609 | } else { |
610 | 610 | $items = array(); |
611 | 611 | } |
612 | 612 | |
613 | 613 | // Get all posts and terms at once to prime the caches |
614 | - if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) { |
|
614 | + if (empty($fetched[$menu->term_id]) || wp_using_ext_object_cache()) { |
|
615 | 615 | $fetched[$menu->term_id] = true; |
616 | 616 | $posts = array(); |
617 | 617 | $terms = array(); |
618 | - foreach ( $items as $item ) { |
|
619 | - $object_id = get_post_meta( $item->ID, '_menu_item_object_id', true ); |
|
620 | - $object = get_post_meta( $item->ID, '_menu_item_object', true ); |
|
621 | - $type = get_post_meta( $item->ID, '_menu_item_type', true ); |
|
618 | + foreach ($items as $item) { |
|
619 | + $object_id = get_post_meta($item->ID, '_menu_item_object_id', true); |
|
620 | + $object = get_post_meta($item->ID, '_menu_item_object', true); |
|
621 | + $type = get_post_meta($item->ID, '_menu_item_type', true); |
|
622 | 622 | |
623 | - if ( 'post_type' == $type ) |
|
623 | + if ('post_type' == $type) |
|
624 | 624 | $posts[$object][] = $object_id; |
625 | - elseif ( 'taxonomy' == $type) |
|
625 | + elseif ('taxonomy' == $type) |
|
626 | 626 | $terms[$object][] = $object_id; |
627 | 627 | } |
628 | 628 | |
629 | - if ( ! empty( $posts ) ) { |
|
630 | - foreach ( array_keys($posts) as $post_type ) { |
|
631 | - get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) ); |
|
629 | + if ( ! empty($posts)) { |
|
630 | + foreach (array_keys($posts) as $post_type) { |
|
631 | + get_posts(array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false)); |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | unset($posts); |
635 | 635 | |
636 | - if ( ! empty( $terms ) ) { |
|
637 | - foreach ( array_keys($terms) as $taxonomy ) { |
|
638 | - get_terms( $taxonomy, array( |
|
639 | - 'include' => $terms[ $taxonomy ], |
|
636 | + if ( ! empty($terms)) { |
|
637 | + foreach (array_keys($terms) as $taxonomy) { |
|
638 | + get_terms($taxonomy, array( |
|
639 | + 'include' => $terms[$taxonomy], |
|
640 | 640 | 'hierarchical' => false, |
641 | - ) ); |
|
641 | + )); |
|
642 | 642 | } |
643 | 643 | } |
644 | 644 | unset($terms); |
645 | 645 | } |
646 | 646 | |
647 | - $items = array_map( 'wp_setup_nav_menu_item', $items ); |
|
647 | + $items = array_map('wp_setup_nav_menu_item', $items); |
|
648 | 648 | |
649 | - if ( ! is_admin() ) { // Remove invalid items only in front end |
|
650 | - $items = array_filter( $items, '_is_valid_nav_menu_item' ); |
|
649 | + if ( ! is_admin()) { // Remove invalid items only in front end |
|
650 | + $items = array_filter($items, '_is_valid_nav_menu_item'); |
|
651 | 651 | } |
652 | 652 | |
653 | - if ( ARRAY_A == $args['output'] ) { |
|
654 | - $items = wp_list_sort( $items, array( |
|
653 | + if (ARRAY_A == $args['output']) { |
|
654 | + $items = wp_list_sort($items, array( |
|
655 | 655 | $args['output_key'] => 'ASC', |
656 | - ) ); |
|
656 | + )); |
|
657 | 657 | $i = 1; |
658 | - foreach ( $items as $k => $item ) { |
|
658 | + foreach ($items as $k => $item) { |
|
659 | 659 | $items[$k]->{$args['output_key']} = $i++; |
660 | 660 | } |
661 | 661 | } |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | * @param object $menu The menu object. |
670 | 670 | * @param array $args An array of arguments used to retrieve menu item objects. |
671 | 671 | */ |
672 | - return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); |
|
672 | + return apply_filters('wp_get_nav_menu_items', $items, $menu, $args); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -699,44 +699,44 @@ discard block |
||
699 | 699 | * @param object $menu_item The menu item to modify. |
700 | 700 | * @return object $menu_item The menu item with standard menu item properties. |
701 | 701 | */ |
702 | -function wp_setup_nav_menu_item( $menu_item ) { |
|
703 | - if ( isset( $menu_item->post_type ) ) { |
|
704 | - if ( 'nav_menu_item' == $menu_item->post_type ) { |
|
702 | +function wp_setup_nav_menu_item($menu_item) { |
|
703 | + if (isset($menu_item->post_type)) { |
|
704 | + if ('nav_menu_item' == $menu_item->post_type) { |
|
705 | 705 | $menu_item->db_id = (int) $menu_item->ID; |
706 | - $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; |
|
707 | - $menu_item->object_id = ! isset( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id; |
|
708 | - $menu_item->object = ! isset( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object; |
|
709 | - $menu_item->type = ! isset( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; |
|
710 | - |
|
711 | - if ( 'post_type' == $menu_item->type ) { |
|
712 | - $object = get_post_type_object( $menu_item->object ); |
|
713 | - if ( $object ) { |
|
706 | + $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; |
|
707 | + $menu_item->object_id = ! isset($menu_item->object_id) ? get_post_meta($menu_item->ID, '_menu_item_object_id', true) : $menu_item->object_id; |
|
708 | + $menu_item->object = ! isset($menu_item->object) ? get_post_meta($menu_item->ID, '_menu_item_object', true) : $menu_item->object; |
|
709 | + $menu_item->type = ! isset($menu_item->type) ? get_post_meta($menu_item->ID, '_menu_item_type', true) : $menu_item->type; |
|
710 | + |
|
711 | + if ('post_type' == $menu_item->type) { |
|
712 | + $object = get_post_type_object($menu_item->object); |
|
713 | + if ($object) { |
|
714 | 714 | $menu_item->type_label = $object->labels->singular_name; |
715 | 715 | } else { |
716 | 716 | $menu_item->type_label = $menu_item->object; |
717 | 717 | $menu_item->_invalid = true; |
718 | 718 | } |
719 | 719 | |
720 | - if ( 'trash' === get_post_status( $menu_item->object_id ) ) { |
|
720 | + if ('trash' === get_post_status($menu_item->object_id)) { |
|
721 | 721 | $menu_item->_invalid = true; |
722 | 722 | } |
723 | 723 | |
724 | - $menu_item->url = get_permalink( $menu_item->object_id ); |
|
724 | + $menu_item->url = get_permalink($menu_item->object_id); |
|
725 | 725 | |
726 | - $original_object = get_post( $menu_item->object_id ); |
|
726 | + $original_object = get_post($menu_item->object_id); |
|
727 | 727 | /** This filter is documented in wp-includes/post-template.php */ |
728 | - $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID ); |
|
728 | + $original_title = apply_filters('the_title', $original_object->post_title, $original_object->ID); |
|
729 | 729 | |
730 | - if ( '' === $original_title ) { |
|
730 | + if ('' === $original_title) { |
|
731 | 731 | /* translators: %d: ID of a post */ |
732 | - $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); |
|
732 | + $original_title = sprintf(__('#%d (no title)'), $original_object->ID); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
736 | 736 | |
737 | - } elseif ( 'post_type_archive' == $menu_item->type ) { |
|
738 | - $object = get_post_type_object( $menu_item->object ); |
|
739 | - if ( $object ) { |
|
737 | + } elseif ('post_type_archive' == $menu_item->type) { |
|
738 | + $object = get_post_type_object($menu_item->object); |
|
739 | + if ($object) { |
|
740 | 740 | $menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title; |
741 | 741 | $post_type_description = $object->description; |
742 | 742 | } else { |
@@ -744,34 +744,34 @@ discard block |
||
744 | 744 | $post_type_description = ''; |
745 | 745 | } |
746 | 746 | |
747 | - $menu_item->type_label = __( 'Post Type Archive' ); |
|
748 | - $post_content = wp_trim_words( $menu_item->post_content, 200 ); |
|
747 | + $menu_item->type_label = __('Post Type Archive'); |
|
748 | + $post_content = wp_trim_words($menu_item->post_content, 200); |
|
749 | 749 | $post_type_description = '' == $post_content ? $post_type_description : $post_content; |
750 | - $menu_item->url = get_post_type_archive_link( $menu_item->object ); |
|
751 | - } elseif ( 'taxonomy' == $menu_item->type ) { |
|
752 | - $object = get_taxonomy( $menu_item->object ); |
|
753 | - if ( $object ) { |
|
750 | + $menu_item->url = get_post_type_archive_link($menu_item->object); |
|
751 | + } elseif ('taxonomy' == $menu_item->type) { |
|
752 | + $object = get_taxonomy($menu_item->object); |
|
753 | + if ($object) { |
|
754 | 754 | $menu_item->type_label = $object->labels->singular_name; |
755 | 755 | } else { |
756 | 756 | $menu_item->type_label = $menu_item->object; |
757 | 757 | $menu_item->_invalid = true; |
758 | 758 | } |
759 | 759 | |
760 | - $term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); |
|
761 | - $menu_item->url = !is_wp_error( $term_url ) ? $term_url : ''; |
|
760 | + $term_url = get_term_link((int) $menu_item->object_id, $menu_item->object); |
|
761 | + $menu_item->url = ! is_wp_error($term_url) ? $term_url : ''; |
|
762 | 762 | |
763 | - $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); |
|
764 | - if ( is_wp_error( $original_title ) ) |
|
763 | + $original_title = get_term_field('name', $menu_item->object_id, $menu_item->object, 'raw'); |
|
764 | + if (is_wp_error($original_title)) |
|
765 | 765 | $original_title = false; |
766 | 766 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
767 | 767 | |
768 | 768 | } else { |
769 | 769 | $menu_item->type_label = __('Custom Link'); |
770 | 770 | $menu_item->title = $menu_item->post_title; |
771 | - $menu_item->url = ! isset( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url; |
|
771 | + $menu_item->url = ! isset($menu_item->url) ? get_post_meta($menu_item->ID, '_menu_item_url', true) : $menu_item->url; |
|
772 | 772 | } |
773 | 773 | |
774 | - $menu_item->target = ! isset( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target; |
|
774 | + $menu_item->target = ! isset($menu_item->target) ? get_post_meta($menu_item->ID, '_menu_item_target', true) : $menu_item->target; |
|
775 | 775 | |
776 | 776 | /** |
777 | 777 | * Filters a navigation menu item's title attribute. |
@@ -780,9 +780,9 @@ discard block |
||
780 | 780 | * |
781 | 781 | * @param string $item_title The menu item title attribute. |
782 | 782 | */ |
783 | - $menu_item->attr_title = ! isset( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title; |
|
783 | + $menu_item->attr_title = ! isset($menu_item->attr_title) ? apply_filters('nav_menu_attr_title', $menu_item->post_excerpt) : $menu_item->attr_title; |
|
784 | 784 | |
785 | - if ( ! isset( $menu_item->description ) ) { |
|
785 | + if ( ! isset($menu_item->description)) { |
|
786 | 786 | /** |
787 | 787 | * Filters a navigation menu item's description. |
788 | 788 | * |
@@ -790,39 +790,39 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @param string $description The menu item description. |
792 | 792 | */ |
793 | - $menu_item->description = apply_filters( 'nav_menu_description', wp_trim_words( $menu_item->post_content, 200 ) ); |
|
793 | + $menu_item->description = apply_filters('nav_menu_description', wp_trim_words($menu_item->post_content, 200)); |
|
794 | 794 | } |
795 | 795 | |
796 | - $menu_item->classes = ! isset( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes; |
|
797 | - $menu_item->xfn = ! isset( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn; |
|
796 | + $menu_item->classes = ! isset($menu_item->classes) ? (array) get_post_meta($menu_item->ID, '_menu_item_classes', true) : $menu_item->classes; |
|
797 | + $menu_item->xfn = ! isset($menu_item->xfn) ? get_post_meta($menu_item->ID, '_menu_item_xfn', true) : $menu_item->xfn; |
|
798 | 798 | } else { |
799 | 799 | $menu_item->db_id = 0; |
800 | 800 | $menu_item->menu_item_parent = 0; |
801 | 801 | $menu_item->object_id = (int) $menu_item->ID; |
802 | 802 | $menu_item->type = 'post_type'; |
803 | 803 | |
804 | - $object = get_post_type_object( $menu_item->post_type ); |
|
804 | + $object = get_post_type_object($menu_item->post_type); |
|
805 | 805 | $menu_item->object = $object->name; |
806 | 806 | $menu_item->type_label = $object->labels->singular_name; |
807 | 807 | |
808 | - if ( '' === $menu_item->post_title ) { |
|
808 | + if ('' === $menu_item->post_title) { |
|
809 | 809 | /* translators: %d: ID of a post */ |
810 | - $menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID ); |
|
810 | + $menu_item->post_title = sprintf(__('#%d (no title)'), $menu_item->ID); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | $menu_item->title = $menu_item->post_title; |
814 | - $menu_item->url = get_permalink( $menu_item->ID ); |
|
814 | + $menu_item->url = get_permalink($menu_item->ID); |
|
815 | 815 | $menu_item->target = ''; |
816 | 816 | |
817 | 817 | /** This filter is documented in wp-includes/nav-menu.php */ |
818 | - $menu_item->attr_title = apply_filters( 'nav_menu_attr_title', '' ); |
|
818 | + $menu_item->attr_title = apply_filters('nav_menu_attr_title', ''); |
|
819 | 819 | |
820 | 820 | /** This filter is documented in wp-includes/nav-menu.php */ |
821 | - $menu_item->description = apply_filters( 'nav_menu_description', '' ); |
|
821 | + $menu_item->description = apply_filters('nav_menu_description', ''); |
|
822 | 822 | $menu_item->classes = array(); |
823 | 823 | $menu_item->xfn = ''; |
824 | 824 | } |
825 | - } elseif ( isset( $menu_item->taxonomy ) ) { |
|
825 | + } elseif (isset($menu_item->taxonomy)) { |
|
826 | 826 | $menu_item->ID = $menu_item->term_id; |
827 | 827 | $menu_item->db_id = 0; |
828 | 828 | $menu_item->menu_item_parent = 0; |
@@ -830,15 +830,15 @@ discard block |
||
830 | 830 | $menu_item->post_parent = (int) $menu_item->parent; |
831 | 831 | $menu_item->type = 'taxonomy'; |
832 | 832 | |
833 | - $object = get_taxonomy( $menu_item->taxonomy ); |
|
833 | + $object = get_taxonomy($menu_item->taxonomy); |
|
834 | 834 | $menu_item->object = $object->name; |
835 | 835 | $menu_item->type_label = $object->labels->singular_name; |
836 | 836 | |
837 | 837 | $menu_item->title = $menu_item->name; |
838 | - $menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy ); |
|
838 | + $menu_item->url = get_term_link($menu_item, $menu_item->taxonomy); |
|
839 | 839 | $menu_item->target = ''; |
840 | 840 | $menu_item->attr_title = ''; |
841 | - $menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy ); |
|
841 | + $menu_item->description = get_term_field('description', $menu_item->term_id, $menu_item->taxonomy); |
|
842 | 842 | $menu_item->classes = array(); |
843 | 843 | $menu_item->xfn = ''; |
844 | 844 | |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | * |
852 | 852 | * @param object $menu_item The menu item object. |
853 | 853 | */ |
854 | - return apply_filters( 'wp_setup_nav_menu_item', $menu_item ); |
|
854 | + return apply_filters('wp_setup_nav_menu_item', $menu_item); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | * @param string $taxonomy If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to |
865 | 865 | * @return array The array of menu item IDs; empty array if none; |
866 | 866 | */ |
867 | -function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) { |
|
867 | +function wp_get_associated_nav_menu_items($object_id = 0, $object_type = 'post_type', $taxonomy = '') { |
|
868 | 868 | $object_id = (int) $object_id; |
869 | 869 | $menu_item_ids = array(); |
870 | 870 | |
@@ -878,9 +878,9 @@ discard block |
||
878 | 878 | 'posts_per_page' => -1, |
879 | 879 | ) |
880 | 880 | ); |
881 | - foreach ( (array) $menu_items as $menu_item ) { |
|
882 | - if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { |
|
883 | - $menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); |
|
881 | + foreach ((array) $menu_items as $menu_item) { |
|
882 | + if (isset($menu_item->ID) && is_nav_menu_item($menu_item->ID)) { |
|
883 | + $menu_item_type = get_post_meta($menu_item->ID, '_menu_item_type', true); |
|
884 | 884 | if ( |
885 | 885 | 'post_type' == $object_type && |
886 | 886 | 'post_type' == $menu_item_type |
@@ -889,14 +889,14 @@ discard block |
||
889 | 889 | } elseif ( |
890 | 890 | 'taxonomy' == $object_type && |
891 | 891 | 'taxonomy' == $menu_item_type && |
892 | - get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy |
|
892 | + get_post_meta($menu_item->ID, '_menu_item_object', true) == $taxonomy |
|
893 | 893 | ) { |
894 | 894 | $menu_item_ids[] = (int) $menu_item->ID; |
895 | 895 | } |
896 | 896 | } |
897 | 897 | } |
898 | 898 | |
899 | - return array_unique( $menu_item_ids ); |
|
899 | + return array_unique($menu_item_ids); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | /** |
@@ -908,13 +908,13 @@ discard block |
||
908 | 908 | * @param int $object_id The ID of the original object being trashed. |
909 | 909 | * |
910 | 910 | */ |
911 | -function _wp_delete_post_menu_item( $object_id = 0 ) { |
|
911 | +function _wp_delete_post_menu_item($object_id = 0) { |
|
912 | 912 | $object_id = (int) $object_id; |
913 | 913 | |
914 | - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' ); |
|
914 | + $menu_item_ids = wp_get_associated_nav_menu_items($object_id, 'post_type'); |
|
915 | 915 | |
916 | - foreach ( (array) $menu_item_ids as $menu_item_id ) { |
|
917 | - wp_delete_post( $menu_item_id, true ); |
|
916 | + foreach ((array) $menu_item_ids as $menu_item_id) { |
|
917 | + wp_delete_post($menu_item_id, true); |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | |
@@ -928,13 +928,13 @@ discard block |
||
928 | 928 | * @param int $tt_id Term taxonomy ID. Unused. |
929 | 929 | * @param string $taxonomy Taxonomy slug. |
930 | 930 | */ |
931 | -function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) { |
|
931 | +function _wp_delete_tax_menu_item($object_id = 0, $tt_id, $taxonomy) { |
|
932 | 932 | $object_id = (int) $object_id; |
933 | 933 | |
934 | - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy ); |
|
934 | + $menu_item_ids = wp_get_associated_nav_menu_items($object_id, 'taxonomy', $taxonomy); |
|
935 | 935 | |
936 | - foreach ( (array) $menu_item_ids as $menu_item_id ) { |
|
937 | - wp_delete_post( $menu_item_id, true ); |
|
936 | + foreach ((array) $menu_item_ids as $menu_item_id) { |
|
937 | + wp_delete_post($menu_item_id, true); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
@@ -948,16 +948,16 @@ discard block |
||
948 | 948 | * @param string $old_status The old status of the post object. |
949 | 949 | * @param object $post The post object being transitioned from one status to another. |
950 | 950 | */ |
951 | -function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { |
|
952 | - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) |
|
951 | +function _wp_auto_add_pages_to_menu($new_status, $old_status, $post) { |
|
952 | + if ('publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type) |
|
953 | 953 | return; |
954 | - if ( ! empty( $post->post_parent ) ) |
|
954 | + if ( ! empty($post->post_parent)) |
|
955 | 955 | return; |
956 | - $auto_add = get_option( 'nav_menu_options' ); |
|
957 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) |
|
956 | + $auto_add = get_option('nav_menu_options'); |
|
957 | + if (empty($auto_add) || ! is_array($auto_add) || ! isset($auto_add['auto_add'])) |
|
958 | 958 | return; |
959 | 959 | $auto_add = $auto_add['auto_add']; |
960 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) ) |
|
960 | + if (empty($auto_add) || ! is_array($auto_add)) |
|
961 | 961 | return; |
962 | 962 | |
963 | 963 | $args = array( |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | 'menu-item-status' => 'publish', |
968 | 968 | ); |
969 | 969 | |
970 | - foreach ( $auto_add as $menu_id ) { |
|
971 | - $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
|
972 | - if ( ! is_array( $items ) ) |
|
970 | + foreach ($auto_add as $menu_id) { |
|
971 | + $items = wp_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft')); |
|
972 | + if ( ! is_array($items)) |
|
973 | 973 | continue; |
974 | - foreach ( $items as $item ) { |
|
975 | - if ( $post->ID == $item->object_id ) |
|
974 | + foreach ($items as $item) { |
|
975 | + if ($post->ID == $item->object_id) |
|
976 | 976 | continue 2; |
977 | 977 | } |
978 | - wp_update_nav_menu_item( $menu_id, 0, $args ); |
|
978 | + wp_update_nav_menu_item($menu_id, 0, $args); |
|
979 | 979 | } |
980 | 980 | } |
@@ -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 | } |
@@ -137,8 +139,9 @@ discard block |
||
137 | 139 | */ |
138 | 140 | function get_registered_nav_menus() { |
139 | 141 | global $_wp_registered_nav_menus; |
140 | - if ( isset( $_wp_registered_nav_menus ) ) |
|
141 | - return $_wp_registered_nav_menus; |
|
142 | + if ( isset( $_wp_registered_nav_menus ) ) { |
|
143 | + return $_wp_registered_nav_menus; |
|
144 | + } |
|
142 | 145 | return array(); |
143 | 146 | } |
144 | 147 | |
@@ -221,8 +224,9 @@ discard block |
||
221 | 224 | */ |
222 | 225 | function wp_delete_nav_menu( $menu ) { |
223 | 226 | $menu = wp_get_nav_menu_object( $menu ); |
224 | - if ( ! $menu ) |
|
225 | - return false; |
|
227 | + if ( ! $menu ) { |
|
228 | + return false; |
|
229 | + } |
|
226 | 230 | |
227 | 231 | $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); |
228 | 232 | if ( ! empty( $menu_objects ) ) { |
@@ -236,13 +240,14 @@ discard block |
||
236 | 240 | // Remove this menu from any locations. |
237 | 241 | $locations = get_nav_menu_locations(); |
238 | 242 | foreach ( $locations as $location => $menu_id ) { |
239 | - if ( $menu_id == $menu->term_id ) |
|
240 | - $locations[ $location ] = 0; |
|
243 | + if ( $menu_id == $menu->term_id ) { |
|
244 | + $locations[ $location ] = 0; |
|
245 | + } |
|
241 | 246 | } |
242 | 247 | set_theme_mod( 'nav_menu_locations', $locations ); |
243 | 248 | |
244 | - if ( $result && !is_wp_error($result) ) |
|
245 | - |
|
249 | + if ( $result && !is_wp_error($result) ) { |
|
250 | + |
|
246 | 251 | /** |
247 | 252 | * Fires after a navigation menu has been successfully deleted. |
248 | 253 | * |
@@ -251,6 +256,7 @@ discard block |
||
251 | 256 | * @param int $term_id ID of the deleted menu. |
252 | 257 | */ |
253 | 258 | do_action( 'wp_delete_nav_menu', $menu->term_id ); |
259 | + } |
|
254 | 260 | |
255 | 261 | return $result; |
256 | 262 | } |
@@ -310,8 +316,9 @@ discard block |
||
310 | 316 | |
311 | 317 | $_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args ); |
312 | 318 | |
313 | - if ( is_wp_error( $_menu ) ) |
|
314 | - return $_menu; |
|
319 | + if ( is_wp_error( $_menu ) ) { |
|
320 | + return $_menu; |
|
321 | + } |
|
315 | 322 | |
316 | 323 | /** |
317 | 324 | * Fires after a navigation menu is successfully created. |
@@ -326,15 +333,17 @@ discard block |
||
326 | 333 | return (int) $_menu['term_id']; |
327 | 334 | } |
328 | 335 | |
329 | - if ( ! $_menu || ! isset( $_menu->term_id ) ) |
|
330 | - return 0; |
|
336 | + if ( ! $_menu || ! isset( $_menu->term_id ) ) { |
|
337 | + return 0; |
|
338 | + } |
|
331 | 339 | |
332 | 340 | $menu_id = (int) $_menu->term_id; |
333 | 341 | |
334 | 342 | $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); |
335 | 343 | |
336 | - if ( is_wp_error( $update_response ) ) |
|
337 | - return $update_response; |
|
344 | + if ( is_wp_error( $update_response ) ) { |
|
345 | + return $update_response; |
|
346 | + } |
|
338 | 347 | |
339 | 348 | $menu_id = (int) $update_response['term_id']; |
340 | 349 | |
@@ -368,8 +377,9 @@ discard block |
||
368 | 377 | $menu_item_db_id = (int) $menu_item_db_id; |
369 | 378 | |
370 | 379 | // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects |
371 | - if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) |
|
372 | - return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
380 | + if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) { |
|
381 | + return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); |
|
382 | + } |
|
373 | 383 | |
374 | 384 | $menu = wp_get_nav_menu_object( $menu_id ); |
375 | 385 | |
@@ -434,12 +444,14 @@ discard block |
||
434 | 444 | } |
435 | 445 | } |
436 | 446 | |
437 | - if ( $args['menu-item-title'] == $original_title ) |
|
438 | - $args['menu-item-title'] = ''; |
|
447 | + if ( $args['menu-item-title'] == $original_title ) { |
|
448 | + $args['menu-item-title'] = ''; |
|
449 | + } |
|
439 | 450 | |
440 | 451 | // hack to get wp to create a post object when too many properties are empty |
441 | - if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) |
|
442 | - $args['menu-item-description'] = ' '; |
|
452 | + if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) { |
|
453 | + $args['menu-item-description'] = ' '; |
|
454 | + } |
|
443 | 455 | } |
444 | 456 | |
445 | 457 | // Populate the menu item object |
@@ -460,8 +472,9 @@ discard block |
||
460 | 472 | $post['ID'] = 0; |
461 | 473 | $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; |
462 | 474 | $menu_item_db_id = wp_insert_post( $post ); |
463 | - if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) |
|
464 | - return $menu_item_db_id; |
|
475 | + if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) { |
|
476 | + return $menu_item_db_id; |
|
477 | + } |
|
465 | 478 | |
466 | 479 | /** |
467 | 480 | * Fires immediately after a new navigation menu item has been added. |
@@ -502,10 +515,11 @@ discard block |
||
502 | 515 | update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); |
503 | 516 | update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); |
504 | 517 | |
505 | - if ( 0 == $menu_id ) |
|
506 | - update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
507 | - elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) |
|
508 | - delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
518 | + if ( 0 == $menu_id ) { |
|
519 | + update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); |
|
520 | + } elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) { |
|
521 | + delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); |
|
522 | + } |
|
509 | 523 | |
510 | 524 | // Update existing menu item. Default is publish status |
511 | 525 | if ( $update ) { |
@@ -620,10 +634,11 @@ discard block |
||
620 | 634 | $object = get_post_meta( $item->ID, '_menu_item_object', true ); |
621 | 635 | $type = get_post_meta( $item->ID, '_menu_item_type', true ); |
622 | 636 | |
623 | - if ( 'post_type' == $type ) |
|
624 | - $posts[$object][] = $object_id; |
|
625 | - elseif ( 'taxonomy' == $type) |
|
626 | - $terms[$object][] = $object_id; |
|
637 | + if ( 'post_type' == $type ) { |
|
638 | + $posts[$object][] = $object_id; |
|
639 | + } elseif ( 'taxonomy' == $type) { |
|
640 | + $terms[$object][] = $object_id; |
|
641 | + } |
|
627 | 642 | } |
628 | 643 | |
629 | 644 | if ( ! empty( $posts ) ) { |
@@ -761,8 +776,9 @@ discard block |
||
761 | 776 | $menu_item->url = !is_wp_error( $term_url ) ? $term_url : ''; |
762 | 777 | |
763 | 778 | $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); |
764 | - if ( is_wp_error( $original_title ) ) |
|
765 | - $original_title = false; |
|
779 | + if ( is_wp_error( $original_title ) ) { |
|
780 | + $original_title = false; |
|
781 | + } |
|
766 | 782 | $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; |
767 | 783 | |
768 | 784 | } else { |
@@ -949,16 +965,20 @@ discard block |
||
949 | 965 | * @param object $post The post object being transitioned from one status to another. |
950 | 966 | */ |
951 | 967 | function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { |
952 | - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) |
|
953 | - return; |
|
954 | - if ( ! empty( $post->post_parent ) ) |
|
955 | - return; |
|
968 | + if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) { |
|
969 | + return; |
|
970 | + } |
|
971 | + if ( ! empty( $post->post_parent ) ) { |
|
972 | + return; |
|
973 | + } |
|
956 | 974 | $auto_add = get_option( 'nav_menu_options' ); |
957 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) |
|
958 | - return; |
|
975 | + if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) { |
|
976 | + return; |
|
977 | + } |
|
959 | 978 | $auto_add = $auto_add['auto_add']; |
960 | - if ( empty( $auto_add ) || ! is_array( $auto_add ) ) |
|
961 | - return; |
|
979 | + if ( empty( $auto_add ) || ! is_array( $auto_add ) ) { |
|
980 | + return; |
|
981 | + } |
|
962 | 982 | |
963 | 983 | $args = array( |
964 | 984 | 'menu-item-object-id' => $post->ID, |
@@ -969,11 +989,13 @@ discard block |
||
969 | 989 | |
970 | 990 | foreach ( $auto_add as $menu_id ) { |
971 | 991 | $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); |
972 | - if ( ! is_array( $items ) ) |
|
973 | - continue; |
|
992 | + if ( ! is_array( $items ) ) { |
|
993 | + continue; |
|
994 | + } |
|
974 | 995 | foreach ( $items as $item ) { |
975 | - if ( $post->ID == $item->object_id ) |
|
976 | - continue 2; |
|
996 | + if ( $post->ID == $item->object_id ) { |
|
997 | + continue 2; |
|
998 | + } |
|
977 | 999 | } |
978 | 1000 | wp_update_nav_menu_item( $menu_id, 0, $args ); |
979 | 1001 | } |