@@ -1309,7 +1309,7 @@ |
||
| 1309 | 1309 | * |
| 1310 | 1310 | * @global array $editor_styles |
| 1311 | 1311 | * |
| 1312 | - * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. |
|
| 1312 | + * @param string[] $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. |
|
| 1313 | 1313 | * Defaults to 'editor-style.css' |
| 1314 | 1314 | */ |
| 1315 | 1315 | function add_editor_style( $stylesheet = 'editor-style.css' ) { |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Theme, template, and stylesheet functions. |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Theme |
|
| 7 | - */ |
|
| 3 | + * Theme, template, and stylesheet functions. |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Theme |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Returns an array of WP_Theme objects based on the arguments. |
@@ -27,55 +27,55 @@ discard block |
||
| 27 | 27 | * synonymous for the current blog. |
| 28 | 28 | * @return array Array of WP_Theme objects. |
| 29 | 29 | */ |
| 30 | -function wp_get_themes( $args = array() ) { |
|
| 30 | +function wp_get_themes($args = array()) { |
|
| 31 | 31 | global $wp_theme_directories; |
| 32 | 32 | |
| 33 | - $defaults = array( 'errors' => false, 'allowed' => null, 'blog_id' => 0 ); |
|
| 34 | - $args = wp_parse_args( $args, $defaults ); |
|
| 33 | + $defaults = array('errors' => false, 'allowed' => null, 'blog_id' => 0); |
|
| 34 | + $args = wp_parse_args($args, $defaults); |
|
| 35 | 35 | |
| 36 | 36 | $theme_directories = search_theme_directories(); |
| 37 | 37 | |
| 38 | - if ( count( $wp_theme_directories ) > 1 ) { |
|
| 38 | + if (count($wp_theme_directories) > 1) { |
|
| 39 | 39 | // Make sure the current theme wins out, in case search_theme_directories() picks the wrong |
| 40 | 40 | // one in the case of a conflict. (Normally, last registered theme root wins.) |
| 41 | 41 | $current_theme = get_stylesheet(); |
| 42 | - if ( isset( $theme_directories[ $current_theme ] ) ) { |
|
| 43 | - $root_of_current_theme = get_raw_theme_root( $current_theme ); |
|
| 44 | - if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) |
|
| 45 | - $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; |
|
| 46 | - $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; |
|
| 42 | + if (isset($theme_directories[$current_theme])) { |
|
| 43 | + $root_of_current_theme = get_raw_theme_root($current_theme); |
|
| 44 | + if ( ! in_array($root_of_current_theme, $wp_theme_directories)) |
|
| 45 | + $root_of_current_theme = WP_CONTENT_DIR.$root_of_current_theme; |
|
| 46 | + $theme_directories[$current_theme]['theme_root'] = $root_of_current_theme; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if ( empty( $theme_directories ) ) |
|
| 50 | + if (empty($theme_directories)) |
|
| 51 | 51 | return array(); |
| 52 | 52 | |
| 53 | - if ( is_multisite() && null !== $args['allowed'] ) { |
|
| 53 | + if (is_multisite() && null !== $args['allowed']) { |
|
| 54 | 54 | $allowed = $args['allowed']; |
| 55 | - if ( 'network' === $allowed ) |
|
| 56 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); |
|
| 57 | - elseif ( 'site' === $allowed ) |
|
| 58 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); |
|
| 59 | - elseif ( $allowed ) |
|
| 60 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 55 | + if ('network' === $allowed) |
|
| 56 | + $theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed_on_network()); |
|
| 57 | + elseif ('site' === $allowed) |
|
| 58 | + $theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed_on_site($args['blog_id'])); |
|
| 59 | + elseif ($allowed) |
|
| 60 | + $theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed($args['blog_id'])); |
|
| 61 | 61 | else |
| 62 | - $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 62 | + $theme_directories = array_diff_key($theme_directories, WP_Theme::get_allowed($args['blog_id'])); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $themes = array(); |
| 66 | 66 | static $_themes = array(); |
| 67 | 67 | |
| 68 | - foreach ( $theme_directories as $theme => $theme_root ) { |
|
| 69 | - if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) |
|
| 70 | - $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; |
|
| 68 | + foreach ($theme_directories as $theme => $theme_root) { |
|
| 69 | + if (isset($_themes[$theme_root['theme_root'].'/'.$theme])) |
|
| 70 | + $themes[$theme] = $_themes[$theme_root['theme_root'].'/'.$theme]; |
|
| 71 | 71 | else |
| 72 | - $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); |
|
| 72 | + $themes[$theme] = $_themes[$theme_root['theme_root'].'/'.$theme] = new WP_Theme($theme, $theme_root['theme_root']); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( null !== $args['errors'] ) { |
|
| 76 | - foreach ( $themes as $theme => $wp_theme ) { |
|
| 77 | - if ( $wp_theme->errors() != $args['errors'] ) |
|
| 78 | - unset( $themes[ $theme ] ); |
|
| 75 | + if (null !== $args['errors']) { |
|
| 76 | + foreach ($themes as $theme => $wp_theme) { |
|
| 77 | + if ($wp_theme->errors() != $args['errors']) |
|
| 78 | + unset($themes[$theme]); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | * is used to calculate the theme root for the $stylesheet provided (or current theme). |
| 95 | 95 | * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence. |
| 96 | 96 | */ |
| 97 | -function wp_get_theme( $stylesheet = null, $theme_root = null ) { |
|
| 97 | +function wp_get_theme($stylesheet = null, $theme_root = null) { |
|
| 98 | 98 | global $wp_theme_directories; |
| 99 | 99 | |
| 100 | - if ( empty( $stylesheet ) ) |
|
| 100 | + if (empty($stylesheet)) |
|
| 101 | 101 | $stylesheet = get_stylesheet(); |
| 102 | 102 | |
| 103 | - if ( empty( $theme_root ) ) { |
|
| 104 | - $theme_root = get_raw_theme_root( $stylesheet ); |
|
| 105 | - if ( false === $theme_root ) |
|
| 106 | - $theme_root = WP_CONTENT_DIR . '/themes'; |
|
| 107 | - elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
| 108 | - $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 103 | + if (empty($theme_root)) { |
|
| 104 | + $theme_root = get_raw_theme_root($stylesheet); |
|
| 105 | + if (false === $theme_root) |
|
| 106 | + $theme_root = WP_CONTENT_DIR.'/themes'; |
|
| 107 | + elseif ( ! in_array($theme_root, (array) $wp_theme_directories)) |
|
| 108 | + $theme_root = WP_CONTENT_DIR.$theme_root; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return new WP_Theme( $stylesheet, $theme_root ); |
|
| 111 | + return new WP_Theme($stylesheet, $theme_root); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | * @since 3.5.0 |
| 118 | 118 | * @param bool $clear_update_cache Whether to clear the Theme updates cache |
| 119 | 119 | */ |
| 120 | -function wp_clean_themes_cache( $clear_update_cache = true ) { |
|
| 121 | - if ( $clear_update_cache ) |
|
| 122 | - delete_site_transient( 'update_themes' ); |
|
| 123 | - search_theme_directories( true ); |
|
| 124 | - foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) |
|
| 120 | +function wp_clean_themes_cache($clear_update_cache = true) { |
|
| 121 | + if ($clear_update_cache) |
|
| 122 | + delete_site_transient('update_themes'); |
|
| 123 | + search_theme_directories(true); |
|
| 124 | + foreach (wp_get_themes(array('errors' => null)) as $theme) |
|
| 125 | 125 | $theme->cache_delete(); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return bool true if a child theme is in use, false otherwise. |
| 134 | 134 | **/ |
| 135 | 135 | function is_child_theme() { |
| 136 | - return ( TEMPLATEPATH !== STYLESHEETPATH ); |
|
| 136 | + return (TEMPLATEPATH !== STYLESHEETPATH); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param string $stylesheet Name of the current stylesheet. |
| 159 | 159 | */ |
| 160 | - return apply_filters( 'stylesheet', get_option( 'stylesheet' ) ); |
|
| 160 | + return apply_filters('stylesheet', get_option('stylesheet')); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function get_stylesheet_directory() { |
| 171 | 171 | $stylesheet = get_stylesheet(); |
| 172 | - $theme_root = get_theme_root( $stylesheet ); |
|
| 172 | + $theme_root = get_theme_root($stylesheet); |
|
| 173 | 173 | $stylesheet_dir = "$theme_root/$stylesheet"; |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $stylesheet Directory name of the current theme. |
| 182 | 182 | * @param string $theme_root Absolute path to themes directory. |
| 183 | 183 | */ |
| 184 | - return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root ); |
|
| 184 | + return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | 194 | function get_stylesheet_directory_uri() { |
| 195 | - $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); |
|
| 196 | - $theme_root_uri = get_theme_root_uri( $stylesheet ); |
|
| 195 | + $stylesheet = str_replace('%2F', '/', rawurlencode(get_stylesheet())); |
|
| 196 | + $theme_root_uri = get_theme_root_uri($stylesheet); |
|
| 197 | 197 | $stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param string $stylesheet Name of the activated theme's directory. |
| 206 | 206 | * @param string $theme_root_uri Themes root URI. |
| 207 | 207 | */ |
| 208 | - return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri ); |
|
| 208 | + return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | function get_stylesheet_uri() { |
| 222 | 222 | $stylesheet_dir_uri = get_stylesheet_directory_uri(); |
| 223 | - $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; |
|
| 223 | + $stylesheet_uri = $stylesheet_dir_uri.'/style.css'; |
|
| 224 | 224 | /** |
| 225 | 225 | * Filter the URI of the current theme stylesheet. |
| 226 | 226 | * |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @param string $stylesheet_uri Stylesheet URI for the current theme/child theme. |
| 230 | 230 | * @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme. |
| 231 | 231 | */ |
| 232 | - return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
| 232 | + return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | $stylesheet_dir_uri = get_stylesheet_directory_uri(); |
| 258 | 258 | $dir = get_stylesheet_directory(); |
| 259 | 259 | $locale = get_locale(); |
| 260 | - if ( file_exists("$dir/$locale.css") ) |
|
| 260 | + if (file_exists("$dir/$locale.css")) |
|
| 261 | 261 | $stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; |
| 262 | - elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") ) |
|
| 262 | + elseif ( ! empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css")) |
|
| 263 | 263 | $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; |
| 264 | 264 | else |
| 265 | 265 | $stylesheet_uri = ''; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param string $stylesheet_uri Localized stylesheet URI. |
| 272 | 272 | * @param string $stylesheet_dir_uri Stylesheet directory URI. |
| 273 | 273 | */ |
| 274 | - return apply_filters( 'locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
| 274 | + return apply_filters('locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * |
| 290 | 290 | * @param string $template Current theme's directory name. |
| 291 | 291 | */ |
| 292 | - return apply_filters( 'template', get_option( 'template' ) ); |
|
| 292 | + return apply_filters('template', get_option('template')); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | function get_template_directory() { |
| 303 | 303 | $template = get_template(); |
| 304 | - $theme_root = get_theme_root( $template ); |
|
| 304 | + $theme_root = get_theme_root($template); |
|
| 305 | 305 | $template_dir = "$theme_root/$template"; |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * @param string $template Directory name of the current theme. |
| 314 | 314 | * @param string $theme_root Absolute path to the themes directory. |
| 315 | 315 | */ |
| 316 | - return apply_filters( 'template_directory', $template_dir, $template, $theme_root ); |
|
| 316 | + return apply_filters('template_directory', $template_dir, $template, $theme_root); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | * @return string Template directory URI. |
| 325 | 325 | */ |
| 326 | 326 | function get_template_directory_uri() { |
| 327 | - $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); |
|
| 328 | - $theme_root_uri = get_theme_root_uri( $template ); |
|
| 327 | + $template = str_replace('%2F', '/', rawurlencode(get_template())); |
|
| 328 | + $theme_root_uri = get_theme_root_uri($template); |
|
| 329 | 329 | $template_dir_uri = "$theme_root_uri/$template"; |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param string $template Directory name of the current theme. |
| 338 | 338 | * @param string $theme_root_uri The themes root URI. |
| 339 | 339 | */ |
| 340 | - return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri ); |
|
| 340 | + return apply_filters('template_directory_uri', $template_dir_uri, $template, $theme_root_uri); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -352,13 +352,13 @@ discard block |
||
| 352 | 352 | function get_theme_roots() { |
| 353 | 353 | global $wp_theme_directories; |
| 354 | 354 | |
| 355 | - if ( count($wp_theme_directories) <= 1 ) |
|
| 355 | + if (count($wp_theme_directories) <= 1) |
|
| 356 | 356 | return '/themes'; |
| 357 | 357 | |
| 358 | - $theme_roots = get_site_transient( 'theme_roots' ); |
|
| 359 | - if ( false === $theme_roots ) { |
|
| 360 | - search_theme_directories( true ); // Regenerate the transient. |
|
| 361 | - $theme_roots = get_site_transient( 'theme_roots' ); |
|
| 358 | + $theme_roots = get_site_transient('theme_roots'); |
|
| 359 | + if (false === $theme_roots) { |
|
| 360 | + search_theme_directories(true); // Regenerate the transient. |
|
| 361 | + $theme_roots = get_site_transient('theme_roots'); |
|
| 362 | 362 | } |
| 363 | 363 | return $theme_roots; |
| 364 | 364 | } |
@@ -373,24 +373,24 @@ discard block |
||
| 373 | 373 | * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR |
| 374 | 374 | * @return bool |
| 375 | 375 | */ |
| 376 | -function register_theme_directory( $directory ) { |
|
| 376 | +function register_theme_directory($directory) { |
|
| 377 | 377 | global $wp_theme_directories; |
| 378 | 378 | |
| 379 | - if ( ! file_exists( $directory ) ) { |
|
| 379 | + if ( ! file_exists($directory)) { |
|
| 380 | 380 | // Try prepending as the theme directory could be relative to the content directory |
| 381 | - $directory = WP_CONTENT_DIR . '/' . $directory; |
|
| 381 | + $directory = WP_CONTENT_DIR.'/'.$directory; |
|
| 382 | 382 | // If this directory does not exist, return and do not register |
| 383 | - if ( ! file_exists( $directory ) ) { |
|
| 383 | + if ( ! file_exists($directory)) { |
|
| 384 | 384 | return false; |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( ! is_array( $wp_theme_directories ) ) { |
|
| 388 | + if ( ! is_array($wp_theme_directories)) { |
|
| 389 | 389 | $wp_theme_directories = array(); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $untrailed = untrailingslashit( $directory ); |
|
| 393 | - if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) { |
|
| 392 | + $untrailed = untrailingslashit($directory); |
|
| 393 | + if ( ! empty($untrailed) && ! in_array($untrailed, $wp_theme_directories)) { |
|
| 394 | 394 | $wp_theme_directories[] = $untrailed; |
| 395 | 395 | } |
| 396 | 396 | |
@@ -408,14 +408,14 @@ discard block |
||
| 408 | 408 | * @param bool $force Optional. Whether to force a new directory scan. Defaults to false. |
| 409 | 409 | * @return array|false Valid themes found |
| 410 | 410 | */ |
| 411 | -function search_theme_directories( $force = false ) { |
|
| 411 | +function search_theme_directories($force = false) { |
|
| 412 | 412 | global $wp_theme_directories; |
| 413 | 413 | static $found_themes = null; |
| 414 | 414 | |
| 415 | - if ( empty( $wp_theme_directories ) ) |
|
| 415 | + if (empty($wp_theme_directories)) |
|
| 416 | 416 | return false; |
| 417 | 417 | |
| 418 | - if ( ! $force && isset( $found_themes ) ) |
|
| 418 | + if ( ! $force && isset($found_themes)) |
|
| 419 | 419 | return $found_themes; |
| 420 | 420 | |
| 421 | 421 | $found_themes = array(); |
@@ -426,11 +426,11 @@ discard block |
||
| 426 | 426 | // Set up maybe-relative, maybe-absolute array of theme directories. |
| 427 | 427 | // We always want to return absolute, but we need to cache relative |
| 428 | 428 | // to use in get_theme_root(). |
| 429 | - foreach ( $wp_theme_directories as $theme_root ) { |
|
| 430 | - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
| 431 | - $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; |
|
| 429 | + foreach ($wp_theme_directories as $theme_root) { |
|
| 430 | + if (0 === strpos($theme_root, WP_CONTENT_DIR)) |
|
| 431 | + $relative_theme_roots[str_replace(WP_CONTENT_DIR, '', $theme_root)] = $theme_root; |
|
| 432 | 432 | else |
| 433 | - $relative_theme_roots[ $theme_root ] = $theme_root; |
|
| 433 | + $relative_theme_roots[$theme_root] = $theme_root; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -441,87 +441,87 @@ discard block |
||
| 441 | 441 | * @param bool $cache_expiration Whether to get the cache of the theme directories. Default false. |
| 442 | 442 | * @param string $cache_directory Directory to be searched for the cache. |
| 443 | 443 | */ |
| 444 | - if ( $cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' ) ) { |
|
| 445 | - $cached_roots = get_site_transient( 'theme_roots' ); |
|
| 446 | - if ( is_array( $cached_roots ) ) { |
|
| 447 | - foreach ( $cached_roots as $theme_dir => $theme_root ) { |
|
| 444 | + if ($cache_expiration = apply_filters('wp_cache_themes_persistently', false, 'search_theme_directories')) { |
|
| 445 | + $cached_roots = get_site_transient('theme_roots'); |
|
| 446 | + if (is_array($cached_roots)) { |
|
| 447 | + foreach ($cached_roots as $theme_dir => $theme_root) { |
|
| 448 | 448 | // A cached theme root is no longer around, so skip it. |
| 449 | - if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) |
|
| 449 | + if ( ! isset($relative_theme_roots[$theme_root])) |
|
| 450 | 450 | continue; |
| 451 | - $found_themes[ $theme_dir ] = array( |
|
| 452 | - 'theme_file' => $theme_dir . '/style.css', |
|
| 453 | - 'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute. |
|
| 451 | + $found_themes[$theme_dir] = array( |
|
| 452 | + 'theme_file' => $theme_dir.'/style.css', |
|
| 453 | + 'theme_root' => $relative_theme_roots[$theme_root], // Convert relative to absolute. |
|
| 454 | 454 | ); |
| 455 | 455 | } |
| 456 | 456 | return $found_themes; |
| 457 | 457 | } |
| 458 | - if ( ! is_int( $cache_expiration ) ) |
|
| 458 | + if ( ! is_int($cache_expiration)) |
|
| 459 | 459 | $cache_expiration = 1800; // half hour |
| 460 | 460 | } else { |
| 461 | 461 | $cache_expiration = 1800; // half hour |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /* Loop the registered theme directories and extract all themes */ |
| 465 | - foreach ( $wp_theme_directories as $theme_root ) { |
|
| 465 | + foreach ($wp_theme_directories as $theme_root) { |
|
| 466 | 466 | |
| 467 | 467 | // Start with directories in the root of the current theme directory. |
| 468 | - $dirs = @ scandir( $theme_root ); |
|
| 469 | - if ( ! $dirs ) { |
|
| 470 | - trigger_error( "$theme_root is not readable", E_USER_NOTICE ); |
|
| 468 | + $dirs = @ scandir($theme_root); |
|
| 469 | + if ( ! $dirs) { |
|
| 470 | + trigger_error("$theme_root is not readable", E_USER_NOTICE); |
|
| 471 | 471 | continue; |
| 472 | 472 | } |
| 473 | - foreach ( $dirs as $dir ) { |
|
| 474 | - if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
| 473 | + foreach ($dirs as $dir) { |
|
| 474 | + if ( ! is_dir($theme_root.'/'.$dir) || $dir[0] == '.' || $dir == 'CVS') |
|
| 475 | 475 | continue; |
| 476 | - if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { |
|
| 476 | + if (file_exists($theme_root.'/'.$dir.'/style.css')) { |
|
| 477 | 477 | // wp-content/themes/a-single-theme |
| 478 | 478 | // wp-content/themes is $theme_root, a-single-theme is $dir |
| 479 | - $found_themes[ $dir ] = array( |
|
| 480 | - 'theme_file' => $dir . '/style.css', |
|
| 479 | + $found_themes[$dir] = array( |
|
| 480 | + 'theme_file' => $dir.'/style.css', |
|
| 481 | 481 | 'theme_root' => $theme_root, |
| 482 | 482 | ); |
| 483 | 483 | } else { |
| 484 | 484 | $found_theme = false; |
| 485 | 485 | // wp-content/themes/a-folder-of-themes/* |
| 486 | 486 | // wp-content/themes is $theme_root, a-folder-of-themes is $dir, then themes are $sub_dirs |
| 487 | - $sub_dirs = @ scandir( $theme_root . '/' . $dir ); |
|
| 488 | - if ( ! $sub_dirs ) { |
|
| 489 | - trigger_error( "$theme_root/$dir is not readable", E_USER_NOTICE ); |
|
| 487 | + $sub_dirs = @ scandir($theme_root.'/'.$dir); |
|
| 488 | + if ( ! $sub_dirs) { |
|
| 489 | + trigger_error("$theme_root/$dir is not readable", E_USER_NOTICE); |
|
| 490 | 490 | continue; |
| 491 | 491 | } |
| 492 | - foreach ( $sub_dirs as $sub_dir ) { |
|
| 493 | - if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
| 492 | + foreach ($sub_dirs as $sub_dir) { |
|
| 493 | + if ( ! is_dir($theme_root.'/'.$dir.'/'.$sub_dir) || $dir[0] == '.' || $dir == 'CVS') |
|
| 494 | 494 | continue; |
| 495 | - if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) |
|
| 495 | + if ( ! file_exists($theme_root.'/'.$dir.'/'.$sub_dir.'/style.css')) |
|
| 496 | 496 | continue; |
| 497 | - $found_themes[ $dir . '/' . $sub_dir ] = array( |
|
| 498 | - 'theme_file' => $dir . '/' . $sub_dir . '/style.css', |
|
| 497 | + $found_themes[$dir.'/'.$sub_dir] = array( |
|
| 498 | + 'theme_file' => $dir.'/'.$sub_dir.'/style.css', |
|
| 499 | 499 | 'theme_root' => $theme_root, |
| 500 | 500 | ); |
| 501 | 501 | $found_theme = true; |
| 502 | 502 | } |
| 503 | 503 | // Never mind the above, it's just a theme missing a style.css. |
| 504 | 504 | // Return it; WP_Theme will catch the error. |
| 505 | - if ( ! $found_theme ) |
|
| 506 | - $found_themes[ $dir ] = array( |
|
| 507 | - 'theme_file' => $dir . '/style.css', |
|
| 505 | + if ( ! $found_theme) |
|
| 506 | + $found_themes[$dir] = array( |
|
| 507 | + 'theme_file' => $dir.'/style.css', |
|
| 508 | 508 | 'theme_root' => $theme_root, |
| 509 | 509 | ); |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - asort( $found_themes ); |
|
| 514 | + asort($found_themes); |
|
| 515 | 515 | |
| 516 | 516 | $theme_roots = array(); |
| 517 | - $relative_theme_roots = array_flip( $relative_theme_roots ); |
|
| 517 | + $relative_theme_roots = array_flip($relative_theme_roots); |
|
| 518 | 518 | |
| 519 | - foreach ( $found_themes as $theme_dir => $theme_data ) { |
|
| 520 | - $theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative. |
|
| 519 | + foreach ($found_themes as $theme_dir => $theme_data) { |
|
| 520 | + $theme_roots[$theme_dir] = $relative_theme_roots[$theme_data['theme_root']]; // Convert absolute to relative. |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - if ( $theme_roots != get_site_transient( 'theme_roots' ) ) |
|
| 524 | - set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); |
|
| 523 | + if ($theme_roots != get_site_transient('theme_roots')) |
|
| 524 | + set_site_transient('theme_roots', $theme_roots, $cache_expiration); |
|
| 525 | 525 | |
| 526 | 526 | return $found_themes; |
| 527 | 527 | } |
@@ -538,16 +538,16 @@ discard block |
||
| 538 | 538 | * @param string $stylesheet_or_template The stylesheet or template name of the theme |
| 539 | 539 | * @return string Theme path. |
| 540 | 540 | */ |
| 541 | -function get_theme_root( $stylesheet_or_template = false ) { |
|
| 541 | +function get_theme_root($stylesheet_or_template = false) { |
|
| 542 | 542 | global $wp_theme_directories; |
| 543 | 543 | |
| 544 | - if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { |
|
| 544 | + if ($stylesheet_or_template && $theme_root = get_raw_theme_root($stylesheet_or_template)) { |
|
| 545 | 545 | // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. |
| 546 | 546 | // This gives relative theme roots the benefit of the doubt when things go haywire. |
| 547 | - if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
| 548 | - $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 547 | + if ( ! in_array($theme_root, (array) $wp_theme_directories)) |
|
| 548 | + $theme_root = WP_CONTENT_DIR.$theme_root; |
|
| 549 | 549 | } else { |
| 550 | - $theme_root = WP_CONTENT_DIR . '/themes'; |
|
| 550 | + $theme_root = WP_CONTENT_DIR.'/themes'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | * |
| 558 | 558 | * @param string $theme_root Absolute path to themes directory. |
| 559 | 559 | */ |
| 560 | - return apply_filters( 'theme_root', $theme_root ); |
|
| 560 | + return apply_filters('theme_root', $theme_root); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -575,28 +575,28 @@ discard block |
||
| 575 | 575 | * the need for a get_raw_theme_root() call. |
| 576 | 576 | * @return string Themes URI. |
| 577 | 577 | */ |
| 578 | -function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { |
|
| 578 | +function get_theme_root_uri($stylesheet_or_template = false, $theme_root = false) { |
|
| 579 | 579 | global $wp_theme_directories; |
| 580 | 580 | |
| 581 | - if ( $stylesheet_or_template && ! $theme_root ) |
|
| 582 | - $theme_root = get_raw_theme_root( $stylesheet_or_template ); |
|
| 581 | + if ($stylesheet_or_template && ! $theme_root) |
|
| 582 | + $theme_root = get_raw_theme_root($stylesheet_or_template); |
|
| 583 | 583 | |
| 584 | - if ( $stylesheet_or_template && $theme_root ) { |
|
| 585 | - if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { |
|
| 584 | + if ($stylesheet_or_template && $theme_root) { |
|
| 585 | + if (in_array($theme_root, (array) $wp_theme_directories)) { |
|
| 586 | 586 | // Absolute path. Make an educated guess. YMMV -- but note the filter below. |
| 587 | - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
| 588 | - $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); |
|
| 589 | - elseif ( 0 === strpos( $theme_root, ABSPATH ) ) |
|
| 590 | - $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); |
|
| 591 | - elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) |
|
| 592 | - $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); |
|
| 587 | + if (0 === strpos($theme_root, WP_CONTENT_DIR)) |
|
| 588 | + $theme_root_uri = content_url(str_replace(WP_CONTENT_DIR, '', $theme_root)); |
|
| 589 | + elseif (0 === strpos($theme_root, ABSPATH)) |
|
| 590 | + $theme_root_uri = site_url(str_replace(ABSPATH, '', $theme_root)); |
|
| 591 | + elseif (0 === strpos($theme_root, WP_PLUGIN_DIR) || 0 === strpos($theme_root, WPMU_PLUGIN_DIR)) |
|
| 592 | + $theme_root_uri = plugins_url(basename($theme_root), $theme_root); |
|
| 593 | 593 | else |
| 594 | 594 | $theme_root_uri = $theme_root; |
| 595 | 595 | } else { |
| 596 | - $theme_root_uri = content_url( $theme_root ); |
|
| 596 | + $theme_root_uri = content_url($theme_root); |
|
| 597 | 597 | } |
| 598 | 598 | } else { |
| 599 | - $theme_root_uri = content_url( 'themes' ); |
|
| 599 | + $theme_root_uri = content_url('themes'); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @param string $siteurl WordPress web address which is set in General Options. |
| 609 | 609 | * @param string $stylesheet_or_template Stylesheet or template name of the theme. |
| 610 | 610 | */ |
| 611 | - return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template ); |
|
| 611 | + return apply_filters('theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -623,25 +623,25 @@ discard block |
||
| 623 | 623 | * Defaults to false, meaning the cache is used. |
| 624 | 624 | * @return string Theme root |
| 625 | 625 | */ |
| 626 | -function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) { |
|
| 626 | +function get_raw_theme_root($stylesheet_or_template, $skip_cache = false) { |
|
| 627 | 627 | global $wp_theme_directories; |
| 628 | 628 | |
| 629 | - if ( count($wp_theme_directories) <= 1 ) |
|
| 629 | + if (count($wp_theme_directories) <= 1) |
|
| 630 | 630 | return '/themes'; |
| 631 | 631 | |
| 632 | 632 | $theme_root = false; |
| 633 | 633 | |
| 634 | 634 | // If requesting the root for the current theme, consult options to avoid calling get_theme_roots() |
| 635 | - if ( ! $skip_cache ) { |
|
| 636 | - if ( get_option('stylesheet') == $stylesheet_or_template ) |
|
| 635 | + if ( ! $skip_cache) { |
|
| 636 | + if (get_option('stylesheet') == $stylesheet_or_template) |
|
| 637 | 637 | $theme_root = get_option('stylesheet_root'); |
| 638 | - elseif ( get_option('template') == $stylesheet_or_template ) |
|
| 638 | + elseif (get_option('template') == $stylesheet_or_template) |
|
| 639 | 639 | $theme_root = get_option('template_root'); |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - if ( empty($theme_root) ) { |
|
| 642 | + if (empty($theme_root)) { |
|
| 643 | 643 | $theme_roots = get_theme_roots(); |
| 644 | - if ( !empty($theme_roots[$stylesheet_or_template]) ) |
|
| 644 | + if ( ! empty($theme_roots[$stylesheet_or_template])) |
|
| 645 | 645 | $theme_root = $theme_roots[$stylesheet_or_template]; |
| 646 | 646 | } |
| 647 | 647 | |
@@ -655,9 +655,9 @@ discard block |
||
| 655 | 655 | */ |
| 656 | 656 | function locale_stylesheet() { |
| 657 | 657 | $stylesheet = get_locale_stylesheet_uri(); |
| 658 | - if ( empty($stylesheet) ) |
|
| 658 | + if (empty($stylesheet)) |
|
| 659 | 659 | return; |
| 660 | - echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; |
|
| 660 | + echo '<link rel="stylesheet" href="'.$stylesheet.'" type="text/css" media="screen" />'; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -674,61 +674,61 @@ discard block |
||
| 674 | 674 | * |
| 675 | 675 | * @param string $stylesheet Stylesheet name |
| 676 | 676 | */ |
| 677 | -function switch_theme( $stylesheet ) { |
|
| 677 | +function switch_theme($stylesheet) { |
|
| 678 | 678 | global $wp_theme_directories, $wp_customize, $sidebars_widgets; |
| 679 | 679 | |
| 680 | 680 | $_sidebars_widgets = null; |
| 681 | - if ( 'wp_ajax_customize_save' === current_action() ) { |
|
| 682 | - $_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) ); |
|
| 683 | - } elseif ( is_array( $sidebars_widgets ) ) { |
|
| 681 | + if ('wp_ajax_customize_save' === current_action()) { |
|
| 682 | + $_sidebars_widgets = $wp_customize->post_value($wp_customize->get_setting('old_sidebars_widgets_data')); |
|
| 683 | + } elseif (is_array($sidebars_widgets)) { |
|
| 684 | 684 | $_sidebars_widgets = $sidebars_widgets; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if ( is_array( $_sidebars_widgets ) ) { |
|
| 688 | - set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); |
|
| 687 | + if (is_array($_sidebars_widgets)) { |
|
| 688 | + set_theme_mod('sidebars_widgets', array('time' => time(), 'data' => $_sidebars_widgets)); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - $old_theme = wp_get_theme(); |
|
| 692 | - $new_theme = wp_get_theme( $stylesheet ); |
|
| 691 | + $old_theme = wp_get_theme(); |
|
| 692 | + $new_theme = wp_get_theme($stylesheet); |
|
| 693 | 693 | |
| 694 | - if ( func_num_args() > 1 ) { |
|
| 694 | + if (func_num_args() > 1) { |
|
| 695 | 695 | $template = $stylesheet; |
| 696 | - $stylesheet = func_get_arg( 1 ); |
|
| 696 | + $stylesheet = func_get_arg(1); |
|
| 697 | 697 | } else { |
| 698 | 698 | $template = $new_theme->get_template(); |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - update_option( 'template', $template ); |
|
| 702 | - update_option( 'stylesheet', $stylesheet ); |
|
| 701 | + update_option('template', $template); |
|
| 702 | + update_option('stylesheet', $stylesheet); |
|
| 703 | 703 | |
| 704 | - if ( count( $wp_theme_directories ) > 1 ) { |
|
| 705 | - update_option( 'template_root', get_raw_theme_root( $template, true ) ); |
|
| 706 | - update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) ); |
|
| 704 | + if (count($wp_theme_directories) > 1) { |
|
| 705 | + update_option('template_root', get_raw_theme_root($template, true)); |
|
| 706 | + update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); |
|
| 707 | 707 | } else { |
| 708 | - delete_option( 'template_root' ); |
|
| 709 | - delete_option( 'stylesheet_root' ); |
|
| 708 | + delete_option('template_root'); |
|
| 709 | + delete_option('stylesheet_root'); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - $new_name = $new_theme->get('Name'); |
|
| 712 | + $new_name = $new_theme->get('Name'); |
|
| 713 | 713 | |
| 714 | - update_option( 'current_theme', $new_name ); |
|
| 714 | + update_option('current_theme', $new_name); |
|
| 715 | 715 | |
| 716 | 716 | // Migrate from the old mods_{name} option to theme_mods_{slug}. |
| 717 | - if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { |
|
| 718 | - $default_theme_mods = (array) get_option( 'mods_' . $new_name ); |
|
| 719 | - add_option( "theme_mods_$stylesheet", $default_theme_mods ); |
|
| 717 | + if (is_admin() && false === get_option('theme_mods_'.$stylesheet)) { |
|
| 718 | + $default_theme_mods = (array) get_option('mods_'.$new_name); |
|
| 719 | + add_option("theme_mods_$stylesheet", $default_theme_mods); |
|
| 720 | 720 | } else { |
| 721 | 721 | /* |
| 722 | 722 | * Since retrieve_widgets() is called when initializing a theme in the Customizer, |
| 723 | 723 | * we need to to remove the theme mods to avoid overwriting changes made via |
| 724 | 724 | * the Customizer when accessing wp-admin/widgets.php. |
| 725 | 725 | */ |
| 726 | - if ( 'wp_ajax_customize_save' === current_action() ) { |
|
| 727 | - remove_theme_mod( 'sidebars_widgets' ); |
|
| 726 | + if ('wp_ajax_customize_save' === current_action()) { |
|
| 727 | + remove_theme_mod('sidebars_widgets'); |
|
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - update_option( 'theme_switched', $old_theme->get_stylesheet() ); |
|
| 731 | + update_option('theme_switched', $old_theme->get_stylesheet()); |
|
| 732 | 732 | /** |
| 733 | 733 | * Fires after the theme is switched. |
| 734 | 734 | * |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * @param string $new_name Name of the new theme. |
| 738 | 738 | * @param WP_Theme $new_theme WP_Theme instance of the new theme. |
| 739 | 739 | */ |
| 740 | - do_action( 'switch_theme', $new_name, $new_theme ); |
|
| 740 | + do_action('switch_theme', $new_name, $new_theme); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -761,21 +761,21 @@ discard block |
||
| 761 | 761 | * |
| 762 | 762 | * @param bool true Validation flag to check the current theme. |
| 763 | 763 | */ |
| 764 | - if ( defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) ) |
|
| 764 | + if (defined('WP_INSTALLING') || ! apply_filters('validate_current_theme', true)) |
|
| 765 | 765 | return true; |
| 766 | 766 | |
| 767 | - if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { |
|
| 768 | - switch_theme( WP_DEFAULT_THEME ); |
|
| 767 | + if (get_template() != WP_DEFAULT_THEME && ! file_exists(get_template_directory().'/index.php')) { |
|
| 768 | + switch_theme(WP_DEFAULT_THEME); |
|
| 769 | 769 | return false; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) { |
|
| 773 | - switch_theme( WP_DEFAULT_THEME ); |
|
| 772 | + if (get_stylesheet() != WP_DEFAULT_THEME && ! file_exists(get_template_directory().'/style.css')) { |
|
| 773 | + switch_theme(WP_DEFAULT_THEME); |
|
| 774 | 774 | return false; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) { |
|
| 778 | - switch_theme( WP_DEFAULT_THEME ); |
|
| 777 | + if (is_child_theme() && ! file_exists(get_stylesheet_directory().'/style.css')) { |
|
| 778 | + switch_theme(WP_DEFAULT_THEME); |
|
| 779 | 779 | return false; |
| 780 | 780 | } |
| 781 | 781 | |
@@ -790,16 +790,16 @@ discard block |
||
| 790 | 790 | * @return array|void Theme modifications. |
| 791 | 791 | */ |
| 792 | 792 | function get_theme_mods() { |
| 793 | - $theme_slug = get_option( 'stylesheet' ); |
|
| 794 | - $mods = get_option( "theme_mods_$theme_slug" ); |
|
| 795 | - if ( false === $mods ) { |
|
| 796 | - $theme_name = get_option( 'current_theme' ); |
|
| 797 | - if ( false === $theme_name ) |
|
| 793 | + $theme_slug = get_option('stylesheet'); |
|
| 794 | + $mods = get_option("theme_mods_$theme_slug"); |
|
| 795 | + if (false === $mods) { |
|
| 796 | + $theme_name = get_option('current_theme'); |
|
| 797 | + if (false === $theme_name) |
|
| 798 | 798 | $theme_name = wp_get_theme()->get('Name'); |
| 799 | - $mods = get_option( "mods_$theme_name" ); // Deprecated location. |
|
| 800 | - if ( is_admin() && false !== $mods ) { |
|
| 801 | - update_option( "theme_mods_$theme_slug", $mods ); |
|
| 802 | - delete_option( "mods_$theme_name" ); |
|
| 799 | + $mods = get_option("mods_$theme_name"); // Deprecated location. |
|
| 800 | + if (is_admin() && false !== $mods) { |
|
| 801 | + update_option("theme_mods_$theme_slug", $mods); |
|
| 802 | + delete_option("mods_$theme_name"); |
|
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | return $mods; |
@@ -819,10 +819,10 @@ discard block |
||
| 819 | 819 | * @param bool|string $default |
| 820 | 820 | * @return string |
| 821 | 821 | */ |
| 822 | -function get_theme_mod( $name, $default = false ) { |
|
| 822 | +function get_theme_mod($name, $default = false) { |
|
| 823 | 823 | $mods = get_theme_mods(); |
| 824 | 824 | |
| 825 | - if ( isset( $mods[$name] ) ) { |
|
| 825 | + if (isset($mods[$name])) { |
|
| 826 | 826 | /** |
| 827 | 827 | * Filter the theme modification, or 'theme_mod', value. |
| 828 | 828 | * |
@@ -835,14 +835,14 @@ discard block |
||
| 835 | 835 | * |
| 836 | 836 | * @param string $current_mod The value of the current theme modification. |
| 837 | 837 | */ |
| 838 | - return apply_filters( "theme_mod_{$name}", $mods[$name] ); |
|
| 838 | + return apply_filters("theme_mod_{$name}", $mods[$name]); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - if ( is_string( $default ) ) |
|
| 842 | - $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 841 | + if (is_string($default)) |
|
| 842 | + $default = sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()); |
|
| 843 | 843 | |
| 844 | 844 | /** This filter is documented in wp-includes/theme.php */ |
| 845 | - return apply_filters( "theme_mod_{$name}", $default ); |
|
| 845 | + return apply_filters("theme_mod_{$name}", $default); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -853,9 +853,9 @@ discard block |
||
| 853 | 853 | * @param string $name Theme modification name. |
| 854 | 854 | * @param mixed $value Theme modification value. |
| 855 | 855 | */ |
| 856 | -function set_theme_mod( $name, $value ) { |
|
| 856 | +function set_theme_mod($name, $value) { |
|
| 857 | 857 | $mods = get_theme_mods(); |
| 858 | - $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; |
|
| 858 | + $old_value = isset($mods[$name]) ? $mods[$name] : false; |
|
| 859 | 859 | |
| 860 | 860 | /** |
| 861 | 861 | * Filter the theme mod value on save. |
@@ -869,10 +869,10 @@ discard block |
||
| 869 | 869 | * @param string $value The new value of the theme mod. |
| 870 | 870 | * @param string $old_value The current value of the theme mod. |
| 871 | 871 | */ |
| 872 | - $mods[ $name ] = apply_filters( "pre_set_theme_mod_$name", $value, $old_value ); |
|
| 872 | + $mods[$name] = apply_filters("pre_set_theme_mod_$name", $value, $old_value); |
|
| 873 | 873 | |
| 874 | - $theme = get_option( 'stylesheet' ); |
|
| 875 | - update_option( "theme_mods_$theme", $mods ); |
|
| 874 | + $theme = get_option('stylesheet'); |
|
| 875 | + update_option("theme_mods_$theme", $mods); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -885,20 +885,20 @@ discard block |
||
| 885 | 885 | * |
| 886 | 886 | * @param string $name Theme modification name. |
| 887 | 887 | */ |
| 888 | -function remove_theme_mod( $name ) { |
|
| 888 | +function remove_theme_mod($name) { |
|
| 889 | 889 | $mods = get_theme_mods(); |
| 890 | 890 | |
| 891 | - if ( ! isset( $mods[ $name ] ) ) |
|
| 891 | + if ( ! isset($mods[$name])) |
|
| 892 | 892 | return; |
| 893 | 893 | |
| 894 | - unset( $mods[ $name ] ); |
|
| 894 | + unset($mods[$name]); |
|
| 895 | 895 | |
| 896 | - if ( empty( $mods ) ) { |
|
| 896 | + if (empty($mods)) { |
|
| 897 | 897 | remove_theme_mods(); |
| 898 | 898 | return; |
| 899 | 899 | } |
| 900 | - $theme = get_option( 'stylesheet' ); |
|
| 901 | - update_option( "theme_mods_$theme", $mods ); |
|
| 900 | + $theme = get_option('stylesheet'); |
|
| 901 | + update_option("theme_mods_$theme", $mods); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -907,13 +907,13 @@ discard block |
||
| 907 | 907 | * @since 2.1.0 |
| 908 | 908 | */ |
| 909 | 909 | function remove_theme_mods() { |
| 910 | - delete_option( 'theme_mods_' . get_option( 'stylesheet' ) ); |
|
| 910 | + delete_option('theme_mods_'.get_option('stylesheet')); |
|
| 911 | 911 | |
| 912 | 912 | // Old style. |
| 913 | - $theme_name = get_option( 'current_theme' ); |
|
| 914 | - if ( false === $theme_name ) |
|
| 913 | + $theme_name = get_option('current_theme'); |
|
| 914 | + if (false === $theme_name) |
|
| 915 | 915 | $theme_name = wp_get_theme()->get('Name'); |
| 916 | - delete_option( 'mods_' . $theme_name ); |
|
| 916 | + delete_option('mods_'.$theme_name); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | /** |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | * @return string |
| 925 | 925 | */ |
| 926 | 926 | function get_header_textcolor() { |
| 927 | - return get_theme_mod('header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
|
| 927 | + return get_theme_mod('header_textcolor', get_theme_support('custom-header', 'default-text-color')); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
@@ -944,10 +944,10 @@ discard block |
||
| 944 | 944 | * @return bool |
| 945 | 945 | */ |
| 946 | 946 | function display_header_text() { |
| 947 | - if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) |
|
| 947 | + if ( ! current_theme_supports('custom-header', 'header-text')) |
|
| 948 | 948 | return false; |
| 949 | 949 | |
| 950 | - $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
|
| 950 | + $text_color = get_theme_mod('header_textcolor', get_theme_support('custom-header', 'default-text-color')); |
|
| 951 | 951 | return 'blank' !== $text_color; |
| 952 | 952 | } |
| 953 | 953 | |
@@ -972,15 +972,15 @@ discard block |
||
| 972 | 972 | * @return string|false |
| 973 | 973 | */ |
| 974 | 974 | function get_header_image() { |
| 975 | - $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
| 975 | + $url = get_theme_mod('header_image', get_theme_support('custom-header', 'default-image')); |
|
| 976 | 976 | |
| 977 | - if ( 'remove-header' == $url ) |
|
| 977 | + if ('remove-header' == $url) |
|
| 978 | 978 | return false; |
| 979 | 979 | |
| 980 | - if ( is_random_header_image() ) |
|
| 980 | + if (is_random_header_image()) |
|
| 981 | 981 | $url = get_random_header_image(); |
| 982 | 982 | |
| 983 | - return esc_url_raw( set_url_scheme( $url ) ); |
|
| 983 | + return esc_url_raw(set_url_scheme($url)); |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | /** |
@@ -998,29 +998,29 @@ discard block |
||
| 998 | 998 | function _get_random_header_data() { |
| 999 | 999 | static $_wp_random_header = null; |
| 1000 | 1000 | |
| 1001 | - if ( empty( $_wp_random_header ) ) { |
|
| 1001 | + if (empty($_wp_random_header)) { |
|
| 1002 | 1002 | global $_wp_default_headers; |
| 1003 | - $header_image_mod = get_theme_mod( 'header_image', '' ); |
|
| 1003 | + $header_image_mod = get_theme_mod('header_image', ''); |
|
| 1004 | 1004 | $headers = array(); |
| 1005 | 1005 | |
| 1006 | - if ( 'random-uploaded-image' == $header_image_mod ) |
|
| 1006 | + if ('random-uploaded-image' == $header_image_mod) |
|
| 1007 | 1007 | $headers = get_uploaded_header_images(); |
| 1008 | - elseif ( ! empty( $_wp_default_headers ) ) { |
|
| 1009 | - if ( 'random-default-image' == $header_image_mod ) { |
|
| 1008 | + elseif ( ! empty($_wp_default_headers)) { |
|
| 1009 | + if ('random-default-image' == $header_image_mod) { |
|
| 1010 | 1010 | $headers = $_wp_default_headers; |
| 1011 | 1011 | } else { |
| 1012 | - if ( current_theme_supports( 'custom-header', 'random-default' ) ) |
|
| 1012 | + if (current_theme_supports('custom-header', 'random-default')) |
|
| 1013 | 1013 | $headers = $_wp_default_headers; |
| 1014 | 1014 | } |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | - if ( empty( $headers ) ) |
|
| 1017 | + if (empty($headers)) |
|
| 1018 | 1018 | return new stdClass; |
| 1019 | 1019 | |
| 1020 | - $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; |
|
| 1020 | + $_wp_random_header = (object) $headers[array_rand($headers)]; |
|
| 1021 | 1021 | |
| 1022 | - $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 1023 | - $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 1022 | + $_wp_random_header->url = sprintf($_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri()); |
|
| 1023 | + $_wp_random_header->thumbnail_url = sprintf($_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri()); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | return $_wp_random_header; |
| 1026 | 1026 | } |
@@ -1034,7 +1034,7 @@ discard block |
||
| 1034 | 1034 | */ |
| 1035 | 1035 | function get_random_header_image() { |
| 1036 | 1036 | $random_image = _get_random_header_data(); |
| 1037 | - if ( empty( $random_image->url ) ) |
|
| 1037 | + if (empty($random_image->url)) |
|
| 1038 | 1038 | return ''; |
| 1039 | 1039 | return $random_image->url; |
| 1040 | 1040 | } |
@@ -1051,16 +1051,16 @@ discard block |
||
| 1051 | 1051 | * @param string $type The random pool to use. any|default|uploaded |
| 1052 | 1052 | * @return bool |
| 1053 | 1053 | */ |
| 1054 | -function is_random_header_image( $type = 'any' ) { |
|
| 1055 | - $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
| 1054 | +function is_random_header_image($type = 'any') { |
|
| 1055 | + $header_image_mod = get_theme_mod('header_image', get_theme_support('custom-header', 'default-image')); |
|
| 1056 | 1056 | |
| 1057 | - if ( 'any' == $type ) { |
|
| 1058 | - if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) |
|
| 1057 | + if ('any' == $type) { |
|
| 1058 | + if ('random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ('' != get_random_header_image() && empty($header_image_mod))) |
|
| 1059 | 1059 | return true; |
| 1060 | 1060 | } else { |
| 1061 | - if ( "random-$type-image" == $header_image_mod ) |
|
| 1061 | + if ("random-$type-image" == $header_image_mod) |
|
| 1062 | 1062 | return true; |
| 1063 | - elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) |
|
| 1063 | + elseif ('default' == $type && empty($header_image_mod) && '' != get_random_header_image()) |
|
| 1064 | 1064 | return true; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
@@ -1074,8 +1074,8 @@ discard block |
||
| 1074 | 1074 | */ |
| 1075 | 1075 | function header_image() { |
| 1076 | 1076 | $image = get_header_image(); |
| 1077 | - if ( $image ) { |
|
| 1078 | - echo esc_url( $image ); |
|
| 1077 | + if ($image) { |
|
| 1078 | + echo esc_url($image); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | |
@@ -1090,25 +1090,25 @@ discard block |
||
| 1090 | 1090 | $header_images = array(); |
| 1091 | 1091 | |
| 1092 | 1092 | // @todo caching |
| 1093 | - $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); |
|
| 1093 | + $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true)); |
|
| 1094 | 1094 | |
| 1095 | - if ( empty( $headers ) ) |
|
| 1095 | + if (empty($headers)) |
|
| 1096 | 1096 | return array(); |
| 1097 | 1097 | |
| 1098 | - foreach ( (array) $headers as $header ) { |
|
| 1099 | - $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); |
|
| 1100 | - $header_data = wp_get_attachment_metadata( $header->ID ); |
|
| 1098 | + foreach ((array) $headers as $header) { |
|
| 1099 | + $url = esc_url_raw(wp_get_attachment_url($header->ID)); |
|
| 1100 | + $header_data = wp_get_attachment_metadata($header->ID); |
|
| 1101 | 1101 | $header_index = basename($url); |
| 1102 | 1102 | |
| 1103 | 1103 | $header_images[$header_index] = array(); |
| 1104 | 1104 | $header_images[$header_index]['attachment_id'] = $header->ID; |
| 1105 | - $header_images[$header_index]['url'] = $url; |
|
| 1105 | + $header_images[$header_index]['url'] = $url; |
|
| 1106 | 1106 | $header_images[$header_index]['thumbnail_url'] = $url; |
| 1107 | - $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); |
|
| 1107 | + $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true); |
|
| 1108 | 1108 | |
| 1109 | - if ( isset( $header_data['width'] ) ) |
|
| 1109 | + if (isset($header_data['width'])) |
|
| 1110 | 1110 | $header_images[$header_index]['width'] = $header_data['width']; |
| 1111 | - if ( isset( $header_data['height'] ) ) |
|
| 1111 | + if (isset($header_data['height'])) |
|
| 1112 | 1112 | $header_images[$header_index]['height'] = $header_data['height']; |
| 1113 | 1113 | } |
| 1114 | 1114 | |
@@ -1127,21 +1127,21 @@ discard block |
||
| 1127 | 1127 | function get_custom_header() { |
| 1128 | 1128 | global $_wp_default_headers; |
| 1129 | 1129 | |
| 1130 | - if ( is_random_header_image() ) { |
|
| 1130 | + if (is_random_header_image()) { |
|
| 1131 | 1131 | $data = _get_random_header_data(); |
| 1132 | 1132 | } else { |
| 1133 | - $data = get_theme_mod( 'header_image_data' ); |
|
| 1134 | - if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { |
|
| 1135 | - $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 1133 | + $data = get_theme_mod('header_image_data'); |
|
| 1134 | + if ( ! $data && current_theme_supports('custom-header', 'default-image')) { |
|
| 1135 | + $directory_args = array(get_template_directory_uri(), get_stylesheet_directory_uri()); |
|
| 1136 | 1136 | $data = array(); |
| 1137 | - $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); |
|
| 1138 | - if ( ! empty( $_wp_default_headers ) ) { |
|
| 1139 | - foreach ( (array) $_wp_default_headers as $default_header ) { |
|
| 1140 | - $url = vsprintf( $default_header['url'], $directory_args ); |
|
| 1141 | - if ( $data['url'] == $url ) { |
|
| 1137 | + $data['url'] = $data['thumbnail_url'] = vsprintf(get_theme_support('custom-header', 'default-image'), $directory_args); |
|
| 1138 | + if ( ! empty($_wp_default_headers)) { |
|
| 1139 | + foreach ((array) $_wp_default_headers as $default_header) { |
|
| 1140 | + $url = vsprintf($default_header['url'], $directory_args); |
|
| 1141 | + if ($data['url'] == $url) { |
|
| 1142 | 1142 | $data = $default_header; |
| 1143 | 1143 | $data['url'] = $url; |
| 1144 | - $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); |
|
| 1144 | + $data['thumbnail_url'] = vsprintf($data['thumbnail_url'], $directory_args); |
|
| 1145 | 1145 | break; |
| 1146 | 1146 | } |
| 1147 | 1147 | } |
@@ -1152,10 +1152,10 @@ discard block |
||
| 1152 | 1152 | $default = array( |
| 1153 | 1153 | 'url' => '', |
| 1154 | 1154 | 'thumbnail_url' => '', |
| 1155 | - 'width' => get_theme_support( 'custom-header', 'width' ), |
|
| 1156 | - 'height' => get_theme_support( 'custom-header', 'height' ), |
|
| 1155 | + 'width' => get_theme_support('custom-header', 'width'), |
|
| 1156 | + 'height' => get_theme_support('custom-header', 'height'), |
|
| 1157 | 1157 | ); |
| 1158 | - return (object) wp_parse_args( $data, $default ); |
|
| 1158 | + return (object) wp_parse_args($data, $default); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | * |
| 1168 | 1168 | * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys. |
| 1169 | 1169 | */ |
| 1170 | -function register_default_headers( $headers ) { |
|
| 1170 | +function register_default_headers($headers) { |
|
| 1171 | 1171 | global $_wp_default_headers; |
| 1172 | 1172 | |
| 1173 | - $_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers ); |
|
| 1173 | + $_wp_default_headers = array_merge((array) $_wp_default_headers, (array) $headers); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | /** |
@@ -1188,12 +1188,12 @@ discard block |
||
| 1188 | 1188 | * @return bool|void A single header returns true on success, false on failure. |
| 1189 | 1189 | * There is currently no return value for multiple headers. |
| 1190 | 1190 | */ |
| 1191 | -function unregister_default_headers( $header ) { |
|
| 1191 | +function unregister_default_headers($header) { |
|
| 1192 | 1192 | global $_wp_default_headers; |
| 1193 | - if ( is_array( $header ) ) { |
|
| 1194 | - array_map( 'unregister_default_headers', $header ); |
|
| 1195 | - } elseif ( isset( $_wp_default_headers[ $header ] ) ) { |
|
| 1196 | - unset( $_wp_default_headers[ $header ] ); |
|
| 1193 | + if (is_array($header)) { |
|
| 1194 | + array_map('unregister_default_headers', $header); |
|
| 1195 | + } elseif (isset($_wp_default_headers[$header])) { |
|
| 1196 | + unset($_wp_default_headers[$header]); |
|
| 1197 | 1197 | return true; |
| 1198 | 1198 | } else { |
| 1199 | 1199 | return false; |
@@ -1208,7 +1208,7 @@ discard block |
||
| 1208 | 1208 | * @return string |
| 1209 | 1209 | */ |
| 1210 | 1210 | function get_background_image() { |
| 1211 | - return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) ); |
|
| 1211 | + return get_theme_mod('background_image', get_theme_support('custom-background', 'default-image')); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | /** |
@@ -1228,7 +1228,7 @@ discard block |
||
| 1228 | 1228 | * @return string |
| 1229 | 1229 | */ |
| 1230 | 1230 | function get_background_color() { |
| 1231 | - return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) ); |
|
| 1231 | + return get_theme_mod('background_color', get_theme_support('custom-background', 'default-color')); |
|
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | /** |
@@ -1248,44 +1248,44 @@ discard block |
||
| 1248 | 1248 | */ |
| 1249 | 1249 | function _custom_background_cb() { |
| 1250 | 1250 | // $background is the saved custom image, or the default image. |
| 1251 | - $background = set_url_scheme( get_background_image() ); |
|
| 1251 | + $background = set_url_scheme(get_background_image()); |
|
| 1252 | 1252 | |
| 1253 | 1253 | // $color is the saved custom color. |
| 1254 | 1254 | // A default has to be specified in style.css. It will not be printed here. |
| 1255 | 1255 | $color = get_background_color(); |
| 1256 | 1256 | |
| 1257 | - if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) { |
|
| 1257 | + if ($color === get_theme_support('custom-background', 'default-color')) { |
|
| 1258 | 1258 | $color = false; |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | - if ( ! $background && ! $color ) |
|
| 1261 | + if ( ! $background && ! $color) |
|
| 1262 | 1262 | return; |
| 1263 | 1263 | |
| 1264 | 1264 | $style = $color ? "background-color: #$color;" : ''; |
| 1265 | 1265 | |
| 1266 | - if ( $background ) { |
|
| 1266 | + if ($background) { |
|
| 1267 | 1267 | $image = " background-image: url('$background');"; |
| 1268 | 1268 | |
| 1269 | - $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
|
| 1270 | - if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) |
|
| 1269 | + $repeat = get_theme_mod('background_repeat', get_theme_support('custom-background', 'default-repeat')); |
|
| 1270 | + if ( ! in_array($repeat, array('no-repeat', 'repeat-x', 'repeat-y', 'repeat'))) |
|
| 1271 | 1271 | $repeat = 'repeat'; |
| 1272 | 1272 | $repeat = " background-repeat: $repeat;"; |
| 1273 | 1273 | |
| 1274 | - $position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
|
| 1275 | - if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) |
|
| 1274 | + $position = get_theme_mod('background_position_x', get_theme_support('custom-background', 'default-position-x')); |
|
| 1275 | + if ( ! in_array($position, array('center', 'right', 'left'))) |
|
| 1276 | 1276 | $position = 'left'; |
| 1277 | 1277 | $position = " background-position: top $position;"; |
| 1278 | 1278 | |
| 1279 | - $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
|
| 1280 | - if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) |
|
| 1279 | + $attachment = get_theme_mod('background_attachment', get_theme_support('custom-background', 'default-attachment')); |
|
| 1280 | + if ( ! in_array($attachment, array('fixed', 'scroll'))) |
|
| 1281 | 1281 | $attachment = 'scroll'; |
| 1282 | 1282 | $attachment = " background-attachment: $attachment;"; |
| 1283 | 1283 | |
| 1284 | - $style .= $image . $repeat . $position . $attachment; |
|
| 1284 | + $style .= $image.$repeat.$position.$attachment; |
|
| 1285 | 1285 | } |
| 1286 | 1286 | ?> |
| 1287 | 1287 | <style type="text/css" id="custom-background-css"> |
| 1288 | -body.custom-background { <?php echo trim( $style ); ?> } |
|
| 1288 | +body.custom-background { <?php echo trim($style); ?> } |
|
| 1289 | 1289 | </style> |
| 1290 | 1290 | <?php |
| 1291 | 1291 | } |
@@ -1312,21 +1312,21 @@ discard block |
||
| 1312 | 1312 | * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. |
| 1313 | 1313 | * Defaults to 'editor-style.css' |
| 1314 | 1314 | */ |
| 1315 | -function add_editor_style( $stylesheet = 'editor-style.css' ) { |
|
| 1316 | - add_theme_support( 'editor-style' ); |
|
| 1315 | +function add_editor_style($stylesheet = 'editor-style.css') { |
|
| 1316 | + add_theme_support('editor-style'); |
|
| 1317 | 1317 | |
| 1318 | - if ( ! is_admin() ) |
|
| 1318 | + if ( ! is_admin()) |
|
| 1319 | 1319 | return; |
| 1320 | 1320 | |
| 1321 | 1321 | global $editor_styles; |
| 1322 | 1322 | $editor_styles = (array) $editor_styles; |
| 1323 | 1323 | $stylesheet = (array) $stylesheet; |
| 1324 | - if ( is_rtl() ) { |
|
| 1324 | + if (is_rtl()) { |
|
| 1325 | 1325 | $rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]); |
| 1326 | 1326 | $stylesheet[] = $rtl_stylesheet; |
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | - $editor_styles = array_merge( $editor_styles, $stylesheet ); |
|
| 1329 | + $editor_styles = array_merge($editor_styles, $stylesheet); |
|
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | /** |
@@ -1339,10 +1339,10 @@ discard block |
||
| 1339 | 1339 | * @return bool True on success, false if there were no stylesheets to remove. |
| 1340 | 1340 | */ |
| 1341 | 1341 | function remove_editor_styles() { |
| 1342 | - if ( ! current_theme_supports( 'editor-style' ) ) |
|
| 1342 | + if ( ! current_theme_supports('editor-style')) |
|
| 1343 | 1343 | return false; |
| 1344 | - _remove_theme_support( 'editor-style' ); |
|
| 1345 | - if ( is_admin() ) |
|
| 1344 | + _remove_theme_support('editor-style'); |
|
| 1345 | + if (is_admin()) |
|
| 1346 | 1346 | $GLOBALS['editor_styles'] = array(); |
| 1347 | 1347 | return true; |
| 1348 | 1348 | } |
@@ -1359,35 +1359,35 @@ discard block |
||
| 1359 | 1359 | function get_editor_stylesheets() { |
| 1360 | 1360 | $stylesheets = array(); |
| 1361 | 1361 | // load editor_style.css if the current theme supports it |
| 1362 | - if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { |
|
| 1362 | + if ( ! empty($GLOBALS['editor_styles']) && is_array($GLOBALS['editor_styles'])) { |
|
| 1363 | 1363 | $editor_styles = $GLOBALS['editor_styles']; |
| 1364 | 1364 | |
| 1365 | - $editor_styles = array_unique( array_filter( $editor_styles ) ); |
|
| 1365 | + $editor_styles = array_unique(array_filter($editor_styles)); |
|
| 1366 | 1366 | $style_uri = get_stylesheet_directory_uri(); |
| 1367 | 1367 | $style_dir = get_stylesheet_directory(); |
| 1368 | 1368 | |
| 1369 | 1369 | // Support externally referenced styles (like, say, fonts). |
| 1370 | - foreach ( $editor_styles as $key => $file ) { |
|
| 1371 | - if ( preg_match( '~^(https?:)?//~', $file ) ) { |
|
| 1372 | - $stylesheets[] = esc_url_raw( $file ); |
|
| 1373 | - unset( $editor_styles[ $key ] ); |
|
| 1370 | + foreach ($editor_styles as $key => $file) { |
|
| 1371 | + if (preg_match('~^(https?:)?//~', $file)) { |
|
| 1372 | + $stylesheets[] = esc_url_raw($file); |
|
| 1373 | + unset($editor_styles[$key]); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | 1377 | // Look in a parent theme first, that way child theme CSS overrides. |
| 1378 | - if ( is_child_theme() ) { |
|
| 1378 | + if (is_child_theme()) { |
|
| 1379 | 1379 | $template_uri = get_template_directory_uri(); |
| 1380 | 1380 | $template_dir = get_template_directory(); |
| 1381 | 1381 | |
| 1382 | - foreach ( $editor_styles as $key => $file ) { |
|
| 1383 | - if ( $file && file_exists( "$template_dir/$file" ) ) { |
|
| 1382 | + foreach ($editor_styles as $key => $file) { |
|
| 1383 | + if ($file && file_exists("$template_dir/$file")) { |
|
| 1384 | 1384 | $stylesheets[] = "$template_uri/$file"; |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | - foreach ( $editor_styles as $file ) { |
|
| 1390 | - if ( $file && file_exists( "$style_dir/$file" ) ) { |
|
| 1389 | + foreach ($editor_styles as $file) { |
|
| 1390 | + if ($file && file_exists("$style_dir/$file")) { |
|
| 1391 | 1391 | $stylesheets[] = "$style_uri/$file"; |
| 1392 | 1392 | } |
| 1393 | 1393 | } |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | * |
| 1401 | 1401 | * @param array $stylesheets Array of stylesheets to be applied to the editor. |
| 1402 | 1402 | */ |
| 1403 | - return apply_filters( 'editor_stylesheets', $stylesheets ); |
|
| 1403 | + return apply_filters('editor_stylesheets', $stylesheets); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | /** |
@@ -1417,45 +1417,45 @@ discard block |
||
| 1417 | 1417 | * @param string $feature The feature being added. |
| 1418 | 1418 | * @return void|bool False on failure, void otherwise. |
| 1419 | 1419 | */ |
| 1420 | -function add_theme_support( $feature ) { |
|
| 1420 | +function add_theme_support($feature) { |
|
| 1421 | 1421 | global $_wp_theme_features; |
| 1422 | 1422 | |
| 1423 | - if ( func_num_args() == 1 ) |
|
| 1423 | + if (func_num_args() == 1) |
|
| 1424 | 1424 | $args = true; |
| 1425 | 1425 | else |
| 1426 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1426 | + $args = array_slice(func_get_args(), 1); |
|
| 1427 | 1427 | |
| 1428 | - switch ( $feature ) { |
|
| 1428 | + switch ($feature) { |
|
| 1429 | 1429 | case 'post-formats' : |
| 1430 | - if ( is_array( $args[0] ) ) { |
|
| 1430 | + if (is_array($args[0])) { |
|
| 1431 | 1431 | $post_formats = get_post_format_slugs(); |
| 1432 | - unset( $post_formats['standard'] ); |
|
| 1432 | + unset($post_formats['standard']); |
|
| 1433 | 1433 | |
| 1434 | - $args[0] = array_intersect( $args[0], array_keys( $post_formats ) ); |
|
| 1434 | + $args[0] = array_intersect($args[0], array_keys($post_formats)); |
|
| 1435 | 1435 | } |
| 1436 | 1436 | break; |
| 1437 | 1437 | |
| 1438 | 1438 | case 'html5' : |
| 1439 | 1439 | // You can't just pass 'html5', you need to pass an array of types. |
| 1440 | - if ( empty( $args[0] ) ) { |
|
| 1440 | + if (empty($args[0])) { |
|
| 1441 | 1441 | // Build an array of types for back-compat. |
| 1442 | - $args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) ); |
|
| 1443 | - } elseif ( ! is_array( $args[0] ) ) { |
|
| 1444 | - _doing_it_wrong( "add_theme_support( 'html5' )", __( 'You need to pass an array of types.' ), '3.6.1' ); |
|
| 1442 | + $args = array(0 => array('comment-list', 'comment-form', 'search-form')); |
|
| 1443 | + } elseif ( ! is_array($args[0])) { |
|
| 1444 | + _doing_it_wrong("add_theme_support( 'html5' )", __('You need to pass an array of types.'), '3.6.1'); |
|
| 1445 | 1445 | return false; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | // Calling 'html5' again merges, rather than overwrites. |
| 1449 | - if ( isset( $_wp_theme_features['html5'] ) ) |
|
| 1450 | - $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); |
|
| 1449 | + if (isset($_wp_theme_features['html5'])) |
|
| 1450 | + $args[0] = array_merge($_wp_theme_features['html5'][0], $args[0]); |
|
| 1451 | 1451 | break; |
| 1452 | 1452 | |
| 1453 | 1453 | case 'custom-header-uploads' : |
| 1454 | - return add_theme_support( 'custom-header', array( 'uploads' => true ) ); |
|
| 1454 | + return add_theme_support('custom-header', array('uploads' => true)); |
|
| 1455 | 1455 | |
| 1456 | 1456 | case 'custom-header' : |
| 1457 | - if ( ! is_array( $args ) ) |
|
| 1458 | - $args = array( 0 => array() ); |
|
| 1457 | + if ( ! is_array($args)) |
|
| 1458 | + $args = array(0 => array()); |
|
| 1459 | 1459 | |
| 1460 | 1460 | $defaults = array( |
| 1461 | 1461 | 'default-image' => '', |
@@ -1472,18 +1472,18 @@ discard block |
||
| 1472 | 1472 | 'admin-preview-callback' => '', |
| 1473 | 1473 | ); |
| 1474 | 1474 | |
| 1475 | - $jit = isset( $args[0]['__jit'] ); |
|
| 1476 | - unset( $args[0]['__jit'] ); |
|
| 1475 | + $jit = isset($args[0]['__jit']); |
|
| 1476 | + unset($args[0]['__jit']); |
|
| 1477 | 1477 | |
| 1478 | 1478 | // Merge in data from previous add_theme_support() calls. |
| 1479 | 1479 | // The first value registered wins. (A child theme is set up first.) |
| 1480 | - if ( isset( $_wp_theme_features['custom-header'] ) ) |
|
| 1481 | - $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); |
|
| 1480 | + if (isset($_wp_theme_features['custom-header'])) |
|
| 1481 | + $args[0] = wp_parse_args($_wp_theme_features['custom-header'][0], $args[0]); |
|
| 1482 | 1482 | |
| 1483 | 1483 | // Load in the defaults at the end, as we need to insure first one wins. |
| 1484 | 1484 | // This will cause all constants to be defined, as each arg will then be set to the default. |
| 1485 | - if ( $jit ) |
|
| 1486 | - $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1485 | + if ($jit) |
|
| 1486 | + $args[0] = wp_parse_args($args[0], $defaults); |
|
| 1487 | 1487 | |
| 1488 | 1488 | // If a constant was defined, use that value. Otherwise, define the constant to ensure |
| 1489 | 1489 | // the constant is always accurate (and is not defined later, overriding our value). |
@@ -1491,48 +1491,48 @@ discard block |
||
| 1491 | 1491 | // Once we get to wp_loaded (just-in-time), define any constants we haven't already. |
| 1492 | 1492 | // Constants are lame. Don't reference them. This is just for backwards compatibility. |
| 1493 | 1493 | |
| 1494 | - if ( defined( 'NO_HEADER_TEXT' ) ) |
|
| 1494 | + if (defined('NO_HEADER_TEXT')) |
|
| 1495 | 1495 | $args[0]['header-text'] = ! NO_HEADER_TEXT; |
| 1496 | - elseif ( isset( $args[0]['header-text'] ) ) |
|
| 1497 | - define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); |
|
| 1496 | + elseif (isset($args[0]['header-text'])) |
|
| 1497 | + define('NO_HEADER_TEXT', empty($args[0]['header-text'])); |
|
| 1498 | 1498 | |
| 1499 | - if ( defined( 'HEADER_IMAGE_WIDTH' ) ) |
|
| 1499 | + if (defined('HEADER_IMAGE_WIDTH')) |
|
| 1500 | 1500 | $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; |
| 1501 | - elseif ( isset( $args[0]['width'] ) ) |
|
| 1502 | - define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); |
|
| 1501 | + elseif (isset($args[0]['width'])) |
|
| 1502 | + define('HEADER_IMAGE_WIDTH', (int) $args[0]['width']); |
|
| 1503 | 1503 | |
| 1504 | - if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) |
|
| 1504 | + if (defined('HEADER_IMAGE_HEIGHT')) |
|
| 1505 | 1505 | $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; |
| 1506 | - elseif ( isset( $args[0]['height'] ) ) |
|
| 1507 | - define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); |
|
| 1506 | + elseif (isset($args[0]['height'])) |
|
| 1507 | + define('HEADER_IMAGE_HEIGHT', (int) $args[0]['height']); |
|
| 1508 | 1508 | |
| 1509 | - if ( defined( 'HEADER_TEXTCOLOR' ) ) |
|
| 1509 | + if (defined('HEADER_TEXTCOLOR')) |
|
| 1510 | 1510 | $args[0]['default-text-color'] = HEADER_TEXTCOLOR; |
| 1511 | - elseif ( isset( $args[0]['default-text-color'] ) ) |
|
| 1512 | - define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); |
|
| 1511 | + elseif (isset($args[0]['default-text-color'])) |
|
| 1512 | + define('HEADER_TEXTCOLOR', $args[0]['default-text-color']); |
|
| 1513 | 1513 | |
| 1514 | - if ( defined( 'HEADER_IMAGE' ) ) |
|
| 1514 | + if (defined('HEADER_IMAGE')) |
|
| 1515 | 1515 | $args[0]['default-image'] = HEADER_IMAGE; |
| 1516 | - elseif ( isset( $args[0]['default-image'] ) ) |
|
| 1517 | - define( 'HEADER_IMAGE', $args[0]['default-image'] ); |
|
| 1516 | + elseif (isset($args[0]['default-image'])) |
|
| 1517 | + define('HEADER_IMAGE', $args[0]['default-image']); |
|
| 1518 | 1518 | |
| 1519 | - if ( $jit && ! empty( $args[0]['default-image'] ) ) |
|
| 1519 | + if ($jit && ! empty($args[0]['default-image'])) |
|
| 1520 | 1520 | $args[0]['random-default'] = false; |
| 1521 | 1521 | |
| 1522 | 1522 | // If headers are supported, and we still don't have a defined width or height, |
| 1523 | 1523 | // we have implicit flex sizes. |
| 1524 | - if ( $jit ) { |
|
| 1525 | - if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) |
|
| 1524 | + if ($jit) { |
|
| 1525 | + if (empty($args[0]['width']) && empty($args[0]['flex-width'])) |
|
| 1526 | 1526 | $args[0]['flex-width'] = true; |
| 1527 | - if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) |
|
| 1527 | + if (empty($args[0]['height']) && empty($args[0]['flex-height'])) |
|
| 1528 | 1528 | $args[0]['flex-height'] = true; |
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | break; |
| 1532 | 1532 | |
| 1533 | 1533 | case 'custom-background' : |
| 1534 | - if ( ! is_array( $args ) ) |
|
| 1535 | - $args = array( 0 => array() ); |
|
| 1534 | + if ( ! is_array($args)) |
|
| 1535 | + $args = array(0 => array()); |
|
| 1536 | 1536 | |
| 1537 | 1537 | $defaults = array( |
| 1538 | 1538 | 'default-image' => '', |
@@ -1545,41 +1545,41 @@ discard block |
||
| 1545 | 1545 | 'admin-preview-callback' => '', |
| 1546 | 1546 | ); |
| 1547 | 1547 | |
| 1548 | - $jit = isset( $args[0]['__jit'] ); |
|
| 1549 | - unset( $args[0]['__jit'] ); |
|
| 1548 | + $jit = isset($args[0]['__jit']); |
|
| 1549 | + unset($args[0]['__jit']); |
|
| 1550 | 1550 | |
| 1551 | 1551 | // Merge in data from previous add_theme_support() calls. The first value registered wins. |
| 1552 | - if ( isset( $_wp_theme_features['custom-background'] ) ) |
|
| 1553 | - $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); |
|
| 1552 | + if (isset($_wp_theme_features['custom-background'])) |
|
| 1553 | + $args[0] = wp_parse_args($_wp_theme_features['custom-background'][0], $args[0]); |
|
| 1554 | 1554 | |
| 1555 | - if ( $jit ) |
|
| 1556 | - $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1555 | + if ($jit) |
|
| 1556 | + $args[0] = wp_parse_args($args[0], $defaults); |
|
| 1557 | 1557 | |
| 1558 | - if ( defined( 'BACKGROUND_COLOR' ) ) |
|
| 1558 | + if (defined('BACKGROUND_COLOR')) |
|
| 1559 | 1559 | $args[0]['default-color'] = BACKGROUND_COLOR; |
| 1560 | - elseif ( isset( $args[0]['default-color'] ) || $jit ) |
|
| 1561 | - define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); |
|
| 1560 | + elseif (isset($args[0]['default-color']) || $jit) |
|
| 1561 | + define('BACKGROUND_COLOR', $args[0]['default-color']); |
|
| 1562 | 1562 | |
| 1563 | - if ( defined( 'BACKGROUND_IMAGE' ) ) |
|
| 1563 | + if (defined('BACKGROUND_IMAGE')) |
|
| 1564 | 1564 | $args[0]['default-image'] = BACKGROUND_IMAGE; |
| 1565 | - elseif ( isset( $args[0]['default-image'] ) || $jit ) |
|
| 1566 | - define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); |
|
| 1565 | + elseif (isset($args[0]['default-image']) || $jit) |
|
| 1566 | + define('BACKGROUND_IMAGE', $args[0]['default-image']); |
|
| 1567 | 1567 | |
| 1568 | 1568 | break; |
| 1569 | 1569 | |
| 1570 | 1570 | // Ensure that 'title-tag' is accessible in the admin. |
| 1571 | 1571 | case 'title-tag' : |
| 1572 | 1572 | // Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. |
| 1573 | - if ( did_action( 'wp_loaded' ) ) { |
|
| 1573 | + if (did_action('wp_loaded')) { |
|
| 1574 | 1574 | /* translators: 1: Theme support 2: hook name */ |
| 1575 | - _doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( __( 'Theme support for %1$s should be registered before the %2$s hook.' ), |
|
| 1576 | - '<code>title-tag</code>', '<code>wp_loaded</code>' ), '4.1' ); |
|
| 1575 | + _doing_it_wrong("add_theme_support( 'title-tag' )", sprintf(__('Theme support for %1$s should be registered before the %2$s hook.'), |
|
| 1576 | + '<code>title-tag</code>', '<code>wp_loaded</code>'), '4.1'); |
|
| 1577 | 1577 | |
| 1578 | 1578 | return false; |
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - $_wp_theme_features[ $feature ] = $args; |
|
| 1582 | + $_wp_theme_features[$feature] = $args; |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | /** |
@@ -1594,30 +1594,30 @@ discard block |
||
| 1594 | 1594 | function _custom_header_background_just_in_time() { |
| 1595 | 1595 | global $custom_image_header, $custom_background; |
| 1596 | 1596 | |
| 1597 | - if ( current_theme_supports( 'custom-header' ) ) { |
|
| 1597 | + if (current_theme_supports('custom-header')) { |
|
| 1598 | 1598 | // In case any constants were defined after an add_custom_image_header() call, re-run. |
| 1599 | - add_theme_support( 'custom-header', array( '__jit' => true ) ); |
|
| 1599 | + add_theme_support('custom-header', array('__jit' => true)); |
|
| 1600 | 1600 | |
| 1601 | - $args = get_theme_support( 'custom-header' ); |
|
| 1602 | - if ( $args[0]['wp-head-callback'] ) |
|
| 1603 | - add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
| 1601 | + $args = get_theme_support('custom-header'); |
|
| 1602 | + if ($args[0]['wp-head-callback']) |
|
| 1603 | + add_action('wp_head', $args[0]['wp-head-callback']); |
|
| 1604 | 1604 | |
| 1605 | - if ( is_admin() ) { |
|
| 1606 | - require_once( ABSPATH . 'wp-admin/custom-header.php' ); |
|
| 1607 | - $custom_image_header = new Custom_Image_Header( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
|
| 1605 | + if (is_admin()) { |
|
| 1606 | + require_once(ABSPATH.'wp-admin/custom-header.php'); |
|
| 1607 | + $custom_image_header = new Custom_Image_Header($args[0]['admin-head-callback'], $args[0]['admin-preview-callback']); |
|
| 1608 | 1608 | } |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - if ( current_theme_supports( 'custom-background' ) ) { |
|
| 1611 | + if (current_theme_supports('custom-background')) { |
|
| 1612 | 1612 | // In case any constants were defined after an add_custom_background() call, re-run. |
| 1613 | - add_theme_support( 'custom-background', array( '__jit' => true ) ); |
|
| 1613 | + add_theme_support('custom-background', array('__jit' => true)); |
|
| 1614 | 1614 | |
| 1615 | - $args = get_theme_support( 'custom-background' ); |
|
| 1616 | - add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
| 1615 | + $args = get_theme_support('custom-background'); |
|
| 1616 | + add_action('wp_head', $args[0]['wp-head-callback']); |
|
| 1617 | 1617 | |
| 1618 | - if ( is_admin() ) { |
|
| 1619 | - require_once( ABSPATH . 'wp-admin/custom-background.php' ); |
|
| 1620 | - $custom_background = new Custom_Background( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
|
| 1618 | + if (is_admin()) { |
|
| 1619 | + require_once(ABSPATH.'wp-admin/custom-background.php'); |
|
| 1620 | + $custom_background = new Custom_Background($args[0]['admin-head-callback'], $args[0]['admin-preview-callback']); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | } |
| 1623 | 1623 | } |
@@ -1632,24 +1632,24 @@ discard block |
||
| 1632 | 1632 | * @param string $feature the feature to check |
| 1633 | 1633 | * @return mixed The array of extra arguments or the value for the registered feature. |
| 1634 | 1634 | */ |
| 1635 | -function get_theme_support( $feature ) { |
|
| 1635 | +function get_theme_support($feature) { |
|
| 1636 | 1636 | global $_wp_theme_features; |
| 1637 | - if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
| 1637 | + if ( ! isset($_wp_theme_features[$feature])) |
|
| 1638 | 1638 | return false; |
| 1639 | 1639 | |
| 1640 | - if ( func_num_args() <= 1 ) |
|
| 1641 | - return $_wp_theme_features[ $feature ]; |
|
| 1640 | + if (func_num_args() <= 1) |
|
| 1641 | + return $_wp_theme_features[$feature]; |
|
| 1642 | 1642 | |
| 1643 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1644 | - switch ( $feature ) { |
|
| 1643 | + $args = array_slice(func_get_args(), 1); |
|
| 1644 | + switch ($feature) { |
|
| 1645 | 1645 | case 'custom-header' : |
| 1646 | 1646 | case 'custom-background' : |
| 1647 | - if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) |
|
| 1648 | - return $_wp_theme_features[ $feature ][0][ $args[0] ]; |
|
| 1647 | + if (isset($_wp_theme_features[$feature][0][$args[0]])) |
|
| 1648 | + return $_wp_theme_features[$feature][0][$args[0]]; |
|
| 1649 | 1649 | return false; |
| 1650 | 1650 | |
| 1651 | 1651 | default : |
| 1652 | - return $_wp_theme_features[ $feature ]; |
|
| 1652 | + return $_wp_theme_features[$feature]; |
|
| 1653 | 1653 | } |
| 1654 | 1654 | } |
| 1655 | 1655 | |
@@ -1664,12 +1664,12 @@ discard block |
||
| 1664 | 1664 | * @param string $feature the feature being added |
| 1665 | 1665 | * @return bool|void Whether feature was removed. |
| 1666 | 1666 | */ |
| 1667 | -function remove_theme_support( $feature ) { |
|
| 1667 | +function remove_theme_support($feature) { |
|
| 1668 | 1668 | // Blacklist: for internal registrations not used directly by themes. |
| 1669 | - if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) |
|
| 1669 | + if (in_array($feature, array('editor-style', 'widgets', 'menus'))) |
|
| 1670 | 1670 | return false; |
| 1671 | 1671 | |
| 1672 | - return _remove_theme_support( $feature ); |
|
| 1672 | + return _remove_theme_support($feature); |
|
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | /** |
@@ -1684,42 +1684,42 @@ discard block |
||
| 1684 | 1684 | * |
| 1685 | 1685 | * @param string $feature |
| 1686 | 1686 | */ |
| 1687 | -function _remove_theme_support( $feature ) { |
|
| 1687 | +function _remove_theme_support($feature) { |
|
| 1688 | 1688 | global $_wp_theme_features; |
| 1689 | 1689 | |
| 1690 | - switch ( $feature ) { |
|
| 1690 | + switch ($feature) { |
|
| 1691 | 1691 | case 'custom-header-uploads' : |
| 1692 | - if ( ! isset( $_wp_theme_features['custom-header'] ) ) |
|
| 1692 | + if ( ! isset($_wp_theme_features['custom-header'])) |
|
| 1693 | 1693 | return false; |
| 1694 | - add_theme_support( 'custom-header', array( 'uploads' => false ) ); |
|
| 1694 | + add_theme_support('custom-header', array('uploads' => false)); |
|
| 1695 | 1695 | return; // Do not continue - custom-header-uploads no longer exists. |
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | - if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
| 1698 | + if ( ! isset($_wp_theme_features[$feature])) |
|
| 1699 | 1699 | return false; |
| 1700 | 1700 | |
| 1701 | - switch ( $feature ) { |
|
| 1701 | + switch ($feature) { |
|
| 1702 | 1702 | case 'custom-header' : |
| 1703 | - if ( ! did_action( 'wp_loaded' ) ) |
|
| 1703 | + if ( ! did_action('wp_loaded')) |
|
| 1704 | 1704 | break; |
| 1705 | - $support = get_theme_support( 'custom-header' ); |
|
| 1706 | - if ( $support[0]['wp-head-callback'] ) |
|
| 1707 | - remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
| 1708 | - remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) ); |
|
| 1709 | - unset( $GLOBALS['custom_image_header'] ); |
|
| 1705 | + $support = get_theme_support('custom-header'); |
|
| 1706 | + if ($support[0]['wp-head-callback']) |
|
| 1707 | + remove_action('wp_head', $support[0]['wp-head-callback']); |
|
| 1708 | + remove_action('admin_menu', array($GLOBALS['custom_image_header'], 'init')); |
|
| 1709 | + unset($GLOBALS['custom_image_header']); |
|
| 1710 | 1710 | break; |
| 1711 | 1711 | |
| 1712 | 1712 | case 'custom-background' : |
| 1713 | - if ( ! did_action( 'wp_loaded' ) ) |
|
| 1713 | + if ( ! did_action('wp_loaded')) |
|
| 1714 | 1714 | break; |
| 1715 | - $support = get_theme_support( 'custom-background' ); |
|
| 1716 | - remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
| 1717 | - remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); |
|
| 1718 | - unset( $GLOBALS['custom_background'] ); |
|
| 1715 | + $support = get_theme_support('custom-background'); |
|
| 1716 | + remove_action('wp_head', $support[0]['wp-head-callback']); |
|
| 1717 | + remove_action('admin_menu', array($GLOBALS['custom_background'], 'init')); |
|
| 1718 | + unset($GLOBALS['custom_background']); |
|
| 1719 | 1719 | break; |
| 1720 | 1720 | } |
| 1721 | 1721 | |
| 1722 | - unset( $_wp_theme_features[ $feature ] ); |
|
| 1722 | + unset($_wp_theme_features[$feature]); |
|
| 1723 | 1723 | return true; |
| 1724 | 1724 | } |
| 1725 | 1725 | |
@@ -1733,38 +1733,38 @@ discard block |
||
| 1733 | 1733 | * @param string $feature the feature being checked |
| 1734 | 1734 | * @return bool |
| 1735 | 1735 | */ |
| 1736 | -function current_theme_supports( $feature ) { |
|
| 1736 | +function current_theme_supports($feature) { |
|
| 1737 | 1737 | global $_wp_theme_features; |
| 1738 | 1738 | |
| 1739 | - if ( 'custom-header-uploads' == $feature ) |
|
| 1740 | - return current_theme_supports( 'custom-header', 'uploads' ); |
|
| 1739 | + if ('custom-header-uploads' == $feature) |
|
| 1740 | + return current_theme_supports('custom-header', 'uploads'); |
|
| 1741 | 1741 | |
| 1742 | - if ( !isset( $_wp_theme_features[$feature] ) ) |
|
| 1742 | + if ( ! isset($_wp_theme_features[$feature])) |
|
| 1743 | 1743 | return false; |
| 1744 | 1744 | |
| 1745 | - if ( 'title-tag' == $feature ) { |
|
| 1745 | + if ('title-tag' == $feature) { |
|
| 1746 | 1746 | // Don't confirm support unless called internally. |
| 1747 | 1747 | $trace = debug_backtrace(); |
| 1748 | - if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) { |
|
| 1748 | + if ( ! in_array($trace[1]['function'], array('_wp_render_title_tag', 'wp_title'))) { |
|
| 1749 | 1749 | return false; |
| 1750 | 1750 | } |
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | 1753 | // If no args passed then no extra checks need be performed |
| 1754 | - if ( func_num_args() <= 1 ) |
|
| 1754 | + if (func_num_args() <= 1) |
|
| 1755 | 1755 | return true; |
| 1756 | 1756 | |
| 1757 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1757 | + $args = array_slice(func_get_args(), 1); |
|
| 1758 | 1758 | |
| 1759 | - switch ( $feature ) { |
|
| 1759 | + switch ($feature) { |
|
| 1760 | 1760 | case 'post-thumbnails': |
| 1761 | 1761 | // post-thumbnails can be registered for only certain content/post types by passing |
| 1762 | 1762 | // an array of types to add_theme_support(). If no array was passed, then |
| 1763 | 1763 | // any type is accepted |
| 1764 | - if ( true === $_wp_theme_features[$feature] ) // Registered for all types |
|
| 1764 | + if (true === $_wp_theme_features[$feature]) // Registered for all types |
|
| 1765 | 1765 | return true; |
| 1766 | 1766 | $content_type = $args[0]; |
| 1767 | - return in_array( $content_type, $_wp_theme_features[$feature][0] ); |
|
| 1767 | + return in_array($content_type, $_wp_theme_features[$feature][0]); |
|
| 1768 | 1768 | |
| 1769 | 1769 | case 'html5': |
| 1770 | 1770 | case 'post-formats': |
@@ -1774,14 +1774,14 @@ discard block |
||
| 1774 | 1774 | // Specific areas of HTML5 support *must* be passed via an array to add_theme_support() |
| 1775 | 1775 | |
| 1776 | 1776 | $type = $args[0]; |
| 1777 | - return in_array( $type, $_wp_theme_features[$feature][0] ); |
|
| 1777 | + return in_array($type, $_wp_theme_features[$feature][0]); |
|
| 1778 | 1778 | |
| 1779 | 1779 | case 'custom-header': |
| 1780 | 1780 | case 'custom-background' : |
| 1781 | 1781 | // specific custom header and background capabilities can be registered by passing |
| 1782 | 1782 | // an array to add_theme_support() |
| 1783 | 1783 | $header_support = $args[0]; |
| 1784 | - return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] ); |
|
| 1784 | + return (isset($_wp_theme_features[$feature][0][$header_support]) && $_wp_theme_features[$feature][0][$header_support]); |
|
| 1785 | 1785 | } |
| 1786 | 1786 | |
| 1787 | 1787 | /** |
@@ -1797,7 +1797,7 @@ discard block |
||
| 1797 | 1797 | * @param array $args Array of arguments for the feature. |
| 1798 | 1798 | * @param string $feature The theme feature. |
| 1799 | 1799 | */ |
| 1800 | - return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); |
|
| 1800 | + return apply_filters("current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature]); |
|
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | /** |
@@ -1809,9 +1809,9 @@ discard block |
||
| 1809 | 1809 | * @param string $include Path to the file. |
| 1810 | 1810 | * @return bool True if the current theme supports the supplied feature, false otherwise. |
| 1811 | 1811 | */ |
| 1812 | -function require_if_theme_supports( $feature, $include ) { |
|
| 1813 | - if ( current_theme_supports( $feature ) ) { |
|
| 1814 | - require ( $include ); |
|
| 1812 | +function require_if_theme_supports($feature, $include) { |
|
| 1813 | + if (current_theme_supports($feature)) { |
|
| 1814 | + require ($include); |
|
| 1815 | 1815 | return true; |
| 1816 | 1816 | } |
| 1817 | 1817 | return false; |
@@ -1829,18 +1829,18 @@ discard block |
||
| 1829 | 1829 | * |
| 1830 | 1830 | * @param int $id The attachment id. |
| 1831 | 1831 | */ |
| 1832 | -function _delete_attachment_theme_mod( $id ) { |
|
| 1833 | - $attachment_image = wp_get_attachment_url( $id ); |
|
| 1832 | +function _delete_attachment_theme_mod($id) { |
|
| 1833 | + $attachment_image = wp_get_attachment_url($id); |
|
| 1834 | 1834 | $header_image = get_header_image(); |
| 1835 | 1835 | $background_image = get_background_image(); |
| 1836 | 1836 | |
| 1837 | - if ( $header_image && $header_image == $attachment_image ) { |
|
| 1838 | - remove_theme_mod( 'header_image' ); |
|
| 1839 | - remove_theme_mod( 'header_image_data' ); |
|
| 1837 | + if ($header_image && $header_image == $attachment_image) { |
|
| 1838 | + remove_theme_mod('header_image'); |
|
| 1839 | + remove_theme_mod('header_image_data'); |
|
| 1840 | 1840 | } |
| 1841 | 1841 | |
| 1842 | - if ( $background_image && $background_image == $attachment_image ) { |
|
| 1843 | - remove_theme_mod( 'background_image' ); |
|
| 1842 | + if ($background_image && $background_image == $attachment_image) { |
|
| 1843 | + remove_theme_mod('background_image'); |
|
| 1844 | 1844 | } |
| 1845 | 1845 | } |
| 1846 | 1846 | |
@@ -1850,16 +1850,16 @@ discard block |
||
| 1850 | 1850 | * @since 3.3.0 |
| 1851 | 1851 | */ |
| 1852 | 1852 | function check_theme_switched() { |
| 1853 | - if ( $stylesheet = get_option( 'theme_switched' ) ) { |
|
| 1854 | - $old_theme = wp_get_theme( $stylesheet ); |
|
| 1853 | + if ($stylesheet = get_option('theme_switched')) { |
|
| 1854 | + $old_theme = wp_get_theme($stylesheet); |
|
| 1855 | 1855 | |
| 1856 | 1856 | // Prevent retrieve_widgets() from running since Customizer already called it up front |
| 1857 | - if ( get_option( 'theme_switched_via_customizer' ) ) { |
|
| 1858 | - remove_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
|
| 1859 | - update_option( 'theme_switched_via_customizer', false ); |
|
| 1857 | + if (get_option('theme_switched_via_customizer')) { |
|
| 1858 | + remove_action('after_switch_theme', '_wp_sidebars_changed'); |
|
| 1859 | + update_option('theme_switched_via_customizer', false); |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | - if ( $old_theme->exists() ) { |
|
| 1862 | + if ($old_theme->exists()) { |
|
| 1863 | 1863 | /** |
| 1864 | 1864 | * Fires on the first WP load after a theme switch if the old theme still exists. |
| 1865 | 1865 | * |
@@ -1873,13 +1873,13 @@ discard block |
||
| 1873 | 1873 | * @param string $old_name Old theme name. |
| 1874 | 1874 | * @param WP_Theme $old_theme WP_Theme instance of the old theme. |
| 1875 | 1875 | */ |
| 1876 | - do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme ); |
|
| 1876 | + do_action('after_switch_theme', $old_theme->get('Name'), $old_theme); |
|
| 1877 | 1877 | } else { |
| 1878 | 1878 | /** This action is documented in wp-includes/theme.php */ |
| 1879 | - do_action( 'after_switch_theme', $stylesheet ); |
|
| 1879 | + do_action('after_switch_theme', $stylesheet); |
|
| 1880 | 1880 | } |
| 1881 | 1881 | |
| 1882 | - update_option( 'theme_switched', false ); |
|
| 1882 | + update_option('theme_switched', false); |
|
| 1883 | 1883 | } |
| 1884 | 1884 | } |
| 1885 | 1885 | |
@@ -1893,12 +1893,12 @@ discard block |
||
| 1893 | 1893 | * @global WP_Customize_Manager $wp_customize |
| 1894 | 1894 | */ |
| 1895 | 1895 | function _wp_customize_include() { |
| 1896 | - if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) |
|
| 1897 | - || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) |
|
| 1898 | - ) ) |
|
| 1896 | + if ( ! ((isset($_REQUEST['wp_customize']) && 'on' == $_REQUEST['wp_customize']) |
|
| 1897 | + || (is_admin() && 'customize.php' == basename($_SERVER['PHP_SELF'])) |
|
| 1898 | + )) |
|
| 1899 | 1899 | return; |
| 1900 | 1900 | |
| 1901 | - require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
|
| 1901 | + require_once ABSPATH.WPINC.'/class-wp-customize-manager.php'; |
|
| 1902 | 1902 | $GLOBALS['wp_customize'] = new WP_Customize_Manager(); |
| 1903 | 1903 | } |
| 1904 | 1904 | |
@@ -1908,33 +1908,33 @@ discard block |
||
| 1908 | 1908 | * @since 3.4.0 |
| 1909 | 1909 | */ |
| 1910 | 1910 | function _wp_customize_loader_settings() { |
| 1911 | - $admin_origin = parse_url( admin_url() ); |
|
| 1912 | - $home_origin = parse_url( home_url() ); |
|
| 1913 | - $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); |
|
| 1911 | + $admin_origin = parse_url(admin_url()); |
|
| 1912 | + $home_origin = parse_url(home_url()); |
|
| 1913 | + $cross_domain = (strtolower($admin_origin['host']) != strtolower($home_origin['host'])); |
|
| 1914 | 1914 | |
| 1915 | 1915 | $browser = array( |
| 1916 | 1916 | 'mobile' => wp_is_mobile(), |
| 1917 | - 'ios' => wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ), |
|
| 1917 | + 'ios' => wp_is_mobile() && preg_match('/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT']), |
|
| 1918 | 1918 | ); |
| 1919 | 1919 | |
| 1920 | 1920 | $settings = array( |
| 1921 | - 'url' => esc_url( admin_url( 'customize.php' ) ), |
|
| 1921 | + 'url' => esc_url(admin_url('customize.php')), |
|
| 1922 | 1922 | 'isCrossDomain' => $cross_domain, |
| 1923 | 1923 | 'browser' => $browser, |
| 1924 | 1924 | 'l10n' => array( |
| 1925 | - 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), |
|
| 1926 | - 'mainIframeTitle' => __( 'Customizer' ), |
|
| 1925 | + 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), |
|
| 1926 | + 'mainIframeTitle' => __('Customizer'), |
|
| 1927 | 1927 | ), |
| 1928 | 1928 | ); |
| 1929 | 1929 | |
| 1930 | - $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';'; |
|
| 1930 | + $script = 'var _wpCustomizeLoaderSettings = '.wp_json_encode($settings).';'; |
|
| 1931 | 1931 | |
| 1932 | 1932 | $wp_scripts = wp_scripts(); |
| 1933 | - $data = $wp_scripts->get_data( 'customize-loader', 'data' ); |
|
| 1934 | - if ( $data ) |
|
| 1933 | + $data = $wp_scripts->get_data('customize-loader', 'data'); |
|
| 1934 | + if ($data) |
|
| 1935 | 1935 | $script = "$data\n$script"; |
| 1936 | 1936 | |
| 1937 | - $wp_scripts->add_data( 'customize-loader', 'data', $script ); |
|
| 1937 | + $wp_scripts->add_data('customize-loader', 'data', $script); |
|
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | /** |
@@ -1946,11 +1946,11 @@ discard block |
||
| 1946 | 1946 | * The theme's stylesheet will be urlencoded if necessary. |
| 1947 | 1947 | * @return string |
| 1948 | 1948 | */ |
| 1949 | -function wp_customize_url( $stylesheet = null ) { |
|
| 1950 | - $url = admin_url( 'customize.php' ); |
|
| 1951 | - if ( $stylesheet ) |
|
| 1952 | - $url .= '?theme=' . urlencode( $stylesheet ); |
|
| 1953 | - return esc_url( $url ); |
|
| 1949 | +function wp_customize_url($stylesheet = null) { |
|
| 1950 | + $url = admin_url('customize.php'); |
|
| 1951 | + if ($stylesheet) |
|
| 1952 | + $url .= '?theme='.urlencode($stylesheet); |
|
| 1953 | + return esc_url($url); |
|
| 1954 | 1954 | } |
| 1955 | 1955 | |
| 1956 | 1956 | /** |
@@ -1969,16 +1969,16 @@ discard block |
||
| 1969 | 1969 | * @since 3.4.0 |
| 1970 | 1970 | */ |
| 1971 | 1971 | function wp_customize_support_script() { |
| 1972 | - $admin_origin = parse_url( admin_url() ); |
|
| 1973 | - $home_origin = parse_url( home_url() ); |
|
| 1974 | - $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); |
|
| 1972 | + $admin_origin = parse_url(admin_url()); |
|
| 1973 | + $home_origin = parse_url(home_url()); |
|
| 1974 | + $cross_domain = (strtolower($admin_origin['host']) != strtolower($home_origin['host'])); |
|
| 1975 | 1975 | |
| 1976 | 1976 | ?> |
| 1977 | 1977 | <script type="text/javascript"> |
| 1978 | 1978 | (function() { |
| 1979 | 1979 | var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)'); |
| 1980 | 1980 | |
| 1981 | -<?php if ( $cross_domain ): ?> |
|
| 1981 | +<?php if ($cross_domain): ?> |
|
| 1982 | 1982 | request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); |
| 1983 | 1983 | <?php else: ?> |
| 1984 | 1984 | request = true; |
@@ -2003,5 +2003,5 @@ discard block |
||
| 2003 | 2003 | function is_customize_preview() { |
| 2004 | 2004 | global $wp_customize; |
| 2005 | 2005 | |
| 2006 | - return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview(); |
|
| 2006 | + return ($wp_customize instanceof WP_Customize_Manager) && $wp_customize->is_preview(); |
|
| 2007 | 2007 | } |
@@ -41,41 +41,46 @@ discard block |
||
| 41 | 41 | $current_theme = get_stylesheet(); |
| 42 | 42 | if ( isset( $theme_directories[ $current_theme ] ) ) { |
| 43 | 43 | $root_of_current_theme = get_raw_theme_root( $current_theme ); |
| 44 | - if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) |
|
| 45 | - $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; |
|
| 44 | + if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) { |
|
| 45 | + $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; |
|
| 46 | + } |
|
| 46 | 47 | $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; |
| 47 | 48 | } |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - if ( empty( $theme_directories ) ) |
|
| 51 | - return array(); |
|
| 51 | + if ( empty( $theme_directories ) ) { |
|
| 52 | + return array(); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | if ( is_multisite() && null !== $args['allowed'] ) { |
| 54 | 56 | $allowed = $args['allowed']; |
| 55 | - if ( 'network' === $allowed ) |
|
| 56 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); |
|
| 57 | - elseif ( 'site' === $allowed ) |
|
| 58 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); |
|
| 59 | - elseif ( $allowed ) |
|
| 60 | - $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 61 | - else |
|
| 62 | - $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 57 | + if ( 'network' === $allowed ) { |
|
| 58 | + $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); |
|
| 59 | + } elseif ( 'site' === $allowed ) { |
|
| 60 | + $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); |
|
| 61 | + } elseif ( $allowed ) { |
|
| 62 | + $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 63 | + } else { |
|
| 64 | + $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
| 65 | + } |
|
| 63 | 66 | } |
| 64 | 67 | |
| 65 | 68 | $themes = array(); |
| 66 | 69 | static $_themes = array(); |
| 67 | 70 | |
| 68 | 71 | foreach ( $theme_directories as $theme => $theme_root ) { |
| 69 | - if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) |
|
| 70 | - $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; |
|
| 71 | - else |
|
| 72 | - $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); |
|
| 72 | + if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) { |
|
| 73 | + $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; |
|
| 74 | + } else { |
|
| 75 | + $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); |
|
| 76 | + } |
|
| 73 | 77 | } |
| 74 | 78 | |
| 75 | 79 | if ( null !== $args['errors'] ) { |
| 76 | 80 | foreach ( $themes as $theme => $wp_theme ) { |
| 77 | - if ( $wp_theme->errors() != $args['errors'] ) |
|
| 78 | - unset( $themes[ $theme ] ); |
|
| 81 | + if ( $wp_theme->errors() != $args['errors'] ) { |
|
| 82 | + unset( $themes[ $theme ] ); |
|
| 83 | + } |
|
| 79 | 84 | } |
| 80 | 85 | } |
| 81 | 86 | |
@@ -97,15 +102,17 @@ discard block |
||
| 97 | 102 | function wp_get_theme( $stylesheet = null, $theme_root = null ) { |
| 98 | 103 | global $wp_theme_directories; |
| 99 | 104 | |
| 100 | - if ( empty( $stylesheet ) ) |
|
| 101 | - $stylesheet = get_stylesheet(); |
|
| 105 | + if ( empty( $stylesheet ) ) { |
|
| 106 | + $stylesheet = get_stylesheet(); |
|
| 107 | + } |
|
| 102 | 108 | |
| 103 | 109 | if ( empty( $theme_root ) ) { |
| 104 | 110 | $theme_root = get_raw_theme_root( $stylesheet ); |
| 105 | - if ( false === $theme_root ) |
|
| 106 | - $theme_root = WP_CONTENT_DIR . '/themes'; |
|
| 107 | - elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
| 108 | - $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 111 | + if ( false === $theme_root ) { |
|
| 112 | + $theme_root = WP_CONTENT_DIR . '/themes'; |
|
| 113 | + } elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { |
|
| 114 | + $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 115 | + } |
|
| 109 | 116 | } |
| 110 | 117 | |
| 111 | 118 | return new WP_Theme( $stylesheet, $theme_root ); |
@@ -118,12 +125,14 @@ discard block |
||
| 118 | 125 | * @param bool $clear_update_cache Whether to clear the Theme updates cache |
| 119 | 126 | */ |
| 120 | 127 | function wp_clean_themes_cache( $clear_update_cache = true ) { |
| 121 | - if ( $clear_update_cache ) |
|
| 122 | - delete_site_transient( 'update_themes' ); |
|
| 128 | + if ( $clear_update_cache ) { |
|
| 129 | + delete_site_transient( 'update_themes' ); |
|
| 130 | + } |
|
| 123 | 131 | search_theme_directories( true ); |
| 124 | - foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) |
|
| 125 | - $theme->cache_delete(); |
|
| 126 | -} |
|
| 132 | + foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) { |
|
| 133 | + $theme->cache_delete(); |
|
| 134 | + } |
|
| 135 | + } |
|
| 127 | 136 | |
| 128 | 137 | /** |
| 129 | 138 | * Whether a child theme is in use. |
@@ -257,12 +266,13 @@ discard block |
||
| 257 | 266 | $stylesheet_dir_uri = get_stylesheet_directory_uri(); |
| 258 | 267 | $dir = get_stylesheet_directory(); |
| 259 | 268 | $locale = get_locale(); |
| 260 | - if ( file_exists("$dir/$locale.css") ) |
|
| 261 | - $stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; |
|
| 262 | - elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") ) |
|
| 263 | - $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; |
|
| 264 | - else |
|
| 265 | - $stylesheet_uri = ''; |
|
| 269 | + if ( file_exists("$dir/$locale.css") ) { |
|
| 270 | + $stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; |
|
| 271 | + } elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") ) { |
|
| 272 | + $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; |
|
| 273 | + } else { |
|
| 274 | + $stylesheet_uri = ''; |
|
| 275 | + } |
|
| 266 | 276 | /** |
| 267 | 277 | * Filter the localized stylesheet URI. |
| 268 | 278 | * |
@@ -352,8 +362,9 @@ discard block |
||
| 352 | 362 | function get_theme_roots() { |
| 353 | 363 | global $wp_theme_directories; |
| 354 | 364 | |
| 355 | - if ( count($wp_theme_directories) <= 1 ) |
|
| 356 | - return '/themes'; |
|
| 365 | + if ( count($wp_theme_directories) <= 1 ) { |
|
| 366 | + return '/themes'; |
|
| 367 | + } |
|
| 357 | 368 | |
| 358 | 369 | $theme_roots = get_site_transient( 'theme_roots' ); |
| 359 | 370 | if ( false === $theme_roots ) { |
@@ -412,11 +423,13 @@ discard block |
||
| 412 | 423 | global $wp_theme_directories; |
| 413 | 424 | static $found_themes = null; |
| 414 | 425 | |
| 415 | - if ( empty( $wp_theme_directories ) ) |
|
| 416 | - return false; |
|
| 426 | + if ( empty( $wp_theme_directories ) ) { |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 417 | 429 | |
| 418 | - if ( ! $force && isset( $found_themes ) ) |
|
| 419 | - return $found_themes; |
|
| 430 | + if ( ! $force && isset( $found_themes ) ) { |
|
| 431 | + return $found_themes; |
|
| 432 | + } |
|
| 420 | 433 | |
| 421 | 434 | $found_themes = array(); |
| 422 | 435 | |
@@ -427,10 +440,11 @@ discard block |
||
| 427 | 440 | // We always want to return absolute, but we need to cache relative |
| 428 | 441 | // to use in get_theme_root(). |
| 429 | 442 | foreach ( $wp_theme_directories as $theme_root ) { |
| 430 | - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
| 431 | - $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; |
|
| 432 | - else |
|
| 433 | - $relative_theme_roots[ $theme_root ] = $theme_root; |
|
| 443 | + if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { |
|
| 444 | + $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; |
|
| 445 | + } else { |
|
| 446 | + $relative_theme_roots[ $theme_root ] = $theme_root; |
|
| 447 | + } |
|
| 434 | 448 | } |
| 435 | 449 | |
| 436 | 450 | /** |
@@ -446,8 +460,9 @@ discard block |
||
| 446 | 460 | if ( is_array( $cached_roots ) ) { |
| 447 | 461 | foreach ( $cached_roots as $theme_dir => $theme_root ) { |
| 448 | 462 | // A cached theme root is no longer around, so skip it. |
| 449 | - if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) |
|
| 450 | - continue; |
|
| 463 | + if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) { |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 451 | 466 | $found_themes[ $theme_dir ] = array( |
| 452 | 467 | 'theme_file' => $theme_dir . '/style.css', |
| 453 | 468 | 'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute. |
@@ -455,8 +470,10 @@ discard block |
||
| 455 | 470 | } |
| 456 | 471 | return $found_themes; |
| 457 | 472 | } |
| 458 | - if ( ! is_int( $cache_expiration ) ) |
|
| 459 | - $cache_expiration = 1800; // half hour |
|
| 473 | + if ( ! is_int( $cache_expiration ) ) { |
|
| 474 | + $cache_expiration = 1800; |
|
| 475 | + } |
|
| 476 | + // half hour |
|
| 460 | 477 | } else { |
| 461 | 478 | $cache_expiration = 1800; // half hour |
| 462 | 479 | } |
@@ -471,8 +488,9 @@ discard block |
||
| 471 | 488 | continue; |
| 472 | 489 | } |
| 473 | 490 | foreach ( $dirs as $dir ) { |
| 474 | - if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
| 475 | - continue; |
|
| 491 | + if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) { |
|
| 492 | + continue; |
|
| 493 | + } |
|
| 476 | 494 | if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { |
| 477 | 495 | // wp-content/themes/a-single-theme |
| 478 | 496 | // wp-content/themes is $theme_root, a-single-theme is $dir |
@@ -490,10 +508,12 @@ discard block |
||
| 490 | 508 | continue; |
| 491 | 509 | } |
| 492 | 510 | foreach ( $sub_dirs as $sub_dir ) { |
| 493 | - if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
| 494 | - continue; |
|
| 495 | - if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) |
|
| 496 | - continue; |
|
| 511 | + if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) { |
|
| 512 | + continue; |
|
| 513 | + } |
|
| 514 | + if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) { |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 497 | 517 | $found_themes[ $dir . '/' . $sub_dir ] = array( |
| 498 | 518 | 'theme_file' => $dir . '/' . $sub_dir . '/style.css', |
| 499 | 519 | 'theme_root' => $theme_root, |
@@ -502,11 +522,12 @@ discard block |
||
| 502 | 522 | } |
| 503 | 523 | // Never mind the above, it's just a theme missing a style.css. |
| 504 | 524 | // Return it; WP_Theme will catch the error. |
| 505 | - if ( ! $found_theme ) |
|
| 506 | - $found_themes[ $dir ] = array( |
|
| 525 | + if ( ! $found_theme ) { |
|
| 526 | + $found_themes[ $dir ] = array( |
|
| 507 | 527 | 'theme_file' => $dir . '/style.css', |
| 508 | 528 | 'theme_root' => $theme_root, |
| 509 | 529 | ); |
| 530 | + } |
|
| 510 | 531 | } |
| 511 | 532 | } |
| 512 | 533 | } |
@@ -520,8 +541,9 @@ discard block |
||
| 520 | 541 | $theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative. |
| 521 | 542 | } |
| 522 | 543 | |
| 523 | - if ( $theme_roots != get_site_transient( 'theme_roots' ) ) |
|
| 524 | - set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); |
|
| 544 | + if ( $theme_roots != get_site_transient( 'theme_roots' ) ) { |
|
| 545 | + set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); |
|
| 546 | + } |
|
| 525 | 547 | |
| 526 | 548 | return $found_themes; |
| 527 | 549 | } |
@@ -544,8 +566,9 @@ discard block |
||
| 544 | 566 | if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { |
| 545 | 567 | // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. |
| 546 | 568 | // This gives relative theme roots the benefit of the doubt when things go haywire. |
| 547 | - if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
| 548 | - $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 569 | + if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { |
|
| 570 | + $theme_root = WP_CONTENT_DIR . $theme_root; |
|
| 571 | + } |
|
| 549 | 572 | } else { |
| 550 | 573 | $theme_root = WP_CONTENT_DIR . '/themes'; |
| 551 | 574 | } |
@@ -578,20 +601,22 @@ discard block |
||
| 578 | 601 | function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { |
| 579 | 602 | global $wp_theme_directories; |
| 580 | 603 | |
| 581 | - if ( $stylesheet_or_template && ! $theme_root ) |
|
| 582 | - $theme_root = get_raw_theme_root( $stylesheet_or_template ); |
|
| 604 | + if ( $stylesheet_or_template && ! $theme_root ) { |
|
| 605 | + $theme_root = get_raw_theme_root( $stylesheet_or_template ); |
|
| 606 | + } |
|
| 583 | 607 | |
| 584 | 608 | if ( $stylesheet_or_template && $theme_root ) { |
| 585 | 609 | if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { |
| 586 | 610 | // Absolute path. Make an educated guess. YMMV -- but note the filter below. |
| 587 | - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
| 588 | - $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); |
|
| 589 | - elseif ( 0 === strpos( $theme_root, ABSPATH ) ) |
|
| 590 | - $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); |
|
| 591 | - elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) |
|
| 592 | - $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); |
|
| 593 | - else |
|
| 594 | - $theme_root_uri = $theme_root; |
|
| 611 | + if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { |
|
| 612 | + $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); |
|
| 613 | + } elseif ( 0 === strpos( $theme_root, ABSPATH ) ) { |
|
| 614 | + $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); |
|
| 615 | + } elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) { |
|
| 616 | + $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); |
|
| 617 | + } else { |
|
| 618 | + $theme_root_uri = $theme_root; |
|
| 619 | + } |
|
| 595 | 620 | } else { |
| 596 | 621 | $theme_root_uri = content_url( $theme_root ); |
| 597 | 622 | } |
@@ -626,23 +651,26 @@ discard block |
||
| 626 | 651 | function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) { |
| 627 | 652 | global $wp_theme_directories; |
| 628 | 653 | |
| 629 | - if ( count($wp_theme_directories) <= 1 ) |
|
| 630 | - return '/themes'; |
|
| 654 | + if ( count($wp_theme_directories) <= 1 ) { |
|
| 655 | + return '/themes'; |
|
| 656 | + } |
|
| 631 | 657 | |
| 632 | 658 | $theme_root = false; |
| 633 | 659 | |
| 634 | 660 | // If requesting the root for the current theme, consult options to avoid calling get_theme_roots() |
| 635 | 661 | if ( ! $skip_cache ) { |
| 636 | - if ( get_option('stylesheet') == $stylesheet_or_template ) |
|
| 637 | - $theme_root = get_option('stylesheet_root'); |
|
| 638 | - elseif ( get_option('template') == $stylesheet_or_template ) |
|
| 639 | - $theme_root = get_option('template_root'); |
|
| 662 | + if ( get_option('stylesheet') == $stylesheet_or_template ) { |
|
| 663 | + $theme_root = get_option('stylesheet_root'); |
|
| 664 | + } elseif ( get_option('template') == $stylesheet_or_template ) { |
|
| 665 | + $theme_root = get_option('template_root'); |
|
| 666 | + } |
|
| 640 | 667 | } |
| 641 | 668 | |
| 642 | 669 | if ( empty($theme_root) ) { |
| 643 | 670 | $theme_roots = get_theme_roots(); |
| 644 | - if ( !empty($theme_roots[$stylesheet_or_template]) ) |
|
| 645 | - $theme_root = $theme_roots[$stylesheet_or_template]; |
|
| 671 | + if ( !empty($theme_roots[$stylesheet_or_template]) ) { |
|
| 672 | + $theme_root = $theme_roots[$stylesheet_or_template]; |
|
| 673 | + } |
|
| 646 | 674 | } |
| 647 | 675 | |
| 648 | 676 | return $theme_root; |
@@ -655,8 +683,9 @@ discard block |
||
| 655 | 683 | */ |
| 656 | 684 | function locale_stylesheet() { |
| 657 | 685 | $stylesheet = get_locale_stylesheet_uri(); |
| 658 | - if ( empty($stylesheet) ) |
|
| 659 | - return; |
|
| 686 | + if ( empty($stylesheet) ) { |
|
| 687 | + return; |
|
| 688 | + } |
|
| 660 | 689 | echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; |
| 661 | 690 | } |
| 662 | 691 | |
@@ -761,8 +790,9 @@ discard block |
||
| 761 | 790 | * |
| 762 | 791 | * @param bool true Validation flag to check the current theme. |
| 763 | 792 | */ |
| 764 | - if ( defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) ) |
|
| 765 | - return true; |
|
| 793 | + if ( defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) ) { |
|
| 794 | + return true; |
|
| 795 | + } |
|
| 766 | 796 | |
| 767 | 797 | if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { |
| 768 | 798 | switch_theme( WP_DEFAULT_THEME ); |
@@ -794,8 +824,9 @@ discard block |
||
| 794 | 824 | $mods = get_option( "theme_mods_$theme_slug" ); |
| 795 | 825 | if ( false === $mods ) { |
| 796 | 826 | $theme_name = get_option( 'current_theme' ); |
| 797 | - if ( false === $theme_name ) |
|
| 798 | - $theme_name = wp_get_theme()->get('Name'); |
|
| 827 | + if ( false === $theme_name ) { |
|
| 828 | + $theme_name = wp_get_theme()->get('Name'); |
|
| 829 | + } |
|
| 799 | 830 | $mods = get_option( "mods_$theme_name" ); // Deprecated location. |
| 800 | 831 | if ( is_admin() && false !== $mods ) { |
| 801 | 832 | update_option( "theme_mods_$theme_slug", $mods ); |
@@ -838,8 +869,9 @@ discard block |
||
| 838 | 869 | return apply_filters( "theme_mod_{$name}", $mods[$name] ); |
| 839 | 870 | } |
| 840 | 871 | |
| 841 | - if ( is_string( $default ) ) |
|
| 842 | - $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 872 | + if ( is_string( $default ) ) { |
|
| 873 | + $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
| 874 | + } |
|
| 843 | 875 | |
| 844 | 876 | /** This filter is documented in wp-includes/theme.php */ |
| 845 | 877 | return apply_filters( "theme_mod_{$name}", $default ); |
@@ -888,8 +920,9 @@ discard block |
||
| 888 | 920 | function remove_theme_mod( $name ) { |
| 889 | 921 | $mods = get_theme_mods(); |
| 890 | 922 | |
| 891 | - if ( ! isset( $mods[ $name ] ) ) |
|
| 892 | - return; |
|
| 923 | + if ( ! isset( $mods[ $name ] ) ) { |
|
| 924 | + return; |
|
| 925 | + } |
|
| 893 | 926 | |
| 894 | 927 | unset( $mods[ $name ] ); |
| 895 | 928 | |
@@ -911,8 +944,9 @@ discard block |
||
| 911 | 944 | |
| 912 | 945 | // Old style. |
| 913 | 946 | $theme_name = get_option( 'current_theme' ); |
| 914 | - if ( false === $theme_name ) |
|
| 915 | - $theme_name = wp_get_theme()->get('Name'); |
|
| 947 | + if ( false === $theme_name ) { |
|
| 948 | + $theme_name = wp_get_theme()->get('Name'); |
|
| 949 | + } |
|
| 916 | 950 | delete_option( 'mods_' . $theme_name ); |
| 917 | 951 | } |
| 918 | 952 | |
@@ -944,8 +978,9 @@ discard block |
||
| 944 | 978 | * @return bool |
| 945 | 979 | */ |
| 946 | 980 | function display_header_text() { |
| 947 | - if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) |
|
| 948 | - return false; |
|
| 981 | + if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
| 982 | + return false; |
|
| 983 | + } |
|
| 949 | 984 | |
| 950 | 985 | $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
| 951 | 986 | return 'blank' !== $text_color; |
@@ -974,11 +1009,13 @@ discard block |
||
| 974 | 1009 | function get_header_image() { |
| 975 | 1010 | $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
| 976 | 1011 | |
| 977 | - if ( 'remove-header' == $url ) |
|
| 978 | - return false; |
|
| 1012 | + if ( 'remove-header' == $url ) { |
|
| 1013 | + return false; |
|
| 1014 | + } |
|
| 979 | 1015 | |
| 980 | - if ( is_random_header_image() ) |
|
| 981 | - $url = get_random_header_image(); |
|
| 1016 | + if ( is_random_header_image() ) { |
|
| 1017 | + $url = get_random_header_image(); |
|
| 1018 | + } |
|
| 982 | 1019 | |
| 983 | 1020 | return esc_url_raw( set_url_scheme( $url ) ); |
| 984 | 1021 | } |
@@ -1003,19 +1040,21 @@ discard block |
||
| 1003 | 1040 | $header_image_mod = get_theme_mod( 'header_image', '' ); |
| 1004 | 1041 | $headers = array(); |
| 1005 | 1042 | |
| 1006 | - if ( 'random-uploaded-image' == $header_image_mod ) |
|
| 1007 | - $headers = get_uploaded_header_images(); |
|
| 1008 | - elseif ( ! empty( $_wp_default_headers ) ) { |
|
| 1043 | + if ( 'random-uploaded-image' == $header_image_mod ) { |
|
| 1044 | + $headers = get_uploaded_header_images(); |
|
| 1045 | + } elseif ( ! empty( $_wp_default_headers ) ) { |
|
| 1009 | 1046 | if ( 'random-default-image' == $header_image_mod ) { |
| 1010 | 1047 | $headers = $_wp_default_headers; |
| 1011 | 1048 | } else { |
| 1012 | - if ( current_theme_supports( 'custom-header', 'random-default' ) ) |
|
| 1013 | - $headers = $_wp_default_headers; |
|
| 1049 | + if ( current_theme_supports( 'custom-header', 'random-default' ) ) { |
|
| 1050 | + $headers = $_wp_default_headers; |
|
| 1051 | + } |
|
| 1014 | 1052 | } |
| 1015 | 1053 | } |
| 1016 | 1054 | |
| 1017 | - if ( empty( $headers ) ) |
|
| 1018 | - return new stdClass; |
|
| 1055 | + if ( empty( $headers ) ) { |
|
| 1056 | + return new stdClass; |
|
| 1057 | + } |
|
| 1019 | 1058 | |
| 1020 | 1059 | $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; |
| 1021 | 1060 | |
@@ -1034,8 +1073,9 @@ discard block |
||
| 1034 | 1073 | */ |
| 1035 | 1074 | function get_random_header_image() { |
| 1036 | 1075 | $random_image = _get_random_header_data(); |
| 1037 | - if ( empty( $random_image->url ) ) |
|
| 1038 | - return ''; |
|
| 1076 | + if ( empty( $random_image->url ) ) { |
|
| 1077 | + return ''; |
|
| 1078 | + } |
|
| 1039 | 1079 | return $random_image->url; |
| 1040 | 1080 | } |
| 1041 | 1081 | |
@@ -1055,13 +1095,15 @@ discard block |
||
| 1055 | 1095 | $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
| 1056 | 1096 | |
| 1057 | 1097 | if ( 'any' == $type ) { |
| 1058 | - if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) |
|
| 1059 | - return true; |
|
| 1098 | + if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) { |
|
| 1099 | + return true; |
|
| 1100 | + } |
|
| 1060 | 1101 | } else { |
| 1061 | - if ( "random-$type-image" == $header_image_mod ) |
|
| 1062 | - return true; |
|
| 1063 | - elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) |
|
| 1064 | - return true; |
|
| 1102 | + if ( "random-$type-image" == $header_image_mod ) { |
|
| 1103 | + return true; |
|
| 1104 | + } elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) { |
|
| 1105 | + return true; |
|
| 1106 | + } |
|
| 1065 | 1107 | } |
| 1066 | 1108 | |
| 1067 | 1109 | return false; |
@@ -1092,8 +1134,9 @@ discard block |
||
| 1092 | 1134 | // @todo caching |
| 1093 | 1135 | $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); |
| 1094 | 1136 | |
| 1095 | - if ( empty( $headers ) ) |
|
| 1096 | - return array(); |
|
| 1137 | + if ( empty( $headers ) ) { |
|
| 1138 | + return array(); |
|
| 1139 | + } |
|
| 1097 | 1140 | |
| 1098 | 1141 | foreach ( (array) $headers as $header ) { |
| 1099 | 1142 | $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); |
@@ -1106,10 +1149,12 @@ discard block |
||
| 1106 | 1149 | $header_images[$header_index]['thumbnail_url'] = $url; |
| 1107 | 1150 | $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); |
| 1108 | 1151 | |
| 1109 | - if ( isset( $header_data['width'] ) ) |
|
| 1110 | - $header_images[$header_index]['width'] = $header_data['width']; |
|
| 1111 | - if ( isset( $header_data['height'] ) ) |
|
| 1112 | - $header_images[$header_index]['height'] = $header_data['height']; |
|
| 1152 | + if ( isset( $header_data['width'] ) ) { |
|
| 1153 | + $header_images[$header_index]['width'] = $header_data['width']; |
|
| 1154 | + } |
|
| 1155 | + if ( isset( $header_data['height'] ) ) { |
|
| 1156 | + $header_images[$header_index]['height'] = $header_data['height']; |
|
| 1157 | + } |
|
| 1113 | 1158 | } |
| 1114 | 1159 | |
| 1115 | 1160 | return $header_images; |
@@ -1258,8 +1303,9 @@ discard block |
||
| 1258 | 1303 | $color = false; |
| 1259 | 1304 | } |
| 1260 | 1305 | |
| 1261 | - if ( ! $background && ! $color ) |
|
| 1262 | - return; |
|
| 1306 | + if ( ! $background && ! $color ) { |
|
| 1307 | + return; |
|
| 1308 | + } |
|
| 1263 | 1309 | |
| 1264 | 1310 | $style = $color ? "background-color: #$color;" : ''; |
| 1265 | 1311 | |
@@ -1267,18 +1313,21 @@ discard block |
||
| 1267 | 1313 | $image = " background-image: url('$background');"; |
| 1268 | 1314 | |
| 1269 | 1315 | $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
| 1270 | - if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) |
|
| 1271 | - $repeat = 'repeat'; |
|
| 1316 | + if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) { |
|
| 1317 | + $repeat = 'repeat'; |
|
| 1318 | + } |
|
| 1272 | 1319 | $repeat = " background-repeat: $repeat;"; |
| 1273 | 1320 | |
| 1274 | 1321 | $position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
| 1275 | - if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) |
|
| 1276 | - $position = 'left'; |
|
| 1322 | + if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) { |
|
| 1323 | + $position = 'left'; |
|
| 1324 | + } |
|
| 1277 | 1325 | $position = " background-position: top $position;"; |
| 1278 | 1326 | |
| 1279 | 1327 | $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
| 1280 | - if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) |
|
| 1281 | - $attachment = 'scroll'; |
|
| 1328 | + if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) { |
|
| 1329 | + $attachment = 'scroll'; |
|
| 1330 | + } |
|
| 1282 | 1331 | $attachment = " background-attachment: $attachment;"; |
| 1283 | 1332 | |
| 1284 | 1333 | $style .= $image . $repeat . $position . $attachment; |
@@ -1315,8 +1364,9 @@ discard block |
||
| 1315 | 1364 | function add_editor_style( $stylesheet = 'editor-style.css' ) { |
| 1316 | 1365 | add_theme_support( 'editor-style' ); |
| 1317 | 1366 | |
| 1318 | - if ( ! is_admin() ) |
|
| 1319 | - return; |
|
| 1367 | + if ( ! is_admin() ) { |
|
| 1368 | + return; |
|
| 1369 | + } |
|
| 1320 | 1370 | |
| 1321 | 1371 | global $editor_styles; |
| 1322 | 1372 | $editor_styles = (array) $editor_styles; |
@@ -1339,11 +1389,13 @@ discard block |
||
| 1339 | 1389 | * @return bool True on success, false if there were no stylesheets to remove. |
| 1340 | 1390 | */ |
| 1341 | 1391 | function remove_editor_styles() { |
| 1342 | - if ( ! current_theme_supports( 'editor-style' ) ) |
|
| 1343 | - return false; |
|
| 1392 | + if ( ! current_theme_supports( 'editor-style' ) ) { |
|
| 1393 | + return false; |
|
| 1394 | + } |
|
| 1344 | 1395 | _remove_theme_support( 'editor-style' ); |
| 1345 | - if ( is_admin() ) |
|
| 1346 | - $GLOBALS['editor_styles'] = array(); |
|
| 1396 | + if ( is_admin() ) { |
|
| 1397 | + $GLOBALS['editor_styles'] = array(); |
|
| 1398 | + } |
|
| 1347 | 1399 | return true; |
| 1348 | 1400 | } |
| 1349 | 1401 | |
@@ -1420,10 +1472,11 @@ discard block |
||
| 1420 | 1472 | function add_theme_support( $feature ) { |
| 1421 | 1473 | global $_wp_theme_features; |
| 1422 | 1474 | |
| 1423 | - if ( func_num_args() == 1 ) |
|
| 1424 | - $args = true; |
|
| 1425 | - else |
|
| 1426 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1475 | + if ( func_num_args() == 1 ) { |
|
| 1476 | + $args = true; |
|
| 1477 | + } else { |
|
| 1478 | + $args = array_slice( func_get_args(), 1 ); |
|
| 1479 | + } |
|
| 1427 | 1480 | |
| 1428 | 1481 | switch ( $feature ) { |
| 1429 | 1482 | case 'post-formats' : |
@@ -1446,16 +1499,18 @@ discard block |
||
| 1446 | 1499 | } |
| 1447 | 1500 | |
| 1448 | 1501 | // Calling 'html5' again merges, rather than overwrites. |
| 1449 | - if ( isset( $_wp_theme_features['html5'] ) ) |
|
| 1450 | - $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); |
|
| 1502 | + if ( isset( $_wp_theme_features['html5'] ) ) { |
|
| 1503 | + $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); |
|
| 1504 | + } |
|
| 1451 | 1505 | break; |
| 1452 | 1506 | |
| 1453 | 1507 | case 'custom-header-uploads' : |
| 1454 | 1508 | return add_theme_support( 'custom-header', array( 'uploads' => true ) ); |
| 1455 | 1509 | |
| 1456 | 1510 | case 'custom-header' : |
| 1457 | - if ( ! is_array( $args ) ) |
|
| 1458 | - $args = array( 0 => array() ); |
|
| 1511 | + if ( ! is_array( $args ) ) { |
|
| 1512 | + $args = array( 0 => array() ); |
|
| 1513 | + } |
|
| 1459 | 1514 | |
| 1460 | 1515 | $defaults = array( |
| 1461 | 1516 | 'default-image' => '', |
@@ -1477,13 +1532,15 @@ discard block |
||
| 1477 | 1532 | |
| 1478 | 1533 | // Merge in data from previous add_theme_support() calls. |
| 1479 | 1534 | // The first value registered wins. (A child theme is set up first.) |
| 1480 | - if ( isset( $_wp_theme_features['custom-header'] ) ) |
|
| 1481 | - $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); |
|
| 1535 | + if ( isset( $_wp_theme_features['custom-header'] ) ) { |
|
| 1536 | + $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); |
|
| 1537 | + } |
|
| 1482 | 1538 | |
| 1483 | 1539 | // Load in the defaults at the end, as we need to insure first one wins. |
| 1484 | 1540 | // This will cause all constants to be defined, as each arg will then be set to the default. |
| 1485 | - if ( $jit ) |
|
| 1486 | - $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1541 | + if ( $jit ) { |
|
| 1542 | + $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1543 | + } |
|
| 1487 | 1544 | |
| 1488 | 1545 | // If a constant was defined, use that value. Otherwise, define the constant to ensure |
| 1489 | 1546 | // the constant is always accurate (and is not defined later, overriding our value). |
@@ -1491,48 +1548,57 @@ discard block |
||
| 1491 | 1548 | // Once we get to wp_loaded (just-in-time), define any constants we haven't already. |
| 1492 | 1549 | // Constants are lame. Don't reference them. This is just for backwards compatibility. |
| 1493 | 1550 | |
| 1494 | - if ( defined( 'NO_HEADER_TEXT' ) ) |
|
| 1495 | - $args[0]['header-text'] = ! NO_HEADER_TEXT; |
|
| 1496 | - elseif ( isset( $args[0]['header-text'] ) ) |
|
| 1497 | - define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); |
|
| 1551 | + if ( defined( 'NO_HEADER_TEXT' ) ) { |
|
| 1552 | + $args[0]['header-text'] = ! NO_HEADER_TEXT; |
|
| 1553 | + } elseif ( isset( $args[0]['header-text'] ) ) { |
|
| 1554 | + define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); |
|
| 1555 | + } |
|
| 1498 | 1556 | |
| 1499 | - if ( defined( 'HEADER_IMAGE_WIDTH' ) ) |
|
| 1500 | - $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; |
|
| 1501 | - elseif ( isset( $args[0]['width'] ) ) |
|
| 1502 | - define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); |
|
| 1557 | + if ( defined( 'HEADER_IMAGE_WIDTH' ) ) { |
|
| 1558 | + $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; |
|
| 1559 | + } elseif ( isset( $args[0]['width'] ) ) { |
|
| 1560 | + define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); |
|
| 1561 | + } |
|
| 1503 | 1562 | |
| 1504 | - if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) |
|
| 1505 | - $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; |
|
| 1506 | - elseif ( isset( $args[0]['height'] ) ) |
|
| 1507 | - define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); |
|
| 1563 | + if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) { |
|
| 1564 | + $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; |
|
| 1565 | + } elseif ( isset( $args[0]['height'] ) ) { |
|
| 1566 | + define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); |
|
| 1567 | + } |
|
| 1508 | 1568 | |
| 1509 | - if ( defined( 'HEADER_TEXTCOLOR' ) ) |
|
| 1510 | - $args[0]['default-text-color'] = HEADER_TEXTCOLOR; |
|
| 1511 | - elseif ( isset( $args[0]['default-text-color'] ) ) |
|
| 1512 | - define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); |
|
| 1569 | + if ( defined( 'HEADER_TEXTCOLOR' ) ) { |
|
| 1570 | + $args[0]['default-text-color'] = HEADER_TEXTCOLOR; |
|
| 1571 | + } elseif ( isset( $args[0]['default-text-color'] ) ) { |
|
| 1572 | + define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); |
|
| 1573 | + } |
|
| 1513 | 1574 | |
| 1514 | - if ( defined( 'HEADER_IMAGE' ) ) |
|
| 1515 | - $args[0]['default-image'] = HEADER_IMAGE; |
|
| 1516 | - elseif ( isset( $args[0]['default-image'] ) ) |
|
| 1517 | - define( 'HEADER_IMAGE', $args[0]['default-image'] ); |
|
| 1575 | + if ( defined( 'HEADER_IMAGE' ) ) { |
|
| 1576 | + $args[0]['default-image'] = HEADER_IMAGE; |
|
| 1577 | + } elseif ( isset( $args[0]['default-image'] ) ) { |
|
| 1578 | + define( 'HEADER_IMAGE', $args[0]['default-image'] ); |
|
| 1579 | + } |
|
| 1518 | 1580 | |
| 1519 | - if ( $jit && ! empty( $args[0]['default-image'] ) ) |
|
| 1520 | - $args[0]['random-default'] = false; |
|
| 1581 | + if ( $jit && ! empty( $args[0]['default-image'] ) ) { |
|
| 1582 | + $args[0]['random-default'] = false; |
|
| 1583 | + } |
|
| 1521 | 1584 | |
| 1522 | 1585 | // If headers are supported, and we still don't have a defined width or height, |
| 1523 | 1586 | // we have implicit flex sizes. |
| 1524 | 1587 | if ( $jit ) { |
| 1525 | - if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) |
|
| 1526 | - $args[0]['flex-width'] = true; |
|
| 1527 | - if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) |
|
| 1528 | - $args[0]['flex-height'] = true; |
|
| 1588 | + if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) { |
|
| 1589 | + $args[0]['flex-width'] = true; |
|
| 1590 | + } |
|
| 1591 | + if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) { |
|
| 1592 | + $args[0]['flex-height'] = true; |
|
| 1593 | + } |
|
| 1529 | 1594 | } |
| 1530 | 1595 | |
| 1531 | 1596 | break; |
| 1532 | 1597 | |
| 1533 | 1598 | case 'custom-background' : |
| 1534 | - if ( ! is_array( $args ) ) |
|
| 1535 | - $args = array( 0 => array() ); |
|
| 1599 | + if ( ! is_array( $args ) ) { |
|
| 1600 | + $args = array( 0 => array() ); |
|
| 1601 | + } |
|
| 1536 | 1602 | |
| 1537 | 1603 | $defaults = array( |
| 1538 | 1604 | 'default-image' => '', |
@@ -1549,21 +1615,25 @@ discard block |
||
| 1549 | 1615 | unset( $args[0]['__jit'] ); |
| 1550 | 1616 | |
| 1551 | 1617 | // Merge in data from previous add_theme_support() calls. The first value registered wins. |
| 1552 | - if ( isset( $_wp_theme_features['custom-background'] ) ) |
|
| 1553 | - $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); |
|
| 1618 | + if ( isset( $_wp_theme_features['custom-background'] ) ) { |
|
| 1619 | + $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); |
|
| 1620 | + } |
|
| 1554 | 1621 | |
| 1555 | - if ( $jit ) |
|
| 1556 | - $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1622 | + if ( $jit ) { |
|
| 1623 | + $args[0] = wp_parse_args( $args[0], $defaults ); |
|
| 1624 | + } |
|
| 1557 | 1625 | |
| 1558 | - if ( defined( 'BACKGROUND_COLOR' ) ) |
|
| 1559 | - $args[0]['default-color'] = BACKGROUND_COLOR; |
|
| 1560 | - elseif ( isset( $args[0]['default-color'] ) || $jit ) |
|
| 1561 | - define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); |
|
| 1626 | + if ( defined( 'BACKGROUND_COLOR' ) ) { |
|
| 1627 | + $args[0]['default-color'] = BACKGROUND_COLOR; |
|
| 1628 | + } elseif ( isset( $args[0]['default-color'] ) || $jit ) { |
|
| 1629 | + define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); |
|
| 1630 | + } |
|
| 1562 | 1631 | |
| 1563 | - if ( defined( 'BACKGROUND_IMAGE' ) ) |
|
| 1564 | - $args[0]['default-image'] = BACKGROUND_IMAGE; |
|
| 1565 | - elseif ( isset( $args[0]['default-image'] ) || $jit ) |
|
| 1566 | - define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); |
|
| 1632 | + if ( defined( 'BACKGROUND_IMAGE' ) ) { |
|
| 1633 | + $args[0]['default-image'] = BACKGROUND_IMAGE; |
|
| 1634 | + } elseif ( isset( $args[0]['default-image'] ) || $jit ) { |
|
| 1635 | + define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); |
|
| 1636 | + } |
|
| 1567 | 1637 | |
| 1568 | 1638 | break; |
| 1569 | 1639 | |
@@ -1599,8 +1669,9 @@ discard block |
||
| 1599 | 1669 | add_theme_support( 'custom-header', array( '__jit' => true ) ); |
| 1600 | 1670 | |
| 1601 | 1671 | $args = get_theme_support( 'custom-header' ); |
| 1602 | - if ( $args[0]['wp-head-callback'] ) |
|
| 1603 | - add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
| 1672 | + if ( $args[0]['wp-head-callback'] ) { |
|
| 1673 | + add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
| 1674 | + } |
|
| 1604 | 1675 | |
| 1605 | 1676 | if ( is_admin() ) { |
| 1606 | 1677 | require_once( ABSPATH . 'wp-admin/custom-header.php' ); |
@@ -1634,18 +1705,21 @@ discard block |
||
| 1634 | 1705 | */ |
| 1635 | 1706 | function get_theme_support( $feature ) { |
| 1636 | 1707 | global $_wp_theme_features; |
| 1637 | - if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
| 1638 | - return false; |
|
| 1708 | + if ( ! isset( $_wp_theme_features[ $feature ] ) ) { |
|
| 1709 | + return false; |
|
| 1710 | + } |
|
| 1639 | 1711 | |
| 1640 | - if ( func_num_args() <= 1 ) |
|
| 1641 | - return $_wp_theme_features[ $feature ]; |
|
| 1712 | + if ( func_num_args() <= 1 ) { |
|
| 1713 | + return $_wp_theme_features[ $feature ]; |
|
| 1714 | + } |
|
| 1642 | 1715 | |
| 1643 | 1716 | $args = array_slice( func_get_args(), 1 ); |
| 1644 | 1717 | switch ( $feature ) { |
| 1645 | 1718 | case 'custom-header' : |
| 1646 | 1719 | case 'custom-background' : |
| 1647 | - if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) |
|
| 1648 | - return $_wp_theme_features[ $feature ][0][ $args[0] ]; |
|
| 1720 | + if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) { |
|
| 1721 | + return $_wp_theme_features[ $feature ][0][ $args[0] ]; |
|
| 1722 | + } |
|
| 1649 | 1723 | return false; |
| 1650 | 1724 | |
| 1651 | 1725 | default : |
@@ -1666,8 +1740,9 @@ discard block |
||
| 1666 | 1740 | */ |
| 1667 | 1741 | function remove_theme_support( $feature ) { |
| 1668 | 1742 | // Blacklist: for internal registrations not used directly by themes. |
| 1669 | - if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) |
|
| 1670 | - return false; |
|
| 1743 | + if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) { |
|
| 1744 | + return false; |
|
| 1745 | + } |
|
| 1671 | 1746 | |
| 1672 | 1747 | return _remove_theme_support( $feature ); |
| 1673 | 1748 | } |
@@ -1689,29 +1764,34 @@ discard block |
||
| 1689 | 1764 | |
| 1690 | 1765 | switch ( $feature ) { |
| 1691 | 1766 | case 'custom-header-uploads' : |
| 1692 | - if ( ! isset( $_wp_theme_features['custom-header'] ) ) |
|
| 1693 | - return false; |
|
| 1767 | + if ( ! isset( $_wp_theme_features['custom-header'] ) ) { |
|
| 1768 | + return false; |
|
| 1769 | + } |
|
| 1694 | 1770 | add_theme_support( 'custom-header', array( 'uploads' => false ) ); |
| 1695 | 1771 | return; // Do not continue - custom-header-uploads no longer exists. |
| 1696 | 1772 | } |
| 1697 | 1773 | |
| 1698 | - if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
| 1699 | - return false; |
|
| 1774 | + if ( ! isset( $_wp_theme_features[ $feature ] ) ) { |
|
| 1775 | + return false; |
|
| 1776 | + } |
|
| 1700 | 1777 | |
| 1701 | 1778 | switch ( $feature ) { |
| 1702 | 1779 | case 'custom-header' : |
| 1703 | - if ( ! did_action( 'wp_loaded' ) ) |
|
| 1704 | - break; |
|
| 1780 | + if ( ! did_action( 'wp_loaded' ) ) { |
|
| 1781 | + break; |
|
| 1782 | + } |
|
| 1705 | 1783 | $support = get_theme_support( 'custom-header' ); |
| 1706 | - if ( $support[0]['wp-head-callback'] ) |
|
| 1707 | - remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
| 1784 | + if ( $support[0]['wp-head-callback'] ) { |
|
| 1785 | + remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
| 1786 | + } |
|
| 1708 | 1787 | remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) ); |
| 1709 | 1788 | unset( $GLOBALS['custom_image_header'] ); |
| 1710 | 1789 | break; |
| 1711 | 1790 | |
| 1712 | 1791 | case 'custom-background' : |
| 1713 | - if ( ! did_action( 'wp_loaded' ) ) |
|
| 1714 | - break; |
|
| 1792 | + if ( ! did_action( 'wp_loaded' ) ) { |
|
| 1793 | + break; |
|
| 1794 | + } |
|
| 1715 | 1795 | $support = get_theme_support( 'custom-background' ); |
| 1716 | 1796 | remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
| 1717 | 1797 | remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); |
@@ -1736,11 +1816,13 @@ discard block |
||
| 1736 | 1816 | function current_theme_supports( $feature ) { |
| 1737 | 1817 | global $_wp_theme_features; |
| 1738 | 1818 | |
| 1739 | - if ( 'custom-header-uploads' == $feature ) |
|
| 1740 | - return current_theme_supports( 'custom-header', 'uploads' ); |
|
| 1819 | + if ( 'custom-header-uploads' == $feature ) { |
|
| 1820 | + return current_theme_supports( 'custom-header', 'uploads' ); |
|
| 1821 | + } |
|
| 1741 | 1822 | |
| 1742 | - if ( !isset( $_wp_theme_features[$feature] ) ) |
|
| 1743 | - return false; |
|
| 1823 | + if ( !isset( $_wp_theme_features[$feature] ) ) { |
|
| 1824 | + return false; |
|
| 1825 | + } |
|
| 1744 | 1826 | |
| 1745 | 1827 | if ( 'title-tag' == $feature ) { |
| 1746 | 1828 | // Don't confirm support unless called internally. |
@@ -1751,8 +1833,9 @@ discard block |
||
| 1751 | 1833 | } |
| 1752 | 1834 | |
| 1753 | 1835 | // If no args passed then no extra checks need be performed |
| 1754 | - if ( func_num_args() <= 1 ) |
|
| 1755 | - return true; |
|
| 1836 | + if ( func_num_args() <= 1 ) { |
|
| 1837 | + return true; |
|
| 1838 | + } |
|
| 1756 | 1839 | |
| 1757 | 1840 | $args = array_slice( func_get_args(), 1 ); |
| 1758 | 1841 | |
@@ -1761,8 +1844,10 @@ discard block |
||
| 1761 | 1844 | // post-thumbnails can be registered for only certain content/post types by passing |
| 1762 | 1845 | // an array of types to add_theme_support(). If no array was passed, then |
| 1763 | 1846 | // any type is accepted |
| 1764 | - if ( true === $_wp_theme_features[$feature] ) // Registered for all types |
|
| 1847 | + if ( true === $_wp_theme_features[$feature] ) { |
|
| 1848 | + // Registered for all types |
|
| 1765 | 1849 | return true; |
| 1850 | + } |
|
| 1766 | 1851 | $content_type = $args[0]; |
| 1767 | 1852 | return in_array( $content_type, $_wp_theme_features[$feature][0] ); |
| 1768 | 1853 | |
@@ -1895,8 +1980,9 @@ discard block |
||
| 1895 | 1980 | function _wp_customize_include() { |
| 1896 | 1981 | if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) |
| 1897 | 1982 | || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) |
| 1898 | - ) ) |
|
| 1899 | - return; |
|
| 1983 | + ) ) { |
|
| 1984 | + return; |
|
| 1985 | + } |
|
| 1900 | 1986 | |
| 1901 | 1987 | require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
| 1902 | 1988 | $GLOBALS['wp_customize'] = new WP_Customize_Manager(); |
@@ -1931,8 +2017,9 @@ discard block |
||
| 1931 | 2017 | |
| 1932 | 2018 | $wp_scripts = wp_scripts(); |
| 1933 | 2019 | $data = $wp_scripts->get_data( 'customize-loader', 'data' ); |
| 1934 | - if ( $data ) |
|
| 1935 | - $script = "$data\n$script"; |
|
| 2020 | + if ( $data ) { |
|
| 2021 | + $script = "$data\n$script"; |
|
| 2022 | + } |
|
| 1936 | 2023 | |
| 1937 | 2024 | $wp_scripts->add_data( 'customize-loader', 'data', $script ); |
| 1938 | 2025 | } |
@@ -1948,8 +2035,9 @@ discard block |
||
| 1948 | 2035 | */ |
| 1949 | 2036 | function wp_customize_url( $stylesheet = null ) { |
| 1950 | 2037 | $url = admin_url( 'customize.php' ); |
| 1951 | - if ( $stylesheet ) |
|
| 1952 | - $url .= '?theme=' . urlencode( $stylesheet ); |
|
| 2038 | + if ( $stylesheet ) { |
|
| 2039 | + $url .= '?theme=' . urlencode( $stylesheet ); |
|
| 2040 | + } |
|
| 1953 | 2041 | return esc_url( $url ); |
| 1954 | 2042 | } |
| 1955 | 2043 | |
@@ -1980,9 +2068,12 @@ discard block |
||
| 1980 | 2068 | |
| 1981 | 2069 | <?php if ( $cross_domain ): ?> |
| 1982 | 2070 | request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); |
| 1983 | -<?php else: ?> |
|
| 2071 | +<?php else { |
|
| 2072 | + : ?> |
|
| 1984 | 2073 | request = true; |
| 1985 | -<?php endif; ?> |
|
| 2074 | +<?php endif; |
|
| 2075 | +} |
|
| 2076 | +?> |
|
| 1986 | 2077 | |
| 1987 | 2078 | b[c] = b[c].replace( rcs, ' ' ); |
| 1988 | 2079 | b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; |
@@ -507,7 +507,6 @@ discard block |
||
| 507 | 507 | * |
| 508 | 508 | * @since 3.1.0 |
| 509 | 509 | * |
| 510 | - * @param null|string|array $args Optional. The query variables. |
|
| 511 | 510 | */ |
| 512 | 511 | public function __construct( $query = null ) { |
| 513 | 512 | if ( ! empty( $query ) ) { |
@@ -1095,7 +1094,7 @@ discard block |
||
| 1095 | 1094 | * @access public |
| 1096 | 1095 | * |
| 1097 | 1096 | * @param string $name Property to check if set. |
| 1098 | - * @return bool Whether the property is set. |
|
| 1097 | + * @return boolean|null Whether the property is set. |
|
| 1099 | 1098 | */ |
| 1100 | 1099 | public function __isset( $name ) { |
| 1101 | 1100 | if ( in_array( $name, $this->compat_fields ) ) { |
@@ -1293,7 +1292,7 @@ discard block |
||
| 1293 | 1292 | * |
| 1294 | 1293 | * @param int $user_id User ID. |
| 1295 | 1294 | * @param string $meta_key Metadata name. |
| 1296 | - * @param mixed $meta_value Metadata value. |
|
| 1295 | + * @param string $meta_value Metadata value. |
|
| 1297 | 1296 | * @param bool $unique Optional, default is false. Whether the same key should not be added. |
| 1298 | 1297 | * @return int|false Meta ID on success, false on failure. |
| 1299 | 1298 | */ |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param bool $secure_cookie Whether to use a secure sign-on cookie. |
| 67 | 67 | * @param array $credentials { |
| 68 | - * Array of entered sign-on data. |
|
| 69 | - * |
|
| 70 | - * @type string $user_login Username. |
|
| 71 | - * @type string $user_password Password entered. |
|
| 68 | + * Array of entered sign-on data. |
|
| 69 | + * |
|
| 70 | + * @type string $user_login Username. |
|
| 71 | + * @type string $user_password Password entered. |
|
| 72 | 72 | * @type bool $remember Whether to 'remember' the user. Increases the time |
| 73 | 73 | * that the cookie will be kept. Default false. |
| 74 | - * } |
|
| 74 | + * } |
|
| 75 | 75 | */ |
| 76 | 76 | $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
| 77 | 77 | |
@@ -1675,7 +1675,7 @@ discard block |
||
| 1675 | 1675 | * |
| 1676 | 1676 | * The dynamic portion of the hook name, `$field`, refers to the prefixed user |
| 1677 | 1677 | * field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
| 1678 | - * |
|
| 1678 | + * |
|
| 1679 | 1679 | * @since 2.9.0 |
| 1680 | 1680 | * |
| 1681 | 1681 | * @param mixed $value Value of the prefixed user field. |
@@ -2390,7 +2390,7 @@ discard block |
||
| 2390 | 2390 | * @since 2.9.0 |
| 2391 | 2391 | * |
| 2392 | 2392 | * @param array $methods Array of contact methods and their labels. |
| 2393 | - * @param WP_User $user WP_User object. |
|
| 2393 | + * @param WP_User $user WP_User object. |
|
| 2394 | 2394 | */ |
| 2395 | 2395 | return apply_filters( 'user_contactmethods', $methods, $user ); |
| 2396 | 2396 | } |
@@ -25,17 +25,17 @@ discard block |
||
| 25 | 25 | * @param string|bool $secure_cookie Optional. Whether to use secure cookie. |
| 26 | 26 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 27 | 27 | */ |
| 28 | -function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
|
| 29 | - if ( empty($credentials) ) { |
|
| 30 | - if ( ! empty($_POST['log']) ) |
|
| 28 | +function wp_signon($credentials = array(), $secure_cookie = '') { |
|
| 29 | + if (empty($credentials)) { |
|
| 30 | + if ( ! empty($_POST['log'])) |
|
| 31 | 31 | $credentials['user_login'] = $_POST['log']; |
| 32 | - if ( ! empty($_POST['pwd']) ) |
|
| 32 | + if ( ! empty($_POST['pwd'])) |
|
| 33 | 33 | $credentials['user_password'] = $_POST['pwd']; |
| 34 | - if ( ! empty($_POST['rememberme']) ) |
|
| 34 | + if ( ! empty($_POST['rememberme'])) |
|
| 35 | 35 | $credentials['remember'] = $_POST['rememberme']; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if ( !empty($credentials['remember']) ) |
|
| 38 | + if ( ! empty($credentials['remember'])) |
|
| 39 | 39 | $credentials['remember'] = true; |
| 40 | 40 | else |
| 41 | 41 | $credentials['remember'] = false; |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | * @param string $user_login Username, passed by reference. |
| 54 | 54 | * @param string $user_password User password, passed by reference. |
| 55 | 55 | */ |
| 56 | - do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
|
| 56 | + do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password'])); |
|
| 57 | 57 | |
| 58 | - if ( '' === $secure_cookie ) |
|
| 58 | + if ('' === $secure_cookie) |
|
| 59 | 59 | $secure_cookie = is_ssl(); |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * that the cookie will be kept. Default false. |
| 74 | 74 | * } |
| 75 | 75 | */ |
| 76 | - $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
|
| 76 | + $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials); |
|
| 77 | 77 | |
| 78 | 78 | global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie |
| 79 | 79 | $auth_secure_cookie = $secure_cookie; |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $user = wp_authenticate($credentials['user_login'], $credentials['user_password']); |
| 84 | 84 | |
| 85 | - if ( is_wp_error($user) ) { |
|
| 86 | - if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) { |
|
| 85 | + if (is_wp_error($user)) { |
|
| 86 | + if ($user->get_error_codes() == array('empty_username', 'empty_password')) { |
|
| 87 | 87 | $user = new WP_Error('', ''); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param string $user_login Username. |
| 100 | 100 | * @param WP_User $user WP_User object of the logged-in user. |
| 101 | 101 | */ |
| 102 | - do_action( 'wp_login', $user->user_login, $user ); |
|
| 102 | + do_action('wp_login', $user->user_login, $user); |
|
| 103 | 103 | return $user; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 115 | 115 | */ |
| 116 | 116 | function wp_authenticate_username_password($user, $username, $password) { |
| 117 | - if ( $user instanceof WP_User ) { |
|
| 117 | + if ($user instanceof WP_User) { |
|
| 118 | 118 | return $user; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( empty($username) || empty($password) ) { |
|
| 122 | - if ( is_wp_error( $user ) ) |
|
| 121 | + if (empty($username) || empty($password)) { |
|
| 122 | + if (is_wp_error($user)) |
|
| 123 | 123 | return $user; |
| 124 | 124 | |
| 125 | 125 | $error = new WP_Error(); |
| 126 | 126 | |
| 127 | - if ( empty($username) ) |
|
| 127 | + if (empty($username)) |
|
| 128 | 128 | $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
| 129 | 129 | |
| 130 | - if ( empty($password) ) |
|
| 130 | + if (empty($password)) |
|
| 131 | 131 | $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
| 132 | 132 | |
| 133 | 133 | return $error; |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $user = get_user_by('login', $username); |
| 137 | 137 | |
| 138 | - if ( !$user ) |
|
| 139 | - return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>' ), wp_lostpassword_url() ) ); |
|
| 138 | + if ( ! $user) |
|
| 139 | + return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>'), wp_lostpassword_url())); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * Filter whether the given user can be authenticated with the provided $password. |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | * callback failed authentication. |
| 148 | 148 | * @param string $password Password to check against the user. |
| 149 | 149 | */ |
| 150 | - $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
| 151 | - if ( is_wp_error($user) ) |
|
| 150 | + $user = apply_filters('wp_authenticate_user', $user, $password); |
|
| 151 | + if (is_wp_error($user)) |
|
| 152 | 152 | return $user; |
| 153 | 153 | |
| 154 | - if ( !wp_check_password($password, $user->user_pass, $user->ID) ) |
|
| 155 | - return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>' ), |
|
| 156 | - $username, wp_lostpassword_url() ) ); |
|
| 154 | + if ( ! wp_check_password($password, $user->user_pass, $user->ID)) |
|
| 155 | + return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>'), |
|
| 156 | + $username, wp_lostpassword_url())); |
|
| 157 | 157 | |
| 158 | 158 | return $user; |
| 159 | 159 | } |
@@ -171,23 +171,23 @@ discard block |
||
| 171 | 171 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 172 | 172 | */ |
| 173 | 173 | function wp_authenticate_cookie($user, $username, $password) { |
| 174 | - if ( $user instanceof WP_User ) { |
|
| 174 | + if ($user instanceof WP_User) { |
|
| 175 | 175 | return $user; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( empty($username) && empty($password) ) { |
|
| 178 | + if (empty($username) && empty($password)) { |
|
| 179 | 179 | $user_id = wp_validate_auth_cookie(); |
| 180 | - if ( $user_id ) |
|
| 180 | + if ($user_id) |
|
| 181 | 181 | return new WP_User($user_id); |
| 182 | 182 | |
| 183 | 183 | global $auth_secure_cookie; |
| 184 | 184 | |
| 185 | - if ( $auth_secure_cookie ) |
|
| 185 | + if ($auth_secure_cookie) |
|
| 186 | 186 | $auth_cookie = SECURE_AUTH_COOKIE; |
| 187 | 187 | else |
| 188 | 188 | $auth_cookie = AUTH_COOKIE; |
| 189 | 189 | |
| 190 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
| 190 | + if ( ! empty($_COOKIE[$auth_cookie])) |
|
| 191 | 191 | return new WP_Error('expired_session', __('Please log in again.')); |
| 192 | 192 | |
| 193 | 193 | // If the cookie is not set, be silent. |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | * @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
| 206 | 206 | * @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer. |
| 207 | 207 | */ |
| 208 | -function wp_authenticate_spam_check( $user ) { |
|
| 209 | - if ( $user instanceof WP_User && is_multisite() ) { |
|
| 208 | +function wp_authenticate_spam_check($user) { |
|
| 209 | + if ($user instanceof WP_User && is_multisite()) { |
|
| 210 | 210 | /** |
| 211 | 211 | * Filter whether the user has been marked as a spammer. |
| 212 | 212 | * |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | * @param bool $spammed Whether the user is considered a spammer. |
| 216 | 216 | * @param WP_User $user User to check against. |
| 217 | 217 | */ |
| 218 | - $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
|
| 218 | + $spammed = apply_filters('check_is_user_spammed', is_user_spammy(), $user); |
|
| 219 | 219 | |
| 220 | - if ( $spammed ) |
|
| 221 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 220 | + if ($spammed) |
|
| 221 | + return new WP_Error('spammer_account', __('<strong>ERROR</strong>: Your account has been marked as a spammer.')); |
|
| 222 | 222 | } |
| 223 | 223 | return $user; |
| 224 | 224 | } |
@@ -238,16 +238,16 @@ discard block |
||
| 238 | 238 | * @return int|false User ID if validated, false otherwise. If a user ID from |
| 239 | 239 | * an earlier filter callback is received, that value is returned. |
| 240 | 240 | */ |
| 241 | -function wp_validate_logged_in_cookie( $user_id ) { |
|
| 242 | - if ( $user_id ) { |
|
| 241 | +function wp_validate_logged_in_cookie($user_id) { |
|
| 242 | + if ($user_id) { |
|
| 243 | 243 | return $user_id; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) { |
|
| 246 | + if (is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE])) { |
|
| 247 | 247 | return false; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ); |
|
| 250 | + return wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in'); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | * @param bool $public_only Optional. Whether to only return counts for public posts. Default false. |
| 266 | 266 | * @return int Number of posts the user has written in this post type. |
| 267 | 267 | */ |
| 268 | -function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { |
|
| 268 | +function count_user_posts($userid, $post_type = 'post', $public_only = false) { |
|
| 269 | 269 | global $wpdb; |
| 270 | 270 | |
| 271 | - $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); |
|
| 271 | + $where = get_posts_by_author_sql($post_type, true, $userid, $public_only); |
|
| 272 | 272 | |
| 273 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
|
| 273 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts $where"); |
|
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | 276 | * Filter the number of posts a user has written. |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @param string|array $post_types Post types to count the number of posts for. |
| 285 | 285 | * @param bool $public_only Whether to limit counted posts to public posts. |
| 286 | 286 | */ |
| 287 | - return apply_filters( 'get_usernumposts', $count, $userid, $post_type ); |
|
| 287 | + return apply_filters('get_usernumposts', $count, $userid, $post_type); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -299,24 +299,24 @@ discard block |
||
| 299 | 299 | * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
| 300 | 300 | * @return array Amount of posts each user has written. |
| 301 | 301 | */ |
| 302 | -function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
|
| 302 | +function count_many_users_posts($users, $post_type = 'post', $public_only = false) { |
|
| 303 | 303 | global $wpdb; |
| 304 | 304 | |
| 305 | 305 | $count = array(); |
| 306 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
| 306 | + if (empty($users) || ! is_array($users)) |
|
| 307 | 307 | return $count; |
| 308 | 308 | |
| 309 | - $userlist = implode( ',', array_map( 'absint', $users ) ); |
|
| 310 | - $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
|
| 309 | + $userlist = implode(',', array_map('absint', $users)); |
|
| 310 | + $where = get_posts_by_author_sql($post_type, true, null, $public_only); |
|
| 311 | 311 | |
| 312 | - $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
|
| 313 | - foreach ( $result as $row ) { |
|
| 314 | - $count[ $row[0] ] = $row[1]; |
|
| 312 | + $result = $wpdb->get_results("SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N); |
|
| 313 | + foreach ($result as $row) { |
|
| 314 | + $count[$row[0]] = $row[1]; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - foreach ( $users as $id ) { |
|
| 318 | - if ( ! isset( $count[ $id ] ) ) |
|
| 319 | - $count[ $id ] = 0; |
|
| 317 | + foreach ($users as $id) { |
|
| 318 | + if ( ! isset($count[$id])) |
|
| 319 | + $count[$id] = 0; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return $count; |
@@ -334,10 +334,10 @@ discard block |
||
| 334 | 334 | * @return int The current user's ID |
| 335 | 335 | */ |
| 336 | 336 | function get_current_user_id() { |
| 337 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
| 337 | + if ( ! function_exists('wp_get_current_user')) |
|
| 338 | 338 | return 0; |
| 339 | 339 | $user = wp_get_current_user(); |
| 340 | - return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
|
| 340 | + return (isset($user->ID) ? (int) $user->ID : 0); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -359,23 +359,23 @@ discard block |
||
| 359 | 359 | * @param string $deprecated Use get_option() to check for an option in the options table. |
| 360 | 360 | * @return mixed User option value on success, false on failure. |
| 361 | 361 | */ |
| 362 | -function get_user_option( $option, $user = 0, $deprecated = '' ) { |
|
| 362 | +function get_user_option($option, $user = 0, $deprecated = '') { |
|
| 363 | 363 | global $wpdb; |
| 364 | 364 | |
| 365 | - if ( !empty( $deprecated ) ) |
|
| 366 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 365 | + if ( ! empty($deprecated)) |
|
| 366 | + _deprecated_argument(__FUNCTION__, '3.0'); |
|
| 367 | 367 | |
| 368 | - if ( empty( $user ) ) |
|
| 368 | + if (empty($user)) |
|
| 369 | 369 | $user = get_current_user_id(); |
| 370 | 370 | |
| 371 | - if ( ! $user = get_userdata( $user ) ) |
|
| 371 | + if ( ! $user = get_userdata($user)) |
|
| 372 | 372 | return false; |
| 373 | 373 | |
| 374 | 374 | $prefix = $wpdb->get_blog_prefix(); |
| 375 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
| 376 | - $result = $user->get( $prefix . $option ); |
|
| 377 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
| 378 | - $result = $user->get( $option ); |
|
| 375 | + if ($user->has_prop($prefix.$option)) // Blog specific |
|
| 376 | + $result = $user->get($prefix.$option); |
|
| 377 | + elseif ($user->has_prop($option)) // User specific and cross-blog |
|
| 378 | + $result = $user->get($option); |
|
| 379 | 379 | else |
| 380 | 380 | $result = false; |
| 381 | 381 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @param string $option Name of the option being retrieved. |
| 391 | 391 | * @param WP_User $user WP_User object of the user whose option is being retrieved. |
| 392 | 392 | */ |
| 393 | - return apply_filters( "get_user_option_{$option}", $result, $option, $user ); |
|
| 393 | + return apply_filters("get_user_option_{$option}", $result, $option, $user); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | * @return int|bool User meta ID if the option didn't exist, true on successful update, |
| 415 | 415 | * false on failure. |
| 416 | 416 | */ |
| 417 | -function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
|
| 417 | +function update_user_option($user_id, $option_name, $newvalue, $global = false) { |
|
| 418 | 418 | global $wpdb; |
| 419 | 419 | |
| 420 | - if ( !$global ) |
|
| 421 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 420 | + if ( ! $global) |
|
| 421 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
| 422 | 422 | |
| 423 | - return update_user_meta( $user_id, $option_name, $newvalue ); |
|
| 423 | + return update_user_meta($user_id, $option_name, $newvalue); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | * Default false (blog specific). |
| 441 | 441 | * @return bool True on success, false on failure. |
| 442 | 442 | */ |
| 443 | -function delete_user_option( $user_id, $option_name, $global = false ) { |
|
| 443 | +function delete_user_option($user_id, $option_name, $global = false) { |
|
| 444 | 444 | global $wpdb; |
| 445 | 445 | |
| 446 | - if ( !$global ) |
|
| 447 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 448 | - return delete_user_meta( $user_id, $option_name ); |
|
| 446 | + if ( ! $global) |
|
| 447 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
| 448 | + return delete_user_meta($user_id, $option_name); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | */ |
| 494 | 494 | public $meta_query = false; |
| 495 | 495 | |
| 496 | - private $compat_fields = array( 'results', 'total_users' ); |
|
| 496 | + private $compat_fields = array('results', 'total_users'); |
|
| 497 | 497 | |
| 498 | 498 | // SQL clauses |
| 499 | 499 | public $query_fields; |
@@ -509,9 +509,9 @@ discard block |
||
| 509 | 509 | * |
| 510 | 510 | * @param null|string|array $args Optional. The query variables. |
| 511 | 511 | */ |
| 512 | - public function __construct( $query = null ) { |
|
| 513 | - if ( ! empty( $query ) ) { |
|
| 514 | - $this->prepare_query( $query ); |
|
| 512 | + public function __construct($query = null) { |
|
| 513 | + if ( ! empty($query)) { |
|
| 514 | + $this->prepare_query($query); |
|
| 515 | 515 | $this->query(); |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -578,12 +578,12 @@ discard block |
||
| 578 | 578 | * public post types. |
| 579 | 579 | * } |
| 580 | 580 | */ |
| 581 | - public function prepare_query( $query = array() ) { |
|
| 581 | + public function prepare_query($query = array()) { |
|
| 582 | 582 | global $wpdb; |
| 583 | 583 | |
| 584 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
| 584 | + if (empty($this->query_vars) || ! empty($query)) { |
|
| 585 | 585 | $this->query_limit = null; |
| 586 | - $this->query_vars = wp_parse_args( $query, array( |
|
| 586 | + $this->query_vars = wp_parse_args($query, array( |
|
| 587 | 587 | 'blog_id' => $GLOBALS['blog_id'], |
| 588 | 588 | 'role' => '', |
| 589 | 589 | 'meta_key' => '', |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | 'fields' => 'all', |
| 602 | 602 | 'who' => '', |
| 603 | 603 | 'has_published_posts' => null, |
| 604 | - ) ); |
|
| 604 | + )); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -615,127 +615,127 @@ discard block |
||
| 615 | 615 | * @param WP_User_Query $this The current WP_User_Query instance, |
| 616 | 616 | * passed by reference. |
| 617 | 617 | */ |
| 618 | - do_action( 'pre_get_users', $this ); |
|
| 618 | + do_action('pre_get_users', $this); |
|
| 619 | 619 | |
| 620 | - $qv =& $this->query_vars; |
|
| 620 | + $qv = & $this->query_vars; |
|
| 621 | 621 | |
| 622 | - if ( is_array( $qv['fields'] ) ) { |
|
| 623 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
| 622 | + if (is_array($qv['fields'])) { |
|
| 623 | + $qv['fields'] = array_unique($qv['fields']); |
|
| 624 | 624 | |
| 625 | 625 | $this->query_fields = array(); |
| 626 | - foreach ( $qv['fields'] as $field ) { |
|
| 627 | - $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); |
|
| 626 | + foreach ($qv['fields'] as $field) { |
|
| 627 | + $field = 'ID' === $field ? 'ID' : sanitize_key($field); |
|
| 628 | 628 | $this->query_fields[] = "$wpdb->users.$field"; |
| 629 | 629 | } |
| 630 | - $this->query_fields = implode( ',', $this->query_fields ); |
|
| 631 | - } elseif ( 'all' == $qv['fields'] ) { |
|
| 630 | + $this->query_fields = implode(',', $this->query_fields); |
|
| 631 | + } elseif ('all' == $qv['fields']) { |
|
| 632 | 632 | $this->query_fields = "$wpdb->users.*"; |
| 633 | 633 | } else { |
| 634 | 634 | $this->query_fields = "$wpdb->users.ID"; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
| 638 | - $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
| 637 | + if (isset($qv['count_total']) && $qv['count_total']) |
|
| 638 | + $this->query_fields = 'SQL_CALC_FOUND_ROWS '.$this->query_fields; |
|
| 639 | 639 | |
| 640 | 640 | $this->query_from = "FROM $wpdb->users"; |
| 641 | 641 | $this->query_where = "WHERE 1=1"; |
| 642 | 642 | |
| 643 | 643 | // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below. |
| 644 | - if ( ! empty( $qv['include'] ) ) { |
|
| 645 | - $include = wp_parse_id_list( $qv['include'] ); |
|
| 644 | + if ( ! empty($qv['include'])) { |
|
| 645 | + $include = wp_parse_id_list($qv['include']); |
|
| 646 | 646 | } else { |
| 647 | 647 | $include = false; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | $blog_id = 0; |
| 651 | - if ( isset( $qv['blog_id'] ) ) { |
|
| 652 | - $blog_id = absint( $qv['blog_id'] ); |
|
| 651 | + if (isset($qv['blog_id'])) { |
|
| 652 | + $blog_id = absint($qv['blog_id']); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { |
|
| 656 | - $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; |
|
| 655 | + if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) { |
|
| 656 | + $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id).'user_level'; |
|
| 657 | 657 | $qv['meta_value'] = 0; |
| 658 | 658 | $qv['meta_compare'] = '!='; |
| 659 | 659 | $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - if ( $qv['has_published_posts'] && $blog_id ) { |
|
| 663 | - if ( true === $qv['has_published_posts'] ) { |
|
| 664 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 662 | + if ($qv['has_published_posts'] && $blog_id) { |
|
| 663 | + if (true === $qv['has_published_posts']) { |
|
| 664 | + $post_types = get_post_types(array('public' => true)); |
|
| 665 | 665 | } else { |
| 666 | 666 | $post_types = (array) $qv['has_published_posts']; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - foreach ( $post_types as &$post_type ) { |
|
| 670 | - $post_type = $wpdb->prepare( '%s', $post_type ); |
|
| 669 | + foreach ($post_types as &$post_type) { |
|
| 670 | + $post_type = $wpdb->prepare('%s', $post_type); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts'; |
|
| 674 | - $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )"; |
|
| 673 | + $posts_table = $wpdb->get_blog_prefix($blog_id).'posts'; |
|
| 674 | + $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( ".join(", ", $post_types)." ) )"; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | // Meta query. |
| 678 | 678 | $this->meta_query = new WP_Meta_Query(); |
| 679 | - $this->meta_query->parse_query_vars( $qv ); |
|
| 679 | + $this->meta_query->parse_query_vars($qv); |
|
| 680 | 680 | |
| 681 | 681 | $role = ''; |
| 682 | - if ( isset( $qv['role'] ) ) { |
|
| 683 | - $role = trim( $qv['role'] ); |
|
| 682 | + if (isset($qv['role'])) { |
|
| 683 | + $role = trim($qv['role']); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - if ( $blog_id && ( $role || is_multisite() ) ) { |
|
| 686 | + if ($blog_id && ($role || is_multisite())) { |
|
| 687 | 687 | $cap_meta_query = array(); |
| 688 | - $cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
| 688 | + $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id).'capabilities'; |
|
| 689 | 689 | |
| 690 | - if ( $role ) { |
|
| 691 | - $cap_meta_query['value'] = '"' . $role . '"'; |
|
| 690 | + if ($role) { |
|
| 691 | + $cap_meta_query['value'] = '"'.$role.'"'; |
|
| 692 | 692 | $cap_meta_query['compare'] = 'like'; |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - if ( empty( $this->meta_query->queries ) ) { |
|
| 696 | - $this->meta_query->queries = array( $cap_meta_query ); |
|
| 697 | - } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) { |
|
| 695 | + if (empty($this->meta_query->queries)) { |
|
| 696 | + $this->meta_query->queries = array($cap_meta_query); |
|
| 697 | + } elseif ( ! in_array($cap_meta_query, $this->meta_query->queries, true)) { |
|
| 698 | 698 | // Append the cap query to the original queries and reparse the query. |
| 699 | 699 | $this->meta_query->queries = array( |
| 700 | 700 | 'relation' => 'AND', |
| 701 | - array( $this->meta_query->queries, $cap_meta_query ), |
|
| 701 | + array($this->meta_query->queries, $cap_meta_query), |
|
| 702 | 702 | ); |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - $this->meta_query->parse_query_vars( $this->meta_query->queries ); |
|
| 705 | + $this->meta_query->parse_query_vars($this->meta_query->queries); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | - if ( ! empty( $this->meta_query->queries ) ) { |
|
| 709 | - $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); |
|
| 708 | + if ( ! empty($this->meta_query->queries)) { |
|
| 709 | + $clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this); |
|
| 710 | 710 | $this->query_from .= $clauses['join']; |
| 711 | 711 | $this->query_where .= $clauses['where']; |
| 712 | 712 | |
| 713 | - if ( $this->meta_query->has_or_relation() ) { |
|
| 714 | - $this->query_fields = 'DISTINCT ' . $this->query_fields; |
|
| 713 | + if ($this->meta_query->has_or_relation()) { |
|
| 714 | + $this->query_fields = 'DISTINCT '.$this->query_fields; |
|
| 715 | 715 | } |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | // sorting |
| 719 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
| 720 | - $order = $this->parse_order( $qv['order'] ); |
|
| 719 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
| 720 | + $order = $this->parse_order($qv['order']); |
|
| 721 | 721 | |
| 722 | - if ( empty( $qv['orderby'] ) ) { |
|
| 722 | + if (empty($qv['orderby'])) { |
|
| 723 | 723 | // Default order is by 'user_login'. |
| 724 | - $ordersby = array( 'user_login' => $order ); |
|
| 725 | - } elseif ( is_array( $qv['orderby'] ) ) { |
|
| 724 | + $ordersby = array('user_login' => $order); |
|
| 725 | + } elseif (is_array($qv['orderby'])) { |
|
| 726 | 726 | $ordersby = $qv['orderby']; |
| 727 | 727 | } else { |
| 728 | 728 | // 'orderby' values may be a comma- or space-separated list. |
| 729 | - $ordersby = preg_split( '/[,\s]+/', $qv['orderby'] ); |
|
| 729 | + $ordersby = preg_split('/[,\s]+/', $qv['orderby']); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | $orderby_array = array(); |
| 733 | - foreach ( $ordersby as $_key => $_value ) { |
|
| 734 | - if ( ! $_value ) { |
|
| 733 | + foreach ($ordersby as $_key => $_value) { |
|
| 734 | + if ( ! $_value) { |
|
| 735 | 735 | continue; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - if ( is_int( $_key ) ) { |
|
| 738 | + if (is_int($_key)) { |
|
| 739 | 739 | // Integer key means this is a flat array of 'orderby' fields. |
| 740 | 740 | $_orderby = $_value; |
| 741 | 741 | $_order = $order; |
@@ -745,57 +745,57 @@ discard block |
||
| 745 | 745 | $_order = $_value; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $parsed = $this->parse_orderby( $_orderby ); |
|
| 748 | + $parsed = $this->parse_orderby($_orderby); |
|
| 749 | 749 | |
| 750 | - if ( ! $parsed ) { |
|
| 750 | + if ( ! $parsed) { |
|
| 751 | 751 | continue; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
| 754 | + $orderby_array[] = $parsed.' '.$this->parse_order($_order); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // If no valid clauses were found, order by user_login. |
| 758 | - if ( empty( $orderby_array ) ) { |
|
| 758 | + if (empty($orderby_array)) { |
|
| 759 | 759 | $orderby_array[] = "user_login $order"; |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
| 762 | + $this->query_orderby = 'ORDER BY '.implode(', ', $orderby_array); |
|
| 763 | 763 | |
| 764 | 764 | // limit |
| 765 | - if ( isset( $qv['number'] ) && $qv['number'] ) { |
|
| 766 | - if ( $qv['offset'] ) |
|
| 765 | + if (isset($qv['number']) && $qv['number']) { |
|
| 766 | + if ($qv['offset']) |
|
| 767 | 767 | $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); |
| 768 | 768 | else |
| 769 | 769 | $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']); |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | $search = ''; |
| 773 | - if ( isset( $qv['search'] ) ) |
|
| 774 | - $search = trim( $qv['search'] ); |
|
| 773 | + if (isset($qv['search'])) |
|
| 774 | + $search = trim($qv['search']); |
|
| 775 | 775 | |
| 776 | - if ( $search ) { |
|
| 777 | - $leading_wild = ( ltrim($search, '*') != $search ); |
|
| 778 | - $trailing_wild = ( rtrim($search, '*') != $search ); |
|
| 779 | - if ( $leading_wild && $trailing_wild ) |
|
| 776 | + if ($search) { |
|
| 777 | + $leading_wild = (ltrim($search, '*') != $search); |
|
| 778 | + $trailing_wild = (rtrim($search, '*') != $search); |
|
| 779 | + if ($leading_wild && $trailing_wild) |
|
| 780 | 780 | $wild = 'both'; |
| 781 | - elseif ( $leading_wild ) |
|
| 781 | + elseif ($leading_wild) |
|
| 782 | 782 | $wild = 'leading'; |
| 783 | - elseif ( $trailing_wild ) |
|
| 783 | + elseif ($trailing_wild) |
|
| 784 | 784 | $wild = 'trailing'; |
| 785 | 785 | else |
| 786 | 786 | $wild = false; |
| 787 | - if ( $wild ) |
|
| 787 | + if ($wild) |
|
| 788 | 788 | $search = trim($search, '*'); |
| 789 | 789 | |
| 790 | 790 | $search_columns = array(); |
| 791 | - if ( $qv['search_columns'] ) |
|
| 792 | - $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
| 793 | - if ( ! $search_columns ) { |
|
| 794 | - if ( false !== strpos( $search, '@') ) |
|
| 791 | + if ($qv['search_columns']) |
|
| 792 | + $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename')); |
|
| 793 | + if ( ! $search_columns) { |
|
| 794 | + if (false !== strpos($search, '@')) |
|
| 795 | 795 | $search_columns = array('user_email'); |
| 796 | - elseif ( is_numeric($search) ) |
|
| 796 | + elseif (is_numeric($search)) |
|
| 797 | 797 | $search_columns = array('user_login', 'ID'); |
| 798 | - elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) |
|
| 798 | + elseif (preg_match('|^https?://|', $search) && ! (is_multisite() && wp_is_large_network('users'))) |
|
| 799 | 799 | $search_columns = array('user_url'); |
| 800 | 800 | else |
| 801 | 801 | $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
@@ -813,23 +813,23 @@ discard block |
||
| 813 | 813 | * @param string $search Text being searched. |
| 814 | 814 | * @param WP_User_Query $this The current WP_User_Query instance. |
| 815 | 815 | */ |
| 816 | - $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this ); |
|
| 816 | + $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this); |
|
| 817 | 817 | |
| 818 | - $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); |
|
| 818 | + $this->query_where .= $this->get_search_sql($search, $search_columns, $wild); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | - if ( ! empty( $include ) ) { |
|
| 821 | + if ( ! empty($include)) { |
|
| 822 | 822 | // Sanitized earlier. |
| 823 | - $ids = implode( ',', $include ); |
|
| 823 | + $ids = implode(',', $include); |
|
| 824 | 824 | $this->query_where .= " AND $wpdb->users.ID IN ($ids)"; |
| 825 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
| 826 | - $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
| 825 | + } elseif ( ! empty($qv['exclude'])) { |
|
| 826 | + $ids = implode(',', wp_parse_id_list($qv['exclude'])); |
|
| 827 | 827 | $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)"; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | // Date queries are allowed for the user_registered field. |
| 831 | - if ( ! empty( $qv['date_query'] ) && is_array( $qv['date_query'] ) ) { |
|
| 832 | - $date_query = new WP_Date_Query( $qv['date_query'], 'user_registered' ); |
|
| 831 | + if ( ! empty($qv['date_query']) && is_array($qv['date_query'])) { |
|
| 832 | + $date_query = new WP_Date_Query($qv['date_query'], 'user_registered'); |
|
| 833 | 833 | $this->query_where .= $date_query->get_sql(); |
| 834 | 834 | } |
| 835 | 835 | |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * @param WP_User_Query $this The current WP_User_Query instance, |
| 846 | 846 | * passed by reference. |
| 847 | 847 | */ |
| 848 | - do_action_ref_array( 'pre_user_query', array( &$this ) ); |
|
| 848 | + do_action_ref_array('pre_user_query', array(&$this)); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -858,14 +858,14 @@ discard block |
||
| 858 | 858 | public function query() { |
| 859 | 859 | global $wpdb; |
| 860 | 860 | |
| 861 | - $qv =& $this->query_vars; |
|
| 861 | + $qv = & $this->query_vars; |
|
| 862 | 862 | |
| 863 | 863 | $query = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
| 864 | 864 | |
| 865 | - if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { |
|
| 866 | - $this->results = $wpdb->get_results( $query ); |
|
| 865 | + if (is_array($qv['fields']) || 'all' == $qv['fields']) { |
|
| 866 | + $this->results = $wpdb->get_results($query); |
|
| 867 | 867 | } else { |
| 868 | - $this->results = $wpdb->get_col( $query ); |
|
| 868 | + $this->results = $wpdb->get_col($query); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -877,23 +877,23 @@ discard block |
||
| 877 | 877 | * |
| 878 | 878 | * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. |
| 879 | 879 | */ |
| 880 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
| 881 | - $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
| 880 | + if (isset($qv['count_total']) && $qv['count_total']) |
|
| 881 | + $this->total_users = $wpdb->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); |
|
| 882 | 882 | |
| 883 | - if ( !$this->results ) |
|
| 883 | + if ( ! $this->results) |
|
| 884 | 884 | return; |
| 885 | 885 | |
| 886 | - if ( 'all_with_meta' == $qv['fields'] ) { |
|
| 887 | - cache_users( $this->results ); |
|
| 886 | + if ('all_with_meta' == $qv['fields']) { |
|
| 887 | + cache_users($this->results); |
|
| 888 | 888 | |
| 889 | 889 | $r = array(); |
| 890 | - foreach ( $this->results as $userid ) |
|
| 891 | - $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
| 890 | + foreach ($this->results as $userid) |
|
| 891 | + $r[$userid] = new WP_User($userid, '', $qv['blog_id']); |
|
| 892 | 892 | |
| 893 | 893 | $this->results = $r; |
| 894 | - } elseif ( 'all' == $qv['fields'] ) { |
|
| 895 | - foreach ( $this->results as $key => $user ) { |
|
| 896 | - $this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] ); |
|
| 894 | + } elseif ('all' == $qv['fields']) { |
|
| 895 | + foreach ($this->results as $key => $user) { |
|
| 896 | + $this->results[$key] = new WP_User($user, '', $qv['blog_id']); |
|
| 897 | 897 | } |
| 898 | 898 | } |
| 899 | 899 | } |
@@ -907,8 +907,8 @@ discard block |
||
| 907 | 907 | * @param string $query_var Query variable key. |
| 908 | 908 | * @return mixed |
| 909 | 909 | */ |
| 910 | - public function get( $query_var ) { |
|
| 911 | - if ( isset( $this->query_vars[$query_var] ) ) |
|
| 910 | + public function get($query_var) { |
|
| 911 | + if (isset($this->query_vars[$query_var])) |
|
| 912 | 912 | return $this->query_vars[$query_var]; |
| 913 | 913 | |
| 914 | 914 | return null; |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | * @param string $query_var Query variable key. |
| 924 | 924 | * @param mixed $value Query variable value. |
| 925 | 925 | */ |
| 926 | - public function set( $query_var, $value ) { |
|
| 926 | + public function set($query_var, $value) { |
|
| 927 | 927 | $this->query_vars[$query_var] = $value; |
| 928 | 928 | } |
| 929 | 929 | |
@@ -941,23 +941,23 @@ discard block |
||
| 941 | 941 | * Single site allows leading and trailing wildcards, Network Admin only trailing. |
| 942 | 942 | * @return string |
| 943 | 943 | */ |
| 944 | - protected function get_search_sql( $string, $cols, $wild = false ) { |
|
| 944 | + protected function get_search_sql($string, $cols, $wild = false) { |
|
| 945 | 945 | global $wpdb; |
| 946 | 946 | |
| 947 | 947 | $searches = array(); |
| 948 | - $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; |
|
| 949 | - $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; |
|
| 950 | - $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; |
|
| 948 | + $leading_wild = ('leading' == $wild || 'both' == $wild) ? '%' : ''; |
|
| 949 | + $trailing_wild = ('trailing' == $wild || 'both' == $wild) ? '%' : ''; |
|
| 950 | + $like = $leading_wild.$wpdb->esc_like($string).$trailing_wild; |
|
| 951 | 951 | |
| 952 | - foreach ( $cols as $col ) { |
|
| 953 | - if ( 'ID' == $col ) { |
|
| 954 | - $searches[] = $wpdb->prepare( "$col = %s", $string ); |
|
| 952 | + foreach ($cols as $col) { |
|
| 953 | + if ('ID' == $col) { |
|
| 954 | + $searches[] = $wpdb->prepare("$col = %s", $string); |
|
| 955 | 955 | } else { |
| 956 | - $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); |
|
| 956 | + $searches[] = $wpdb->prepare("$col LIKE %s", $like); |
|
| 957 | 957 | } |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - return ' AND (' . implode(' OR ', $searches) . ')'; |
|
| 960 | + return ' AND ('.implode(' OR ', $searches).')'; |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
@@ -995,21 +995,21 @@ discard block |
||
| 995 | 995 | * @param string $orderby Alias for the field to order by. |
| 996 | 996 | * @return string Value to used in the ORDER clause, if `$orderby` is valid. |
| 997 | 997 | */ |
| 998 | - protected function parse_orderby( $orderby ) { |
|
| 998 | + protected function parse_orderby($orderby) { |
|
| 999 | 999 | global $wpdb; |
| 1000 | 1000 | |
| 1001 | 1001 | $meta_query_clauses = $this->meta_query->get_clauses(); |
| 1002 | 1002 | |
| 1003 | 1003 | $_orderby = ''; |
| 1004 | - if ( in_array( $orderby, array( 'login', 'nicename', 'email', 'url', 'registered' ) ) ) { |
|
| 1005 | - $_orderby = 'user_' . $orderby; |
|
| 1006 | - } elseif ( in_array( $orderby, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered' ) ) ) { |
|
| 1004 | + if (in_array($orderby, array('login', 'nicename', 'email', 'url', 'registered'))) { |
|
| 1005 | + $_orderby = 'user_'.$orderby; |
|
| 1006 | + } elseif (in_array($orderby, array('user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered'))) { |
|
| 1007 | 1007 | $_orderby = $orderby; |
| 1008 | - } elseif ( 'name' == $orderby || 'display_name' == $orderby ) { |
|
| 1008 | + } elseif ('name' == $orderby || 'display_name' == $orderby) { |
|
| 1009 | 1009 | $_orderby = 'display_name'; |
| 1010 | - } elseif ( 'post_count' == $orderby ) { |
|
| 1010 | + } elseif ('post_count' == $orderby) { |
|
| 1011 | 1011 | // todo: avoid the JOIN |
| 1012 | - $where = get_posts_by_author_sql( 'post' ); |
|
| 1012 | + $where = get_posts_by_author_sql('post'); |
|
| 1013 | 1013 | $this->query_from .= " LEFT OUTER JOIN ( |
| 1014 | 1014 | SELECT post_author, COUNT(*) as post_count |
| 1015 | 1015 | FROM $wpdb->posts |
@@ -1018,19 +1018,19 @@ discard block |
||
| 1018 | 1018 | ) p ON ({$wpdb->users}.ID = p.post_author) |
| 1019 | 1019 | "; |
| 1020 | 1020 | $_orderby = 'post_count'; |
| 1021 | - } elseif ( 'ID' == $orderby || 'id' == $orderby ) { |
|
| 1021 | + } elseif ('ID' == $orderby || 'id' == $orderby) { |
|
| 1022 | 1022 | $_orderby = 'ID'; |
| 1023 | - } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { |
|
| 1023 | + } elseif ('meta_value' == $orderby || $this->get('meta_key') == $orderby) { |
|
| 1024 | 1024 | $_orderby = "$wpdb->usermeta.meta_value"; |
| 1025 | - } elseif ( 'meta_value_num' == $orderby ) { |
|
| 1025 | + } elseif ('meta_value_num' == $orderby) { |
|
| 1026 | 1026 | $_orderby = "$wpdb->usermeta.meta_value+0"; |
| 1027 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
| 1028 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
| 1029 | - $include_sql = implode( ',', $include ); |
|
| 1027 | + } elseif ('include' === $orderby && ! empty($this->query_vars['include'])) { |
|
| 1028 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
| 1029 | + $include_sql = implode(',', $include); |
|
| 1030 | 1030 | $_orderby = "FIELD( $wpdb->users.ID, $include_sql )"; |
| 1031 | - } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) { |
|
| 1032 | - $meta_clause = $meta_query_clauses[ $orderby ]; |
|
| 1033 | - $_orderby = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); |
|
| 1031 | + } elseif (isset($meta_query_clauses[$orderby])) { |
|
| 1032 | + $meta_clause = $meta_query_clauses[$orderby]; |
|
| 1033 | + $_orderby = sprintf("CAST(%s.meta_value AS %s)", esc_sql($meta_clause['alias']), esc_sql($meta_clause['cast'])); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | return $_orderby; |
@@ -1045,12 +1045,12 @@ discard block |
||
| 1045 | 1045 | * @param string $order The 'order' query variable. |
| 1046 | 1046 | * @return string The sanitized 'order' query variable. |
| 1047 | 1047 | */ |
| 1048 | - protected function parse_order( $order ) { |
|
| 1049 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
| 1048 | + protected function parse_order($order) { |
|
| 1049 | + if ( ! is_string($order) || empty($order)) { |
|
| 1050 | 1050 | return 'DESC'; |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
| 1053 | + if ('ASC' === strtoupper($order)) { |
|
| 1054 | 1054 | return 'ASC'; |
| 1055 | 1055 | } else { |
| 1056 | 1056 | return 'DESC'; |
@@ -1066,8 +1066,8 @@ discard block |
||
| 1066 | 1066 | * @param string $name Property to get. |
| 1067 | 1067 | * @return mixed Property. |
| 1068 | 1068 | */ |
| 1069 | - public function __get( $name ) { |
|
| 1070 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 1069 | + public function __get($name) { |
|
| 1070 | + if (in_array($name, $this->compat_fields)) { |
|
| 1071 | 1071 | return $this->$name; |
| 1072 | 1072 | } |
| 1073 | 1073 | } |
@@ -1082,8 +1082,8 @@ discard block |
||
| 1082 | 1082 | * @param mixed $value Property value. |
| 1083 | 1083 | * @return mixed Newly-set property. |
| 1084 | 1084 | */ |
| 1085 | - public function __set( $name, $value ) { |
|
| 1086 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 1085 | + public function __set($name, $value) { |
|
| 1086 | + if (in_array($name, $this->compat_fields)) { |
|
| 1087 | 1087 | return $this->$name = $value; |
| 1088 | 1088 | } |
| 1089 | 1089 | } |
@@ -1097,9 +1097,9 @@ discard block |
||
| 1097 | 1097 | * @param string $name Property to check if set. |
| 1098 | 1098 | * @return bool Whether the property is set. |
| 1099 | 1099 | */ |
| 1100 | - public function __isset( $name ) { |
|
| 1101 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 1102 | - return isset( $this->$name ); |
|
| 1100 | + public function __isset($name) { |
|
| 1101 | + if (in_array($name, $this->compat_fields)) { |
|
| 1102 | + return isset($this->$name); |
|
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | 1105 | |
@@ -1111,9 +1111,9 @@ discard block |
||
| 1111 | 1111 | * |
| 1112 | 1112 | * @param string $name Property to unset. |
| 1113 | 1113 | */ |
| 1114 | - public function __unset( $name ) { |
|
| 1115 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 1116 | - unset( $this->$name ); |
|
| 1114 | + public function __unset($name) { |
|
| 1115 | + if (in_array($name, $this->compat_fields)) { |
|
| 1116 | + unset($this->$name); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | } |
| 1119 | 1119 | |
@@ -1127,9 +1127,9 @@ discard block |
||
| 1127 | 1127 | * @param array $arguments Arguments to pass when calling. |
| 1128 | 1128 | * @return mixed Return value of the callback, false otherwise. |
| 1129 | 1129 | */ |
| 1130 | - public function __call( $name, $arguments ) { |
|
| 1131 | - if ( 'get_search_sql' === $name ) { |
|
| 1132 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 1130 | + public function __call($name, $arguments) { |
|
| 1131 | + if ('get_search_sql' === $name) { |
|
| 1132 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | return false; |
| 1135 | 1135 | } |
@@ -1146,9 +1146,9 @@ discard block |
||
| 1146 | 1146 | * for more information on accepted arguments. |
| 1147 | 1147 | * @return array List of users. |
| 1148 | 1148 | */ |
| 1149 | -function get_users( $args = array() ) { |
|
| 1149 | +function get_users($args = array()) { |
|
| 1150 | 1150 | |
| 1151 | - $args = wp_parse_args( $args ); |
|
| 1151 | + $args = wp_parse_args($args); |
|
| 1152 | 1152 | $args['count_total'] = false; |
| 1153 | 1153 | |
| 1154 | 1154 | $user_search = new WP_User_Query($args); |
@@ -1169,40 +1169,40 @@ discard block |
||
| 1169 | 1169 | * @return array A list of the user's blogs. An empty array if the user doesn't exist |
| 1170 | 1170 | * or belongs to no blogs. |
| 1171 | 1171 | */ |
| 1172 | -function get_blogs_of_user( $user_id, $all = false ) { |
|
| 1172 | +function get_blogs_of_user($user_id, $all = false) { |
|
| 1173 | 1173 | global $wpdb; |
| 1174 | 1174 | |
| 1175 | 1175 | $user_id = (int) $user_id; |
| 1176 | 1176 | |
| 1177 | 1177 | // Logged out users can't have blogs |
| 1178 | - if ( empty( $user_id ) ) |
|
| 1178 | + if (empty($user_id)) |
|
| 1179 | 1179 | return array(); |
| 1180 | 1180 | |
| 1181 | - $keys = get_user_meta( $user_id ); |
|
| 1182 | - if ( empty( $keys ) ) |
|
| 1181 | + $keys = get_user_meta($user_id); |
|
| 1182 | + if (empty($keys)) |
|
| 1183 | 1183 | return array(); |
| 1184 | 1184 | |
| 1185 | - if ( ! is_multisite() ) { |
|
| 1185 | + if ( ! is_multisite()) { |
|
| 1186 | 1186 | $blog_id = get_current_blog_id(); |
| 1187 | - $blogs = array( $blog_id => new stdClass ); |
|
| 1188 | - $blogs[ $blog_id ]->userblog_id = $blog_id; |
|
| 1189 | - $blogs[ $blog_id ]->blogname = get_option('blogname'); |
|
| 1190 | - $blogs[ $blog_id ]->domain = ''; |
|
| 1191 | - $blogs[ $blog_id ]->path = ''; |
|
| 1192 | - $blogs[ $blog_id ]->site_id = 1; |
|
| 1193 | - $blogs[ $blog_id ]->siteurl = get_option('siteurl'); |
|
| 1194 | - $blogs[ $blog_id ]->archived = 0; |
|
| 1195 | - $blogs[ $blog_id ]->spam = 0; |
|
| 1196 | - $blogs[ $blog_id ]->deleted = 0; |
|
| 1187 | + $blogs = array($blog_id => new stdClass); |
|
| 1188 | + $blogs[$blog_id]->userblog_id = $blog_id; |
|
| 1189 | + $blogs[$blog_id]->blogname = get_option('blogname'); |
|
| 1190 | + $blogs[$blog_id]->domain = ''; |
|
| 1191 | + $blogs[$blog_id]->path = ''; |
|
| 1192 | + $blogs[$blog_id]->site_id = 1; |
|
| 1193 | + $blogs[$blog_id]->siteurl = get_option('siteurl'); |
|
| 1194 | + $blogs[$blog_id]->archived = 0; |
|
| 1195 | + $blogs[$blog_id]->spam = 0; |
|
| 1196 | + $blogs[$blog_id]->deleted = 0; |
|
| 1197 | 1197 | return $blogs; |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | $blogs = array(); |
| 1201 | 1201 | |
| 1202 | - if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { |
|
| 1203 | - $blog = get_blog_details( 1 ); |
|
| 1204 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
| 1205 | - $blogs[ 1 ] = (object) array( |
|
| 1202 | + if (isset($keys[$wpdb->base_prefix.'capabilities']) && defined('MULTISITE')) { |
|
| 1203 | + $blog = get_blog_details(1); |
|
| 1204 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
| 1205 | + $blogs[1] = (object) array( |
|
| 1206 | 1206 | 'userblog_id' => 1, |
| 1207 | 1207 | 'blogname' => $blog->blogname, |
| 1208 | 1208 | 'domain' => $blog->domain, |
@@ -1215,24 +1215,24 @@ discard block |
||
| 1215 | 1215 | 'deleted' => $blog->deleted, |
| 1216 | 1216 | ); |
| 1217 | 1217 | } |
| 1218 | - unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); |
|
| 1218 | + unset($keys[$wpdb->base_prefix.'capabilities']); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | - $keys = array_keys( $keys ); |
|
| 1221 | + $keys = array_keys($keys); |
|
| 1222 | 1222 | |
| 1223 | - foreach ( $keys as $key ) { |
|
| 1224 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
| 1223 | + foreach ($keys as $key) { |
|
| 1224 | + if ('capabilities' !== substr($key, -12)) |
|
| 1225 | 1225 | continue; |
| 1226 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
| 1226 | + if ($wpdb->base_prefix && 0 !== strpos($key, $wpdb->base_prefix)) |
|
| 1227 | 1227 | continue; |
| 1228 | - $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
|
| 1229 | - if ( ! is_numeric( $blog_id ) ) |
|
| 1228 | + $blog_id = str_replace(array($wpdb->base_prefix, '_capabilities'), '', $key); |
|
| 1229 | + if ( ! is_numeric($blog_id)) |
|
| 1230 | 1230 | continue; |
| 1231 | 1231 | |
| 1232 | 1232 | $blog_id = (int) $blog_id; |
| 1233 | - $blog = get_blog_details( $blog_id ); |
|
| 1234 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
| 1235 | - $blogs[ $blog_id ] = (object) array( |
|
| 1233 | + $blog = get_blog_details($blog_id); |
|
| 1234 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
| 1235 | + $blogs[$blog_id] = (object) array( |
|
| 1236 | 1236 | 'userblog_id' => $blog_id, |
| 1237 | 1237 | 'blogname' => $blog->blogname, |
| 1238 | 1238 | 'domain' => $blog->domain, |
@@ -1257,7 +1257,7 @@ discard block |
||
| 1257 | 1257 | * @param bool $all Whether the returned blogs array should contain all blogs, including |
| 1258 | 1258 | * those marked 'deleted', 'archived', or 'spam'. Default false. |
| 1259 | 1259 | */ |
| 1260 | - return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all ); |
|
| 1260 | + return apply_filters('get_blogs_of_user', $blogs, $user_id, $all); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | /** |
@@ -1269,18 +1269,18 @@ discard block |
||
| 1269 | 1269 | * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site. |
| 1270 | 1270 | * @return bool |
| 1271 | 1271 | */ |
| 1272 | -function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { |
|
| 1272 | +function is_user_member_of_blog($user_id = 0, $blog_id = 0) { |
|
| 1273 | 1273 | $user_id = (int) $user_id; |
| 1274 | 1274 | $blog_id = (int) $blog_id; |
| 1275 | 1275 | |
| 1276 | - if ( empty( $user_id ) ) |
|
| 1276 | + if (empty($user_id)) |
|
| 1277 | 1277 | $user_id = get_current_user_id(); |
| 1278 | 1278 | |
| 1279 | - if ( empty( $blog_id ) ) |
|
| 1279 | + if (empty($blog_id)) |
|
| 1280 | 1280 | $blog_id = get_current_blog_id(); |
| 1281 | 1281 | |
| 1282 | - $blogs = get_blogs_of_user( $user_id ); |
|
| 1283 | - return array_key_exists( $blog_id, $blogs ); |
|
| 1282 | + $blogs = get_blogs_of_user($user_id); |
|
| 1283 | + return array_key_exists($blog_id, $blogs); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | /** |
@@ -1379,23 +1379,23 @@ discard block |
||
| 1379 | 1379 | $blog_prefix = $wpdb->get_blog_prefix($id); |
| 1380 | 1380 | $result = array(); |
| 1381 | 1381 | |
| 1382 | - if ( 'time' == $strategy ) { |
|
| 1382 | + if ('time' == $strategy) { |
|
| 1383 | 1383 | $avail_roles = wp_roles()->get_names(); |
| 1384 | 1384 | |
| 1385 | 1385 | // Build a CPU-intensive query that will return concise information. |
| 1386 | 1386 | $select_count = array(); |
| 1387 | - foreach ( $avail_roles as $this_role => $name ) { |
|
| 1388 | - $select_count[] = $wpdb->prepare( "COUNT(NULLIF(`meta_value` LIKE %s, false))", '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%'); |
|
| 1387 | + foreach ($avail_roles as $this_role => $name) { |
|
| 1388 | + $select_count[] = $wpdb->prepare("COUNT(NULLIF(`meta_value` LIKE %s, false))", '%'.$wpdb->esc_like('"'.$this_role.'"').'%'); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | $select_count = implode(', ', $select_count); |
| 1391 | 1391 | |
| 1392 | 1392 | // Add the meta_value index to the selection list, then run the query. |
| 1393 | - $row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); |
|
| 1393 | + $row = $wpdb->get_row("SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N); |
|
| 1394 | 1394 | |
| 1395 | 1395 | // Run the previous loop again to associate results with role names. |
| 1396 | 1396 | $col = 0; |
| 1397 | 1397 | $role_counts = array(); |
| 1398 | - foreach ( $avail_roles as $this_role => $name ) { |
|
| 1398 | + foreach ($avail_roles as $this_role => $name) { |
|
| 1399 | 1399 | $count = (int) $row[$col++]; |
| 1400 | 1400 | if ($count > 0) { |
| 1401 | 1401 | $role_counts[$this_role] = $count; |
@@ -1406,18 +1406,18 @@ discard block |
||
| 1406 | 1406 | $total_users = (int) $row[$col]; |
| 1407 | 1407 | |
| 1408 | 1408 | $result['total_users'] = $total_users; |
| 1409 | - $result['avail_roles'] =& $role_counts; |
|
| 1409 | + $result['avail_roles'] = & $role_counts; |
|
| 1410 | 1410 | } else { |
| 1411 | 1411 | $avail_roles = array(); |
| 1412 | 1412 | |
| 1413 | - $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" ); |
|
| 1413 | + $users_of_blog = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'"); |
|
| 1414 | 1414 | |
| 1415 | - foreach ( $users_of_blog as $caps_meta ) { |
|
| 1415 | + foreach ($users_of_blog as $caps_meta) { |
|
| 1416 | 1416 | $b_roles = maybe_unserialize($caps_meta); |
| 1417 | - if ( ! is_array( $b_roles ) ) |
|
| 1417 | + if ( ! is_array($b_roles)) |
|
| 1418 | 1418 | continue; |
| 1419 | - foreach ( $b_roles as $b_role => $val ) { |
|
| 1420 | - if ( isset($avail_roles[$b_role]) ) { |
|
| 1419 | + foreach ($b_roles as $b_role => $val) { |
|
| 1420 | + if (isset($avail_roles[$b_role])) { |
|
| 1421 | 1421 | $avail_roles[$b_role]++; |
| 1422 | 1422 | } else { |
| 1423 | 1423 | $avail_roles[$b_role] = 1; |
@@ -1425,8 +1425,8 @@ discard block |
||
| 1425 | 1425 | } |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - $result['total_users'] = count( $users_of_blog ); |
|
| 1429 | - $result['avail_roles'] =& $avail_roles; |
|
| 1428 | + $result['total_users'] = count($users_of_blog); |
|
| 1429 | + $result['avail_roles'] = & $avail_roles; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | return $result; |
@@ -1456,11 +1456,11 @@ discard block |
||
| 1456 | 1456 | function setup_userdata($for_user_id = '') { |
| 1457 | 1457 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
| 1458 | 1458 | |
| 1459 | - if ( '' == $for_user_id ) |
|
| 1459 | + if ('' == $for_user_id) |
|
| 1460 | 1460 | $for_user_id = get_current_user_id(); |
| 1461 | - $user = get_userdata( $for_user_id ); |
|
| 1461 | + $user = get_userdata($for_user_id); |
|
| 1462 | 1462 | |
| 1463 | - if ( ! $user ) { |
|
| 1463 | + if ( ! $user) { |
|
| 1464 | 1464 | $user_ID = 0; |
| 1465 | 1465 | $user_level = 0; |
| 1466 | 1466 | $userdata = null; |
@@ -1532,7 +1532,7 @@ discard block |
||
| 1532 | 1532 | * } |
| 1533 | 1533 | * @return string String of HTML content. |
| 1534 | 1534 | */ |
| 1535 | -function wp_dropdown_users( $args = '' ) { |
|
| 1535 | +function wp_dropdown_users($args = '') { |
|
| 1536 | 1536 | $defaults = array( |
| 1537 | 1537 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
| 1538 | 1538 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -1543,53 +1543,53 @@ discard block |
||
| 1543 | 1543 | 'option_none_value' => -1 |
| 1544 | 1544 | ); |
| 1545 | 1545 | |
| 1546 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
| 1546 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
| 1547 | 1547 | |
| 1548 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1548 | + $r = wp_parse_args($args, $defaults); |
|
| 1549 | 1549 | $show = $r['show']; |
| 1550 | 1550 | $show_option_all = $r['show_option_all']; |
| 1551 | 1551 | $show_option_none = $r['show_option_none']; |
| 1552 | 1552 | $option_none_value = $r['option_none_value']; |
| 1553 | 1553 | |
| 1554 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
| 1555 | - $query_args['fields'] = array( 'ID', 'user_login', $show ); |
|
| 1556 | - $users = get_users( $query_args ); |
|
| 1554 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
| 1555 | + $query_args['fields'] = array('ID', 'user_login', $show); |
|
| 1556 | + $users = get_users($query_args); |
|
| 1557 | 1557 | |
| 1558 | 1558 | $output = ''; |
| 1559 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
| 1560 | - $name = esc_attr( $r['name'] ); |
|
| 1561 | - if ( $r['multi'] && ! $r['id'] ) { |
|
| 1559 | + if ( ! empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
| 1560 | + $name = esc_attr($r['name']); |
|
| 1561 | + if ($r['multi'] && ! $r['id']) { |
|
| 1562 | 1562 | $id = ''; |
| 1563 | 1563 | } else { |
| 1564 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
| 1564 | + $id = $r['id'] ? " id='".esc_attr($r['id'])."'" : " id='$name'"; |
|
| 1565 | 1565 | } |
| 1566 | - $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
|
| 1566 | + $output = "<select name='{$name}'{$id} class='".$r['class']."'>\n"; |
|
| 1567 | 1567 | |
| 1568 | - if ( $show_option_all ) { |
|
| 1568 | + if ($show_option_all) { |
|
| 1569 | 1569 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | - if ( $show_option_none ) { |
|
| 1573 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
| 1574 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
| 1572 | + if ($show_option_none) { |
|
| 1573 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
| 1574 | + $output .= "\t<option value='".esc_attr($option_none_value)."'$_selected>$show_option_none</option>\n"; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | $found_selected = false; |
| 1578 | - foreach ( (array) $users as $user ) { |
|
| 1578 | + foreach ((array) $users as $user) { |
|
| 1579 | 1579 | $user->ID = (int) $user->ID; |
| 1580 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
| 1581 | - if ( $_selected ) { |
|
| 1580 | + $_selected = selected($user->ID, $r['selected'], false); |
|
| 1581 | + if ($_selected) { |
|
| 1582 | 1582 | $found_selected = true; |
| 1583 | 1583 | } |
| 1584 | - $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')'; |
|
| 1585 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
| 1584 | + $display = ! empty($user->$show) ? $user->$show : '('.$user->user_login.')'; |
|
| 1585 | + $output .= "\t<option value='$user->ID'$_selected>".esc_html($display)."</option>\n"; |
|
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | - if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) { |
|
| 1589 | - $user = get_userdata( $r['selected'] ); |
|
| 1590 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
| 1591 | - $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')'; |
|
| 1592 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
| 1588 | + if ($r['include_selected'] && ! $found_selected && ($r['selected'] > 0)) { |
|
| 1589 | + $user = get_userdata($r['selected']); |
|
| 1590 | + $_selected = selected($user->ID, $r['selected'], false); |
|
| 1591 | + $display = ! empty($user->$show) ? $user->$show : '('.$user->user_login.')'; |
|
| 1592 | + $output .= "\t<option value='$user->ID'$_selected>".esc_html($display)."</option>\n"; |
|
| 1593 | 1593 | } |
| 1594 | 1594 | |
| 1595 | 1595 | $output .= "</select>"; |
@@ -1602,9 +1602,9 @@ discard block |
||
| 1602 | 1602 | * |
| 1603 | 1603 | * @param string $output HTML output generated by wp_dropdown_users(). |
| 1604 | 1604 | */ |
| 1605 | - $html = apply_filters( 'wp_dropdown_users', $output ); |
|
| 1605 | + $html = apply_filters('wp_dropdown_users', $output); |
|
| 1606 | 1606 | |
| 1607 | - if ( $r['echo'] ) { |
|
| 1607 | + if ($r['echo']) { |
|
| 1608 | 1608 | echo $html; |
| 1609 | 1609 | } |
| 1610 | 1610 | return $html; |
@@ -1628,22 +1628,22 @@ discard block |
||
| 1628 | 1628 | */ |
| 1629 | 1629 | function sanitize_user_field($field, $value, $user_id, $context) { |
| 1630 | 1630 | $int_fields = array('ID'); |
| 1631 | - if ( in_array($field, $int_fields) ) |
|
| 1631 | + if (in_array($field, $int_fields)) |
|
| 1632 | 1632 | $value = (int) $value; |
| 1633 | 1633 | |
| 1634 | - if ( 'raw' == $context ) |
|
| 1634 | + if ('raw' == $context) |
|
| 1635 | 1635 | return $value; |
| 1636 | 1636 | |
| 1637 | - if ( !is_string($value) && !is_numeric($value) ) |
|
| 1637 | + if ( ! is_string($value) && ! is_numeric($value)) |
|
| 1638 | 1638 | return $value; |
| 1639 | 1639 | |
| 1640 | - $prefixed = false !== strpos( $field, 'user_' ); |
|
| 1640 | + $prefixed = false !== strpos($field, 'user_'); |
|
| 1641 | 1641 | |
| 1642 | - if ( 'edit' == $context ) { |
|
| 1643 | - if ( $prefixed ) { |
|
| 1642 | + if ('edit' == $context) { |
|
| 1643 | + if ($prefixed) { |
|
| 1644 | 1644 | |
| 1645 | 1645 | /** This filter is documented in wp-includes/post.php */ |
| 1646 | - $value = apply_filters( "edit_{$field}", $value, $user_id ); |
|
| 1646 | + $value = apply_filters("edit_{$field}", $value, $user_id); |
|
| 1647 | 1647 | } else { |
| 1648 | 1648 | |
| 1649 | 1649 | /** |
@@ -1657,17 +1657,17 @@ discard block |
||
| 1657 | 1657 | * @param mixed $value Value of the prefixed user field. |
| 1658 | 1658 | * @param int $user_id User ID. |
| 1659 | 1659 | */ |
| 1660 | - $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
|
| 1660 | + $value = apply_filters("edit_user_{$field}", $value, $user_id); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | - if ( 'description' == $field ) |
|
| 1664 | - $value = esc_html( $value ); // textarea_escaped? |
|
| 1663 | + if ('description' == $field) |
|
| 1664 | + $value = esc_html($value); // textarea_escaped? |
|
| 1665 | 1665 | else |
| 1666 | 1666 | $value = esc_attr($value); |
| 1667 | - } elseif ( 'db' == $context ) { |
|
| 1668 | - if ( $prefixed ) { |
|
| 1667 | + } elseif ('db' == $context) { |
|
| 1668 | + if ($prefixed) { |
|
| 1669 | 1669 | /** This filter is documented in wp-includes/post.php */ |
| 1670 | - $value = apply_filters( "pre_{$field}", $value ); |
|
| 1670 | + $value = apply_filters("pre_{$field}", $value); |
|
| 1671 | 1671 | } else { |
| 1672 | 1672 | |
| 1673 | 1673 | /** |
@@ -1680,14 +1680,14 @@ discard block |
||
| 1680 | 1680 | * |
| 1681 | 1681 | * @param mixed $value Value of the prefixed user field. |
| 1682 | 1682 | */ |
| 1683 | - $value = apply_filters( "pre_user_{$field}", $value ); |
|
| 1683 | + $value = apply_filters("pre_user_{$field}", $value); |
|
| 1684 | 1684 | } |
| 1685 | 1685 | } else { |
| 1686 | 1686 | // Use display filters by default. |
| 1687 | - if ( $prefixed ) { |
|
| 1687 | + if ($prefixed) { |
|
| 1688 | 1688 | |
| 1689 | 1689 | /** This filter is documented in wp-includes/post.php */ |
| 1690 | - $value = apply_filters( $field, $value, $user_id, $context ); |
|
| 1690 | + $value = apply_filters($field, $value, $user_id, $context); |
|
| 1691 | 1691 | } else { |
| 1692 | 1692 | |
| 1693 | 1693 | /** |
@@ -1702,17 +1702,17 @@ discard block |
||
| 1702 | 1702 | * @param int $user_id User ID. |
| 1703 | 1703 | * @param string $context The context to filter within. |
| 1704 | 1704 | */ |
| 1705 | - $value = apply_filters( "user_{$field}", $value, $user_id, $context ); |
|
| 1705 | + $value = apply_filters("user_{$field}", $value, $user_id, $context); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | - if ( 'user_url' == $field ) |
|
| 1709 | + if ('user_url' == $field) |
|
| 1710 | 1710 | $value = esc_url($value); |
| 1711 | 1711 | |
| 1712 | - if ( 'attribute' == $context ) { |
|
| 1713 | - $value = esc_attr( $value ); |
|
| 1714 | - } elseif ( 'js' == $context ) { |
|
| 1715 | - $value = esc_js( $value ); |
|
| 1712 | + if ('attribute' == $context) { |
|
| 1713 | + $value = esc_attr($value); |
|
| 1714 | + } elseif ('js' == $context) { |
|
| 1715 | + $value = esc_js($value); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | return $value; |
| 1718 | 1718 | } |
@@ -1738,17 +1738,17 @@ discard block |
||
| 1738 | 1738 | * |
| 1739 | 1739 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
| 1740 | 1740 | */ |
| 1741 | -function clean_user_cache( $user ) { |
|
| 1742 | - if ( is_numeric( $user ) ) |
|
| 1743 | - $user = new WP_User( $user ); |
|
| 1741 | +function clean_user_cache($user) { |
|
| 1742 | + if (is_numeric($user)) |
|
| 1743 | + $user = new WP_User($user); |
|
| 1744 | 1744 | |
| 1745 | - if ( ! $user->exists() ) |
|
| 1745 | + if ( ! $user->exists()) |
|
| 1746 | 1746 | return; |
| 1747 | 1747 | |
| 1748 | - wp_cache_delete( $user->ID, 'users' ); |
|
| 1749 | - wp_cache_delete( $user->user_login, 'userlogins' ); |
|
| 1750 | - wp_cache_delete( $user->user_email, 'useremail' ); |
|
| 1751 | - wp_cache_delete( $user->user_nicename, 'userslugs' ); |
|
| 1748 | + wp_cache_delete($user->ID, 'users'); |
|
| 1749 | + wp_cache_delete($user->user_login, 'userlogins'); |
|
| 1750 | + wp_cache_delete($user->user_email, 'useremail'); |
|
| 1751 | + wp_cache_delete($user->user_nicename, 'userslugs'); |
|
| 1752 | 1752 | } |
| 1753 | 1753 | |
| 1754 | 1754 | /** |
@@ -1759,8 +1759,8 @@ discard block |
||
| 1759 | 1759 | * @param string $username Username. |
| 1760 | 1760 | * @return int|false The user's ID on success, and false on failure. |
| 1761 | 1761 | */ |
| 1762 | -function username_exists( $username ) { |
|
| 1763 | - if ( $user = get_user_by( 'login', $username ) ) { |
|
| 1762 | +function username_exists($username) { |
|
| 1763 | + if ($user = get_user_by('login', $username)) { |
|
| 1764 | 1764 | return $user->ID; |
| 1765 | 1765 | } |
| 1766 | 1766 | return false; |
@@ -1774,8 +1774,8 @@ discard block |
||
| 1774 | 1774 | * @param string $email Email. |
| 1775 | 1775 | * @return int|false The user's ID on success, and false on failure. |
| 1776 | 1776 | */ |
| 1777 | -function email_exists( $email ) { |
|
| 1778 | - if ( $user = get_user_by( 'email', $email) ) { |
|
| 1777 | +function email_exists($email) { |
|
| 1778 | + if ($user = get_user_by('email', $email)) { |
|
| 1779 | 1779 | return $user->ID; |
| 1780 | 1780 | } |
| 1781 | 1781 | return false; |
@@ -1789,9 +1789,9 @@ discard block |
||
| 1789 | 1789 | * @param string $username Username. |
| 1790 | 1790 | * @return bool Whether username given is valid |
| 1791 | 1791 | */ |
| 1792 | -function validate_username( $username ) { |
|
| 1793 | - $sanitized = sanitize_user( $username, true ); |
|
| 1794 | - $valid = ( $sanitized == $username ); |
|
| 1792 | +function validate_username($username) { |
|
| 1793 | + $sanitized = sanitize_user($username, true); |
|
| 1794 | + $valid = ($sanitized == $username); |
|
| 1795 | 1795 | /** |
| 1796 | 1796 | * Filter whether the provided username is valid or not. |
| 1797 | 1797 | * |
@@ -1800,7 +1800,7 @@ discard block |
||
| 1800 | 1800 | * @param bool $valid Whether given username is valid. |
| 1801 | 1801 | * @param string $username Username to check. |
| 1802 | 1802 | */ |
| 1803 | - return apply_filters( 'validate_username', $valid, $username ); |
|
| 1803 | + return apply_filters('validate_username', $valid, $username); |
|
| 1804 | 1804 | } |
| 1805 | 1805 | |
| 1806 | 1806 | /** |
@@ -1853,28 +1853,28 @@ discard block |
||
| 1853 | 1853 | * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
| 1854 | 1854 | * be created. |
| 1855 | 1855 | */ |
| 1856 | -function wp_insert_user( $userdata ) { |
|
| 1856 | +function wp_insert_user($userdata) { |
|
| 1857 | 1857 | global $wpdb; |
| 1858 | 1858 | |
| 1859 | - if ( $userdata instanceof stdClass ) { |
|
| 1860 | - $userdata = get_object_vars( $userdata ); |
|
| 1861 | - } elseif ( $userdata instanceof WP_User ) { |
|
| 1859 | + if ($userdata instanceof stdClass) { |
|
| 1860 | + $userdata = get_object_vars($userdata); |
|
| 1861 | + } elseif ($userdata instanceof WP_User) { |
|
| 1862 | 1862 | $userdata = $userdata->to_array(); |
| 1863 | 1863 | } |
| 1864 | 1864 | // Are we updating or creating? |
| 1865 | - if ( ! empty( $userdata['ID'] ) ) { |
|
| 1865 | + if ( ! empty($userdata['ID'])) { |
|
| 1866 | 1866 | $ID = (int) $userdata['ID']; |
| 1867 | 1867 | $update = true; |
| 1868 | - $old_user_data = WP_User::get_data_by( 'id', $ID ); |
|
| 1868 | + $old_user_data = WP_User::get_data_by('id', $ID); |
|
| 1869 | 1869 | // hashed in wp_update_user(), plaintext if called directly |
| 1870 | 1870 | $user_pass = $userdata['user_pass']; |
| 1871 | 1871 | } else { |
| 1872 | 1872 | $update = false; |
| 1873 | 1873 | // Hash the password |
| 1874 | - $user_pass = wp_hash_password( $userdata['user_pass'] ); |
|
| 1874 | + $user_pass = wp_hash_password($userdata['user_pass']); |
|
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | - $sanitized_user_login = sanitize_user( $userdata['user_login'], true ); |
|
| 1877 | + $sanitized_user_login = sanitize_user($userdata['user_login'], true); |
|
| 1878 | 1878 | |
| 1879 | 1879 | /** |
| 1880 | 1880 | * Filter a username after it has been sanitized. |
@@ -1885,27 +1885,27 @@ discard block |
||
| 1885 | 1885 | * |
| 1886 | 1886 | * @param string $sanitized_user_login Username after it has been sanitized. |
| 1887 | 1887 | */ |
| 1888 | - $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); |
|
| 1888 | + $pre_user_login = apply_filters('pre_user_login', $sanitized_user_login); |
|
| 1889 | 1889 | |
| 1890 | 1890 | //Remove any non-printable chars from the login string to see if we have ended up with an empty username |
| 1891 | - $user_login = trim( $pre_user_login ); |
|
| 1891 | + $user_login = trim($pre_user_login); |
|
| 1892 | 1892 | |
| 1893 | - if ( empty( $user_login ) ) { |
|
| 1894 | - return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); |
|
| 1893 | + if (empty($user_login)) { |
|
| 1894 | + return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.')); |
|
| 1895 | 1895 | } |
| 1896 | - if ( ! $update && username_exists( $user_login ) ) { |
|
| 1897 | - return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
|
| 1896 | + if ( ! $update && username_exists($user_login)) { |
|
| 1897 | + return new WP_Error('existing_user_login', __('Sorry, that username already exists!')); |
|
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | // If a nicename is provided, remove unsafe user characters before |
| 1901 | 1901 | // using it. Otherwise build a nicename from the user_login. |
| 1902 | - if ( ! empty( $userdata['user_nicename'] ) ) { |
|
| 1903 | - $user_nicename = sanitize_user( $userdata['user_nicename'], true ); |
|
| 1902 | + if ( ! empty($userdata['user_nicename'])) { |
|
| 1903 | + $user_nicename = sanitize_user($userdata['user_nicename'], true); |
|
| 1904 | 1904 | } else { |
| 1905 | 1905 | $user_nicename = $user_login; |
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | - $user_nicename = sanitize_title( $user_nicename ); |
|
| 1908 | + $user_nicename = sanitize_title($user_nicename); |
|
| 1909 | 1909 | |
| 1910 | 1910 | // Store values to save in user meta. |
| 1911 | 1911 | $meta = array(); |
@@ -1917,9 +1917,9 @@ discard block |
||
| 1917 | 1917 | * |
| 1918 | 1918 | * @param string $user_nicename The user's nicename. |
| 1919 | 1919 | */ |
| 1920 | - $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); |
|
| 1920 | + $user_nicename = apply_filters('pre_user_nicename', $user_nicename); |
|
| 1921 | 1921 | |
| 1922 | - $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; |
|
| 1922 | + $raw_user_url = empty($userdata['user_url']) ? '' : $userdata['user_url']; |
|
| 1923 | 1923 | |
| 1924 | 1924 | /** |
| 1925 | 1925 | * Filter a user's URL before the user is created or updated. |
@@ -1928,9 +1928,9 @@ discard block |
||
| 1928 | 1928 | * |
| 1929 | 1929 | * @param string $raw_user_url The user's URL. |
| 1930 | 1930 | */ |
| 1931 | - $user_url = apply_filters( 'pre_user_url', $raw_user_url ); |
|
| 1931 | + $user_url = apply_filters('pre_user_url', $raw_user_url); |
|
| 1932 | 1932 | |
| 1933 | - $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; |
|
| 1933 | + $raw_user_email = empty($userdata['user_email']) ? '' : $userdata['user_email']; |
|
| 1934 | 1934 | |
| 1935 | 1935 | /** |
| 1936 | 1936 | * Filter a user's email before the user is created or updated. |
@@ -1939,20 +1939,20 @@ discard block |
||
| 1939 | 1939 | * |
| 1940 | 1940 | * @param string $raw_user_email The user's email. |
| 1941 | 1941 | */ |
| 1942 | - $user_email = apply_filters( 'pre_user_email', $raw_user_email ); |
|
| 1942 | + $user_email = apply_filters('pre_user_email', $raw_user_email); |
|
| 1943 | 1943 | |
| 1944 | 1944 | /* |
| 1945 | 1945 | * If there is no update, just check for `email_exists`. If there is an update, |
| 1946 | 1946 | * check if current email and new email are the same, or not, and check `email_exists` |
| 1947 | 1947 | * accordingly. |
| 1948 | 1948 | */ |
| 1949 | - if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) ) |
|
| 1950 | - && ! defined( 'WP_IMPORTING' ) |
|
| 1951 | - && email_exists( $user_email ) |
|
| 1949 | + if (( ! $update || ( ! empty($old_user_data) && 0 !== strcasecmp($user_email, $old_user_data->user_email))) |
|
| 1950 | + && ! defined('WP_IMPORTING') |
|
| 1951 | + && email_exists($user_email) |
|
| 1952 | 1952 | ) { |
| 1953 | - return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); |
|
| 1953 | + return new WP_Error('existing_user_email', __('Sorry, that email address is already used!')); |
|
| 1954 | 1954 | } |
| 1955 | - $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; |
|
| 1955 | + $nickname = empty($userdata['nickname']) ? $user_login : $userdata['nickname']; |
|
| 1956 | 1956 | |
| 1957 | 1957 | /** |
| 1958 | 1958 | * Filter a user's nickname before the user is created or updated. |
@@ -1961,9 +1961,9 @@ discard block |
||
| 1961 | 1961 | * |
| 1962 | 1962 | * @param string $nickname The user's nickname. |
| 1963 | 1963 | */ |
| 1964 | - $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname ); |
|
| 1964 | + $meta['nickname'] = apply_filters('pre_user_nickname', $nickname); |
|
| 1965 | 1965 | |
| 1966 | - $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; |
|
| 1966 | + $first_name = empty($userdata['first_name']) ? '' : $userdata['first_name']; |
|
| 1967 | 1967 | |
| 1968 | 1968 | /** |
| 1969 | 1969 | * Filter a user's first name before the user is created or updated. |
@@ -1972,9 +1972,9 @@ discard block |
||
| 1972 | 1972 | * |
| 1973 | 1973 | * @param string $first_name The user's first name. |
| 1974 | 1974 | */ |
| 1975 | - $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name ); |
|
| 1975 | + $meta['first_name'] = apply_filters('pre_user_first_name', $first_name); |
|
| 1976 | 1976 | |
| 1977 | - $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; |
|
| 1977 | + $last_name = empty($userdata['last_name']) ? '' : $userdata['last_name']; |
|
| 1978 | 1978 | |
| 1979 | 1979 | /** |
| 1980 | 1980 | * Filter a user's last name before the user is created or updated. |
@@ -1983,17 +1983,17 @@ discard block |
||
| 1983 | 1983 | * |
| 1984 | 1984 | * @param string $last_name The user's last name. |
| 1985 | 1985 | */ |
| 1986 | - $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name ); |
|
| 1986 | + $meta['last_name'] = apply_filters('pre_user_last_name', $last_name); |
|
| 1987 | 1987 | |
| 1988 | - if ( empty( $userdata['display_name'] ) ) { |
|
| 1989 | - if ( $update ) { |
|
| 1988 | + if (empty($userdata['display_name'])) { |
|
| 1989 | + if ($update) { |
|
| 1990 | 1990 | $display_name = $user_login; |
| 1991 | - } elseif ( $meta['first_name'] && $meta['last_name'] ) { |
|
| 1991 | + } elseif ($meta['first_name'] && $meta['last_name']) { |
|
| 1992 | 1992 | /* translators: 1: first name, 2: last name */ |
| 1993 | - $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] ); |
|
| 1994 | - } elseif ( $meta['first_name'] ) { |
|
| 1993 | + $display_name = sprintf(_x('%1$s %2$s', 'Display name based on first name and last name'), $meta['first_name'], $meta['last_name']); |
|
| 1994 | + } elseif ($meta['first_name']) { |
|
| 1995 | 1995 | $display_name = $meta['first_name']; |
| 1996 | - } elseif ( $meta['last_name'] ) { |
|
| 1996 | + } elseif ($meta['last_name']) { |
|
| 1997 | 1997 | $display_name = $meta['last_name']; |
| 1998 | 1998 | } else { |
| 1999 | 1999 | $display_name = $user_login; |
@@ -2009,9 +2009,9 @@ discard block |
||
| 2009 | 2009 | * |
| 2010 | 2010 | * @param string $display_name The user's display name. |
| 2011 | 2011 | */ |
| 2012 | - $display_name = apply_filters( 'pre_user_display_name', $display_name ); |
|
| 2012 | + $display_name = apply_filters('pre_user_display_name', $display_name); |
|
| 2013 | 2013 | |
| 2014 | - $description = empty( $userdata['description'] ) ? '' : $userdata['description']; |
|
| 2014 | + $description = empty($userdata['description']) ? '' : $userdata['description']; |
|
| 2015 | 2015 | |
| 2016 | 2016 | /** |
| 2017 | 2017 | * Filter a user's description before the user is created or updated. |
@@ -2020,69 +2020,69 @@ discard block |
||
| 2020 | 2020 | * |
| 2021 | 2021 | * @param string $description The user's description. |
| 2022 | 2022 | */ |
| 2023 | - $meta['description'] = apply_filters( 'pre_user_description', $description ); |
|
| 2023 | + $meta['description'] = apply_filters('pre_user_description', $description); |
|
| 2024 | 2024 | |
| 2025 | - $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
|
| 2025 | + $meta['rich_editing'] = empty($userdata['rich_editing']) ? 'true' : $userdata['rich_editing']; |
|
| 2026 | 2026 | |
| 2027 | - $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
| 2027 | + $meta['comment_shortcuts'] = empty($userdata['comment_shortcuts']) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
| 2028 | 2028 | |
| 2029 | - $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; |
|
| 2030 | - $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); |
|
| 2029 | + $admin_color = empty($userdata['admin_color']) ? 'fresh' : $userdata['admin_color']; |
|
| 2030 | + $meta['admin_color'] = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color); |
|
| 2031 | 2031 | |
| 2032 | - $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl']; |
|
| 2032 | + $meta['use_ssl'] = empty($userdata['use_ssl']) ? 0 : $userdata['use_ssl']; |
|
| 2033 | 2033 | |
| 2034 | - $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; |
|
| 2034 | + $user_registered = empty($userdata['user_registered']) ? gmdate('Y-m-d H:i:s') : $userdata['user_registered']; |
|
| 2035 | 2035 | |
| 2036 | - $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; |
|
| 2036 | + $meta['show_admin_bar_front'] = empty($userdata['show_admin_bar_front']) ? 'true' : $userdata['show_admin_bar_front']; |
|
| 2037 | 2037 | |
| 2038 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); |
|
| 2038 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login)); |
|
| 2039 | 2039 | |
| 2040 | - if ( $user_nicename_check ) { |
|
| 2040 | + if ($user_nicename_check) { |
|
| 2041 | 2041 | $suffix = 2; |
| 2042 | 2042 | while ($user_nicename_check) { |
| 2043 | - $alt_user_nicename = $user_nicename . "-$suffix"; |
|
| 2044 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login)); |
|
| 2043 | + $alt_user_nicename = $user_nicename."-$suffix"; |
|
| 2044 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login)); |
|
| 2045 | 2045 | $suffix++; |
| 2046 | 2046 | } |
| 2047 | 2047 | $user_nicename = $alt_user_nicename; |
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | - $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); |
|
| 2051 | - $data = wp_unslash( $compacted ); |
|
| 2050 | + $compacted = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered'); |
|
| 2051 | + $data = wp_unslash($compacted); |
|
| 2052 | 2052 | |
| 2053 | - if ( $update ) { |
|
| 2054 | - if ( $user_email !== $old_user_data->user_email ) { |
|
| 2053 | + if ($update) { |
|
| 2054 | + if ($user_email !== $old_user_data->user_email) { |
|
| 2055 | 2055 | $data['user_activation_key'] = ''; |
| 2056 | 2056 | } |
| 2057 | - $wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); |
|
| 2057 | + $wpdb->update($wpdb->users, $data, compact('ID')); |
|
| 2058 | 2058 | $user_id = (int) $ID; |
| 2059 | 2059 | } else { |
| 2060 | - $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) ); |
|
| 2060 | + $wpdb->insert($wpdb->users, $data + compact('user_login')); |
|
| 2061 | 2061 | $user_id = (int) $wpdb->insert_id; |
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | - $user = new WP_User( $user_id ); |
|
| 2064 | + $user = new WP_User($user_id); |
|
| 2065 | 2065 | |
| 2066 | 2066 | // Update user meta. |
| 2067 | - foreach ( $meta as $key => $value ) { |
|
| 2068 | - update_user_meta( $user_id, $key, $value ); |
|
| 2067 | + foreach ($meta as $key => $value) { |
|
| 2068 | + update_user_meta($user_id, $key, $value); |
|
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | - foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) { |
|
| 2072 | - if ( isset( $userdata[ $key ] ) ) { |
|
| 2073 | - update_user_meta( $user_id, $key, $userdata[ $key ] ); |
|
| 2071 | + foreach (wp_get_user_contact_methods($user) as $key => $value) { |
|
| 2072 | + if (isset($userdata[$key])) { |
|
| 2073 | + update_user_meta($user_id, $key, $userdata[$key]); |
|
| 2074 | 2074 | } |
| 2075 | 2075 | } |
| 2076 | 2076 | |
| 2077 | - if ( isset( $userdata['role'] ) ) { |
|
| 2078 | - $user->set_role( $userdata['role'] ); |
|
| 2079 | - } elseif ( ! $update ) { |
|
| 2077 | + if (isset($userdata['role'])) { |
|
| 2078 | + $user->set_role($userdata['role']); |
|
| 2079 | + } elseif ( ! $update) { |
|
| 2080 | 2080 | $user->set_role(get_option('default_role')); |
| 2081 | 2081 | } |
| 2082 | - wp_cache_delete( $user_id, 'users' ); |
|
| 2083 | - wp_cache_delete( $user_login, 'userlogins' ); |
|
| 2082 | + wp_cache_delete($user_id, 'users'); |
|
| 2083 | + wp_cache_delete($user_login, 'userlogins'); |
|
| 2084 | 2084 | |
| 2085 | - if ( $update ) { |
|
| 2085 | + if ($update) { |
|
| 2086 | 2086 | /** |
| 2087 | 2087 | * Fires immediately after an existing user is updated. |
| 2088 | 2088 | * |
@@ -2091,7 +2091,7 @@ discard block |
||
| 2091 | 2091 | * @param int $user_id User ID. |
| 2092 | 2092 | * @param object $old_user_data Object containing user's data prior to update. |
| 2093 | 2093 | */ |
| 2094 | - do_action( 'profile_update', $user_id, $old_user_data ); |
|
| 2094 | + do_action('profile_update', $user_id, $old_user_data); |
|
| 2095 | 2095 | } else { |
| 2096 | 2096 | /** |
| 2097 | 2097 | * Fires immediately after a new user is registered. |
@@ -2100,7 +2100,7 @@ discard block |
||
| 2100 | 2100 | * |
| 2101 | 2101 | * @param int $user_id User ID. |
| 2102 | 2102 | */ |
| 2103 | - do_action( 'user_register', $user_id ); |
|
| 2103 | + do_action('user_register', $user_id); |
|
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | 2106 | return $user_id; |
@@ -2123,37 +2123,37 @@ discard block |
||
| 2123 | 2123 | * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. |
| 2124 | 2124 | */ |
| 2125 | 2125 | function wp_update_user($userdata) { |
| 2126 | - if ( $userdata instanceof stdClass ) { |
|
| 2127 | - $userdata = get_object_vars( $userdata ); |
|
| 2128 | - } elseif ( $userdata instanceof WP_User ) { |
|
| 2126 | + if ($userdata instanceof stdClass) { |
|
| 2127 | + $userdata = get_object_vars($userdata); |
|
| 2128 | + } elseif ($userdata instanceof WP_User) { |
|
| 2129 | 2129 | $userdata = $userdata->to_array(); |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | - $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0; |
|
| 2133 | - if ( ! $ID ) { |
|
| 2134 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
| 2132 | + $ID = isset($userdata['ID']) ? (int) $userdata['ID'] : 0; |
|
| 2133 | + if ( ! $ID) { |
|
| 2134 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | // First, get all of the original fields |
| 2138 | - $user_obj = get_userdata( $ID ); |
|
| 2139 | - if ( ! $user_obj ) { |
|
| 2140 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
| 2138 | + $user_obj = get_userdata($ID); |
|
| 2139 | + if ( ! $user_obj) { |
|
| 2140 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | $user = $user_obj->to_array(); |
| 2144 | 2144 | |
| 2145 | 2145 | // Add additional custom fields |
| 2146 | - foreach ( _get_additional_user_keys( $user_obj ) as $key ) { |
|
| 2147 | - $user[ $key ] = get_user_meta( $ID, $key, true ); |
|
| 2146 | + foreach (_get_additional_user_keys($user_obj) as $key) { |
|
| 2147 | + $user[$key] = get_user_meta($ID, $key, true); |
|
| 2148 | 2148 | } |
| 2149 | 2149 | |
| 2150 | 2150 | // Escape data pulled from DB. |
| 2151 | - $user = add_magic_quotes( $user ); |
|
| 2151 | + $user = add_magic_quotes($user); |
|
| 2152 | 2152 | |
| 2153 | - if ( ! empty($userdata['user_pass']) ) { |
|
| 2153 | + if ( ! empty($userdata['user_pass'])) { |
|
| 2154 | 2154 | // If password is changing, hash it now |
| 2155 | 2155 | $plaintext_pass = $userdata['user_pass']; |
| 2156 | - $userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); |
|
| 2156 | + $userdata['user_pass'] = wp_hash_password($userdata['user_pass']); |
|
| 2157 | 2157 | |
| 2158 | 2158 | /** |
| 2159 | 2159 | * Filter whether to send the password change email. |
@@ -2167,10 +2167,10 @@ discard block |
||
| 2167 | 2167 | * @param array $userdata The updated user array. |
| 2168 | 2168 | * |
| 2169 | 2169 | */ |
| 2170 | - $send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata ); |
|
| 2170 | + $send_password_change_email = apply_filters('send_password_change_email', true, $user, $userdata); |
|
| 2171 | 2171 | } |
| 2172 | 2172 | |
| 2173 | - if ( isset( $userdata['user_email'] ) && $user['user_email'] !== $userdata['user_email'] ) { |
|
| 2173 | + if (isset($userdata['user_email']) && $user['user_email'] !== $userdata['user_email']) { |
|
| 2174 | 2174 | /** |
| 2175 | 2175 | * Filter whether to send the email change email. |
| 2176 | 2176 | * |
@@ -2183,23 +2183,23 @@ discard block |
||
| 2183 | 2183 | * @param array $userdata The updated user array. |
| 2184 | 2184 | * |
| 2185 | 2185 | */ |
| 2186 | - $send_email_change_email = apply_filters( 'send_email_change_email', true, $user, $userdata ); |
|
| 2186 | + $send_email_change_email = apply_filters('send_email_change_email', true, $user, $userdata); |
|
| 2187 | 2187 | } |
| 2188 | 2188 | |
| 2189 | - wp_cache_delete( $user['user_email'], 'useremail' ); |
|
| 2189 | + wp_cache_delete($user['user_email'], 'useremail'); |
|
| 2190 | 2190 | |
| 2191 | 2191 | // Merge old and new fields with new fields overwriting old ones. |
| 2192 | - $userdata = array_merge( $user, $userdata ); |
|
| 2193 | - $user_id = wp_insert_user( $userdata ); |
|
| 2192 | + $userdata = array_merge($user, $userdata); |
|
| 2193 | + $user_id = wp_insert_user($userdata); |
|
| 2194 | 2194 | |
| 2195 | - if ( ! is_wp_error( $user_id ) ) { |
|
| 2195 | + if ( ! is_wp_error($user_id)) { |
|
| 2196 | 2196 | |
| 2197 | - $blog_name = wp_specialchars_decode( get_option( 'blogname' ) ); |
|
| 2197 | + $blog_name = wp_specialchars_decode(get_option('blogname')); |
|
| 2198 | 2198 | |
| 2199 | - if ( ! empty( $send_password_change_email ) ) { |
|
| 2199 | + if ( ! empty($send_password_change_email)) { |
|
| 2200 | 2200 | |
| 2201 | 2201 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
| 2202 | - $pass_change_text = __( 'Hi ###USERNAME###, |
|
| 2202 | + $pass_change_text = __('Hi ###USERNAME###, |
|
| 2203 | 2203 | |
| 2204 | 2204 | This notice confirms that your password was changed on ###SITENAME###. |
| 2205 | 2205 | |
@@ -2214,7 +2214,7 @@ discard block |
||
| 2214 | 2214 | |
| 2215 | 2215 | $pass_change_email = array( |
| 2216 | 2216 | 'to' => $user['user_email'], |
| 2217 | - 'subject' => __( '[%s] Notice of Password Change' ), |
|
| 2217 | + 'subject' => __('[%s] Notice of Password Change'), |
|
| 2218 | 2218 | 'message' => $pass_change_text, |
| 2219 | 2219 | 'headers' => '', |
| 2220 | 2220 | ); |
@@ -2241,20 +2241,20 @@ discard block |
||
| 2241 | 2241 | * @param array $userdata The updated user array. |
| 2242 | 2242 | * |
| 2243 | 2243 | */ |
| 2244 | - $pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata ); |
|
| 2244 | + $pass_change_email = apply_filters('password_change_email', $pass_change_email, $user, $userdata); |
|
| 2245 | 2245 | |
| 2246 | - $pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] ); |
|
| 2247 | - $pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] ); |
|
| 2248 | - $pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] ); |
|
| 2249 | - $pass_change_email['message'] = str_replace( '###SITENAME###', get_option( 'blogname' ), $pass_change_email['message'] ); |
|
| 2250 | - $pass_change_email['message'] = str_replace( '###SITEURL###', get_option( 'siteurl' ), $pass_change_email['message'] ); |
|
| 2246 | + $pass_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $pass_change_email['message']); |
|
| 2247 | + $pass_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $pass_change_email['message']); |
|
| 2248 | + $pass_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $pass_change_email['message']); |
|
| 2249 | + $pass_change_email['message'] = str_replace('###SITENAME###', get_option('blogname'), $pass_change_email['message']); |
|
| 2250 | + $pass_change_email['message'] = str_replace('###SITEURL###', get_option('siteurl'), $pass_change_email['message']); |
|
| 2251 | 2251 | |
| 2252 | - wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); |
|
| 2252 | + wp_mail($pass_change_email['to'], sprintf($pass_change_email['subject'], $blog_name), $pass_change_email['message'], $pass_change_email['headers']); |
|
| 2253 | 2253 | } |
| 2254 | 2254 | |
| 2255 | - if ( ! empty( $send_email_change_email ) ) { |
|
| 2255 | + if ( ! empty($send_email_change_email)) { |
|
| 2256 | 2256 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
| 2257 | - $email_change_text = __( 'Hi ###USERNAME###, |
|
| 2257 | + $email_change_text = __('Hi ###USERNAME###, |
|
| 2258 | 2258 | |
| 2259 | 2259 | This notice confirms that your email was changed on ###SITENAME###. |
| 2260 | 2260 | |
@@ -2269,7 +2269,7 @@ discard block |
||
| 2269 | 2269 | |
| 2270 | 2270 | $email_change_email = array( |
| 2271 | 2271 | 'to' => $user['user_email'], |
| 2272 | - 'subject' => __( '[%s] Notice of Email Change' ), |
|
| 2272 | + 'subject' => __('[%s] Notice of Email Change'), |
|
| 2273 | 2273 | 'message' => $email_change_text, |
| 2274 | 2274 | 'headers' => '', |
| 2275 | 2275 | ); |
@@ -2295,32 +2295,32 @@ discard block |
||
| 2295 | 2295 | * @param array $user The original user array. |
| 2296 | 2296 | * @param array $userdata The updated user array. |
| 2297 | 2297 | */ |
| 2298 | - $email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata ); |
|
| 2298 | + $email_change_email = apply_filters('email_change_email', $email_change_email, $user, $userdata); |
|
| 2299 | 2299 | |
| 2300 | - $email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] ); |
|
| 2301 | - $email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] ); |
|
| 2302 | - $email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] ); |
|
| 2303 | - $email_change_email['message'] = str_replace( '###SITENAME###', get_option( 'blogname' ), $email_change_email['message'] ); |
|
| 2304 | - $email_change_email['message'] = str_replace( '###SITEURL###', get_option( 'siteurl' ), $email_change_email['message'] ); |
|
| 2300 | + $email_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $email_change_email['message']); |
|
| 2301 | + $email_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $email_change_email['message']); |
|
| 2302 | + $email_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $email_change_email['message']); |
|
| 2303 | + $email_change_email['message'] = str_replace('###SITENAME###', get_option('blogname'), $email_change_email['message']); |
|
| 2304 | + $email_change_email['message'] = str_replace('###SITEURL###', get_option('siteurl'), $email_change_email['message']); |
|
| 2305 | 2305 | |
| 2306 | - wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); |
|
| 2306 | + wp_mail($email_change_email['to'], sprintf($email_change_email['subject'], $blog_name), $email_change_email['message'], $email_change_email['headers']); |
|
| 2307 | 2307 | } |
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | 2310 | // Update the cookies if the password changed. |
| 2311 | 2311 | $current_user = wp_get_current_user(); |
| 2312 | - if ( $current_user->ID == $ID ) { |
|
| 2313 | - if ( isset($plaintext_pass) ) { |
|
| 2312 | + if ($current_user->ID == $ID) { |
|
| 2313 | + if (isset($plaintext_pass)) { |
|
| 2314 | 2314 | wp_clear_auth_cookie(); |
| 2315 | 2315 | |
| 2316 | 2316 | // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
| 2317 | 2317 | // If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
| 2318 | - $logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
| 2318 | + $logged_in_cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
| 2319 | 2319 | /** This filter is documented in wp-includes/pluggable.php */ |
| 2320 | - $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false ); |
|
| 2321 | - $remember = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ); |
|
| 2320 | + $default_cookie_life = apply_filters('auth_cookie_expiration', (2 * DAY_IN_SECONDS), $ID, false); |
|
| 2321 | + $remember = (($logged_in_cookie['expiration'] - time()) > $default_cookie_life); |
|
| 2322 | 2322 | |
| 2323 | - wp_set_auth_cookie( $ID, $remember ); |
|
| 2323 | + wp_set_auth_cookie($ID, $remember); |
|
| 2324 | 2324 | } |
| 2325 | 2325 | } |
| 2326 | 2326 | |
@@ -2342,8 +2342,8 @@ discard block |
||
| 2342 | 2342 | * @return int|WP_Error The new user's ID. |
| 2343 | 2343 | */ |
| 2344 | 2344 | function wp_create_user($username, $password, $email = '') { |
| 2345 | - $user_login = wp_slash( $username ); |
|
| 2346 | - $user_email = wp_slash( $email ); |
|
| 2345 | + $user_login = wp_slash($username); |
|
| 2346 | + $user_email = wp_slash($email); |
|
| 2347 | 2347 | $user_pass = $password; |
| 2348 | 2348 | |
| 2349 | 2349 | $userdata = compact('user_login', 'user_email', 'user_pass'); |
@@ -2359,9 +2359,9 @@ discard block |
||
| 2359 | 2359 | * @param WP_User $user WP_User instance. |
| 2360 | 2360 | * @return array |
| 2361 | 2361 | */ |
| 2362 | -function _get_additional_user_keys( $user ) { |
|
| 2363 | - $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' ); |
|
| 2364 | - return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); |
|
| 2362 | +function _get_additional_user_keys($user) { |
|
| 2363 | + $keys = array('first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front'); |
|
| 2364 | + return array_merge($keys, array_keys(wp_get_user_contact_methods($user))); |
|
| 2365 | 2365 | } |
| 2366 | 2366 | |
| 2367 | 2367 | /** |
@@ -2374,13 +2374,13 @@ discard block |
||
| 2374 | 2374 | * @param WP_User $user Optional. WP_User object. |
| 2375 | 2375 | * @return array Array of contact methods and their labels. |
| 2376 | 2376 | */ |
| 2377 | -function wp_get_user_contact_methods( $user = null ) { |
|
| 2377 | +function wp_get_user_contact_methods($user = null) { |
|
| 2378 | 2378 | $methods = array(); |
| 2379 | - if ( get_site_option( 'initial_db_version' ) < 23588 ) { |
|
| 2379 | + if (get_site_option('initial_db_version') < 23588) { |
|
| 2380 | 2380 | $methods = array( |
| 2381 | - 'aim' => __( 'AIM' ), |
|
| 2382 | - 'yim' => __( 'Yahoo IM' ), |
|
| 2383 | - 'jabber' => __( 'Jabber / Google Talk' ) |
|
| 2381 | + 'aim' => __('AIM'), |
|
| 2382 | + 'yim' => __('Yahoo IM'), |
|
| 2383 | + 'jabber' => __('Jabber / Google Talk') |
|
| 2384 | 2384 | ); |
| 2385 | 2385 | } |
| 2386 | 2386 | |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | * @param array $methods Array of contact methods and their labels. |
| 2393 | 2393 | * @param WP_User $user WP_User object. |
| 2394 | 2394 | */ |
| 2395 | - return apply_filters( 'user_contactmethods', $methods, $user ); |
|
| 2395 | + return apply_filters('user_contactmethods', $methods, $user); |
|
| 2396 | 2396 | } |
| 2397 | 2397 | |
| 2398 | 2398 | /** |
@@ -2401,8 +2401,8 @@ discard block |
||
| 2401 | 2401 | * @since 2.9.0 |
| 2402 | 2402 | * @access private |
| 2403 | 2403 | */ |
| 2404 | -function _wp_get_user_contactmethods( $user = null ) { |
|
| 2405 | - return wp_get_user_contact_methods( $user ); |
|
| 2404 | +function _wp_get_user_contactmethods($user = null) { |
|
| 2405 | + return wp_get_user_contact_methods($user); |
|
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | 2408 | /** |
@@ -2413,7 +2413,7 @@ discard block |
||
| 2413 | 2413 | * @return string The password hint text. |
| 2414 | 2414 | */ |
| 2415 | 2415 | function wp_get_password_hint() { |
| 2416 | - $hint = __( 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' ); |
|
| 2416 | + $hint = __('Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'); |
|
| 2417 | 2417 | |
| 2418 | 2418 | /** |
| 2419 | 2419 | * Filter the text describing the site's password complexity policy. |
@@ -2422,7 +2422,7 @@ discard block |
||
| 2422 | 2422 | * |
| 2423 | 2423 | * @param string $hint The password hint text. |
| 2424 | 2424 | */ |
| 2425 | - return apply_filters( 'password_hint', $hint ); |
|
| 2425 | + return apply_filters('password_hint', $hint); |
|
| 2426 | 2426 | } |
| 2427 | 2427 | |
| 2428 | 2428 | /** |
@@ -2447,19 +2447,19 @@ discard block |
||
| 2447 | 2447 | |
| 2448 | 2448 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
| 2449 | 2449 | |
| 2450 | - if ( empty( $key ) || !is_string( $key ) ) |
|
| 2450 | + if (empty($key) || ! is_string($key)) |
|
| 2451 | 2451 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2452 | 2452 | |
| 2453 | - if ( empty($login) || !is_string($login) ) |
|
| 2453 | + if (empty($login) || ! is_string($login)) |
|
| 2454 | 2454 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2455 | 2455 | |
| 2456 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
|
| 2457 | - if ( ! $row ) |
|
| 2456 | + $row = $wpdb->get_row($wpdb->prepare("SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login)); |
|
| 2457 | + if ( ! $row) |
|
| 2458 | 2458 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2459 | 2459 | |
| 2460 | - if ( empty( $wp_hasher ) ) { |
|
| 2461 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
| 2462 | - $wp_hasher = new PasswordHash( 8, true ); |
|
| 2460 | + if (empty($wp_hasher)) { |
|
| 2461 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
| 2462 | + $wp_hasher = new PasswordHash(8, true); |
|
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | 2465 | /** |
@@ -2469,27 +2469,27 @@ discard block |
||
| 2469 | 2469 | * |
| 2470 | 2470 | * @param int $expiration The expiration time in seconds. |
| 2471 | 2471 | */ |
| 2472 | - $expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS ); |
|
| 2472 | + $expiration_duration = apply_filters('password_reset_expiration', DAY_IN_SECONDS); |
|
| 2473 | 2473 | |
| 2474 | - if ( false !== strpos( $row->user_activation_key, ':' ) ) { |
|
| 2475 | - list( $pass_request_time, $pass_key ) = explode( ':', $row->user_activation_key, 2 ); |
|
| 2474 | + if (false !== strpos($row->user_activation_key, ':')) { |
|
| 2475 | + list($pass_request_time, $pass_key) = explode(':', $row->user_activation_key, 2); |
|
| 2476 | 2476 | $expiration_time = $pass_request_time + $expiration_duration; |
| 2477 | 2477 | } else { |
| 2478 | 2478 | $pass_key = $row->user_activation_key; |
| 2479 | 2479 | $expiration_time = false; |
| 2480 | 2480 | } |
| 2481 | 2481 | |
| 2482 | - $hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key ); |
|
| 2482 | + $hash_is_correct = $wp_hasher->CheckPassword($key, $pass_key); |
|
| 2483 | 2483 | |
| 2484 | - if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { |
|
| 2485 | - return get_userdata( $row->ID ); |
|
| 2486 | - } elseif ( $hash_is_correct && $expiration_time ) { |
|
| 2484 | + if ($hash_is_correct && $expiration_time && time() < $expiration_time) { |
|
| 2485 | + return get_userdata($row->ID); |
|
| 2486 | + } elseif ($hash_is_correct && $expiration_time) { |
|
| 2487 | 2487 | // Key has an expiration time that's passed |
| 2488 | - return new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
| 2488 | + return new WP_Error('expired_key', __('Invalid key')); |
|
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | - if ( hash_equals( $row->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) { |
|
| 2492 | - $return = new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
| 2491 | + if (hash_equals($row->user_activation_key, $key) || ($hash_is_correct && ! $expiration_time)) { |
|
| 2492 | + $return = new WP_Error('expired_key', __('Invalid key')); |
|
| 2493 | 2493 | $user_id = $row->ID; |
| 2494 | 2494 | |
| 2495 | 2495 | /** |
@@ -2503,10 +2503,10 @@ discard block |
||
| 2503 | 2503 | * Return a WP_User object to validate the key. |
| 2504 | 2504 | * @param int $user_id The matched user ID. |
| 2505 | 2505 | */ |
| 2506 | - return apply_filters( 'password_reset_key_expired', $return, $user_id ); |
|
| 2506 | + return apply_filters('password_reset_key_expired', $return, $user_id); |
|
| 2507 | 2507 | } |
| 2508 | 2508 | |
| 2509 | - return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
|
| 2509 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2510 | 2510 | } |
| 2511 | 2511 | |
| 2512 | 2512 | /** |
@@ -2517,7 +2517,7 @@ discard block |
||
| 2517 | 2517 | * @param object $user The user |
| 2518 | 2518 | * @param string $new_pass New password for the user in plaintext |
| 2519 | 2519 | */ |
| 2520 | -function reset_password( $user, $new_pass ) { |
|
| 2520 | +function reset_password($user, $new_pass) { |
|
| 2521 | 2521 | /** |
| 2522 | 2522 | * Fires before the user's password is reset. |
| 2523 | 2523 | * |
@@ -2526,12 +2526,12 @@ discard block |
||
| 2526 | 2526 | * @param object $user The user. |
| 2527 | 2527 | * @param string $new_pass New user password. |
| 2528 | 2528 | */ |
| 2529 | - do_action( 'password_reset', $user, $new_pass ); |
|
| 2529 | + do_action('password_reset', $user, $new_pass); |
|
| 2530 | 2530 | |
| 2531 | - wp_set_password( $new_pass, $user->ID ); |
|
| 2532 | - update_user_option( $user->ID, 'default_password_nag', false, true ); |
|
| 2531 | + wp_set_password($new_pass, $user->ID); |
|
| 2532 | + update_user_option($user->ID, 'default_password_nag', false, true); |
|
| 2533 | 2533 | |
| 2534 | - wp_password_change_notification( $user ); |
|
| 2534 | + wp_password_change_notification($user); |
|
| 2535 | 2535 | } |
| 2536 | 2536 | |
| 2537 | 2537 | /** |
@@ -2543,10 +2543,10 @@ discard block |
||
| 2543 | 2543 | * @param string $user_email User's email address to send password and add |
| 2544 | 2544 | * @return int|WP_Error Either user's ID or error on failure. |
| 2545 | 2545 | */ |
| 2546 | -function register_new_user( $user_login, $user_email ) { |
|
| 2546 | +function register_new_user($user_login, $user_email) { |
|
| 2547 | 2547 | $errors = new WP_Error(); |
| 2548 | 2548 | |
| 2549 | - $sanitized_user_login = sanitize_user( $user_login ); |
|
| 2549 | + $sanitized_user_login = sanitize_user($user_login); |
|
| 2550 | 2550 | /** |
| 2551 | 2551 | * Filter the email address of a user being registered. |
| 2552 | 2552 | * |
@@ -2554,26 +2554,26 @@ discard block |
||
| 2554 | 2554 | * |
| 2555 | 2555 | * @param string $user_email The email address of the new user. |
| 2556 | 2556 | */ |
| 2557 | - $user_email = apply_filters( 'user_registration_email', $user_email ); |
|
| 2557 | + $user_email = apply_filters('user_registration_email', $user_email); |
|
| 2558 | 2558 | |
| 2559 | 2559 | // Check the username |
| 2560 | - if ( $sanitized_user_login == '' ) { |
|
| 2561 | - $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); |
|
| 2562 | - } elseif ( ! validate_username( $user_login ) ) { |
|
| 2563 | - $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
|
| 2560 | + if ($sanitized_user_login == '') { |
|
| 2561 | + $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); |
|
| 2562 | + } elseif ( ! validate_username($user_login)) { |
|
| 2563 | + $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); |
|
| 2564 | 2564 | $sanitized_user_login = ''; |
| 2565 | - } elseif ( username_exists( $sanitized_user_login ) ) { |
|
| 2566 | - $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); |
|
| 2565 | + } elseif (username_exists($sanitized_user_login)) { |
|
| 2566 | + $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); |
|
| 2567 | 2567 | } |
| 2568 | 2568 | |
| 2569 | 2569 | // Check the e-mail address |
| 2570 | - if ( $user_email == '' ) { |
|
| 2571 | - $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) ); |
|
| 2572 | - } elseif ( ! is_email( $user_email ) ) { |
|
| 2573 | - $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); |
|
| 2570 | + if ($user_email == '') { |
|
| 2571 | + $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); |
|
| 2572 | + } elseif ( ! is_email($user_email)) { |
|
| 2573 | + $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); |
|
| 2574 | 2574 | $user_email = ''; |
| 2575 | - } elseif ( email_exists( $user_email ) ) { |
|
| 2576 | - $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); |
|
| 2575 | + } elseif (email_exists($user_email)) { |
|
| 2576 | + $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); |
|
| 2577 | 2577 | } |
| 2578 | 2578 | |
| 2579 | 2579 | /** |
@@ -2587,7 +2587,7 @@ discard block |
||
| 2587 | 2587 | * e.g., an empty field, an invalid username or email, |
| 2588 | 2588 | * or an existing username or email. |
| 2589 | 2589 | */ |
| 2590 | - do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
|
| 2590 | + do_action('register_post', $sanitized_user_login, $user_email, $errors); |
|
| 2591 | 2591 | |
| 2592 | 2592 | /** |
| 2593 | 2593 | * Filter the errors encountered when a new user is being registered. |
@@ -2605,21 +2605,21 @@ discard block |
||
| 2605 | 2605 | * @param string $sanitized_user_login User's username after it has been sanitized. |
| 2606 | 2606 | * @param string $user_email User's email. |
| 2607 | 2607 | */ |
| 2608 | - $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
|
| 2608 | + $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); |
|
| 2609 | 2609 | |
| 2610 | - if ( $errors->get_error_code() ) |
|
| 2610 | + if ($errors->get_error_code()) |
|
| 2611 | 2611 | return $errors; |
| 2612 | 2612 | |
| 2613 | - $user_pass = wp_generate_password( 12, false ); |
|
| 2614 | - $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
|
| 2615 | - if ( ! $user_id || is_wp_error( $user_id ) ) { |
|
| 2616 | - $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); |
|
| 2613 | + $user_pass = wp_generate_password(12, false); |
|
| 2614 | + $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); |
|
| 2615 | + if ( ! $user_id || is_wp_error($user_id)) { |
|
| 2616 | + $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); |
|
| 2617 | 2617 | return $errors; |
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 2620 | - update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. |
|
| 2620 | + update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. |
|
| 2621 | 2621 | |
| 2622 | - wp_new_user_notification( $user_id, 'both' ); |
|
| 2622 | + wp_new_user_notification($user_id, 'both'); |
|
| 2623 | 2623 | |
| 2624 | 2624 | return $user_id; |
| 2625 | 2625 | } |
@@ -2632,8 +2632,8 @@ discard block |
||
| 2632 | 2632 | * @return string Token. |
| 2633 | 2633 | */ |
| 2634 | 2634 | function wp_get_session_token() { |
| 2635 | - $cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
| 2636 | - return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; |
|
| 2635 | + $cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
| 2636 | + return ! empty($cookie['token']) ? $cookie['token'] : ''; |
|
| 2637 | 2637 | } |
| 2638 | 2638 | |
| 2639 | 2639 | /** |
@@ -2643,7 +2643,7 @@ discard block |
||
| 2643 | 2643 | * @return array Array of sessions. |
| 2644 | 2644 | */ |
| 2645 | 2645 | function wp_get_all_sessions() { |
| 2646 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2646 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2647 | 2647 | return $manager->get_all(); |
| 2648 | 2648 | } |
| 2649 | 2649 | |
@@ -2654,9 +2654,9 @@ discard block |
||
| 2654 | 2654 | */ |
| 2655 | 2655 | function wp_destroy_current_session() { |
| 2656 | 2656 | $token = wp_get_session_token(); |
| 2657 | - if ( $token ) { |
|
| 2658 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2659 | - $manager->destroy( $token ); |
|
| 2657 | + if ($token) { |
|
| 2658 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2659 | + $manager->destroy($token); |
|
| 2660 | 2660 | } |
| 2661 | 2661 | } |
| 2662 | 2662 | |
@@ -2667,9 +2667,9 @@ discard block |
||
| 2667 | 2667 | */ |
| 2668 | 2668 | function wp_destroy_other_sessions() { |
| 2669 | 2669 | $token = wp_get_session_token(); |
| 2670 | - if ( $token ) { |
|
| 2671 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2672 | - $manager->destroy_others( $token ); |
|
| 2670 | + if ($token) { |
|
| 2671 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2672 | + $manager->destroy_others($token); |
|
| 2673 | 2673 | } |
| 2674 | 2674 | } |
| 2675 | 2675 | |
@@ -2679,6 +2679,6 @@ discard block |
||
| 2679 | 2679 | * @since 4.0.0 |
| 2680 | 2680 | */ |
| 2681 | 2681 | function wp_destroy_all_sessions() { |
| 2682 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2682 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2683 | 2683 | $manager->destroy_all(); |
| 2684 | 2684 | } |
@@ -27,18 +27,22 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
| 29 | 29 | if ( empty($credentials) ) { |
| 30 | - if ( ! empty($_POST['log']) ) |
|
| 31 | - $credentials['user_login'] = $_POST['log']; |
|
| 32 | - if ( ! empty($_POST['pwd']) ) |
|
| 33 | - $credentials['user_password'] = $_POST['pwd']; |
|
| 34 | - if ( ! empty($_POST['rememberme']) ) |
|
| 35 | - $credentials['remember'] = $_POST['rememberme']; |
|
| 30 | + if ( ! empty($_POST['log']) ) { |
|
| 31 | + $credentials['user_login'] = $_POST['log']; |
|
| 32 | + } |
|
| 33 | + if ( ! empty($_POST['pwd']) ) { |
|
| 34 | + $credentials['user_password'] = $_POST['pwd']; |
|
| 35 | + } |
|
| 36 | + if ( ! empty($_POST['rememberme']) ) { |
|
| 37 | + $credentials['remember'] = $_POST['rememberme']; |
|
| 38 | + } |
|
| 36 | 39 | } |
| 37 | 40 | |
| 38 | - if ( !empty($credentials['remember']) ) |
|
| 39 | - $credentials['remember'] = true; |
|
| 40 | - else |
|
| 41 | - $credentials['remember'] = false; |
|
| 41 | + if ( !empty($credentials['remember']) ) { |
|
| 42 | + $credentials['remember'] = true; |
|
| 43 | + } else { |
|
| 44 | + $credentials['remember'] = false; |
|
| 45 | + } |
|
| 42 | 46 | |
| 43 | 47 | /** |
| 44 | 48 | * Fires before the user is authenticated. |
@@ -55,8 +59,9 @@ discard block |
||
| 55 | 59 | */ |
| 56 | 60 | do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
| 57 | 61 | |
| 58 | - if ( '' === $secure_cookie ) |
|
| 59 | - $secure_cookie = is_ssl(); |
|
| 62 | + if ( '' === $secure_cookie ) { |
|
| 63 | + $secure_cookie = is_ssl(); |
|
| 64 | + } |
|
| 60 | 65 | |
| 61 | 66 | /** |
| 62 | 67 | * Filter whether to use a secure sign-on cookie. |
@@ -119,24 +124,28 @@ discard block |
||
| 119 | 124 | } |
| 120 | 125 | |
| 121 | 126 | if ( empty($username) || empty($password) ) { |
| 122 | - if ( is_wp_error( $user ) ) |
|
| 123 | - return $user; |
|
| 127 | + if ( is_wp_error( $user ) ) { |
|
| 128 | + return $user; |
|
| 129 | + } |
|
| 124 | 130 | |
| 125 | 131 | $error = new WP_Error(); |
| 126 | 132 | |
| 127 | - if ( empty($username) ) |
|
| 128 | - $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
| 133 | + if ( empty($username) ) { |
|
| 134 | + $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
| 135 | + } |
|
| 129 | 136 | |
| 130 | - if ( empty($password) ) |
|
| 131 | - $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
| 137 | + if ( empty($password) ) { |
|
| 138 | + $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
| 139 | + } |
|
| 132 | 140 | |
| 133 | 141 | return $error; |
| 134 | 142 | } |
| 135 | 143 | |
| 136 | 144 | $user = get_user_by('login', $username); |
| 137 | 145 | |
| 138 | - if ( !$user ) |
|
| 139 | - return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>' ), wp_lostpassword_url() ) ); |
|
| 146 | + if ( !$user ) { |
|
| 147 | + return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>' ), wp_lostpassword_url() ) ); |
|
| 148 | + } |
|
| 140 | 149 | |
| 141 | 150 | /** |
| 142 | 151 | * Filter whether the given user can be authenticated with the provided $password. |
@@ -148,12 +157,14 @@ discard block |
||
| 148 | 157 | * @param string $password Password to check against the user. |
| 149 | 158 | */ |
| 150 | 159 | $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
| 151 | - if ( is_wp_error($user) ) |
|
| 152 | - return $user; |
|
| 160 | + if ( is_wp_error($user) ) { |
|
| 161 | + return $user; |
|
| 162 | + } |
|
| 153 | 163 | |
| 154 | - if ( !wp_check_password($password, $user->user_pass, $user->ID) ) |
|
| 155 | - return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>' ), |
|
| 164 | + if ( !wp_check_password($password, $user->user_pass, $user->ID) ) { |
|
| 165 | + return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>' ), |
|
| 156 | 166 | $username, wp_lostpassword_url() ) ); |
| 167 | + } |
|
| 157 | 168 | |
| 158 | 169 | return $user; |
| 159 | 170 | } |
@@ -177,18 +188,21 @@ discard block |
||
| 177 | 188 | |
| 178 | 189 | if ( empty($username) && empty($password) ) { |
| 179 | 190 | $user_id = wp_validate_auth_cookie(); |
| 180 | - if ( $user_id ) |
|
| 181 | - return new WP_User($user_id); |
|
| 191 | + if ( $user_id ) { |
|
| 192 | + return new WP_User($user_id); |
|
| 193 | + } |
|
| 182 | 194 | |
| 183 | 195 | global $auth_secure_cookie; |
| 184 | 196 | |
| 185 | - if ( $auth_secure_cookie ) |
|
| 186 | - $auth_cookie = SECURE_AUTH_COOKIE; |
|
| 187 | - else |
|
| 188 | - $auth_cookie = AUTH_COOKIE; |
|
| 197 | + if ( $auth_secure_cookie ) { |
|
| 198 | + $auth_cookie = SECURE_AUTH_COOKIE; |
|
| 199 | + } else { |
|
| 200 | + $auth_cookie = AUTH_COOKIE; |
|
| 201 | + } |
|
| 189 | 202 | |
| 190 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
| 191 | - return new WP_Error('expired_session', __('Please log in again.')); |
|
| 203 | + if ( !empty($_COOKIE[$auth_cookie]) ) { |
|
| 204 | + return new WP_Error('expired_session', __('Please log in again.')); |
|
| 205 | + } |
|
| 192 | 206 | |
| 193 | 207 | // If the cookie is not set, be silent. |
| 194 | 208 | } |
@@ -217,8 +231,9 @@ discard block |
||
| 217 | 231 | */ |
| 218 | 232 | $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
| 219 | 233 | |
| 220 | - if ( $spammed ) |
|
| 221 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 234 | + if ( $spammed ) { |
|
| 235 | + return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 236 | + } |
|
| 222 | 237 | } |
| 223 | 238 | return $user; |
| 224 | 239 | } |
@@ -303,8 +318,9 @@ discard block |
||
| 303 | 318 | global $wpdb; |
| 304 | 319 | |
| 305 | 320 | $count = array(); |
| 306 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
| 307 | - return $count; |
|
| 321 | + if ( empty( $users ) || ! is_array( $users ) ) { |
|
| 322 | + return $count; |
|
| 323 | + } |
|
| 308 | 324 | |
| 309 | 325 | $userlist = implode( ',', array_map( 'absint', $users ) ); |
| 310 | 326 | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
@@ -315,8 +331,9 @@ discard block |
||
| 315 | 331 | } |
| 316 | 332 | |
| 317 | 333 | foreach ( $users as $id ) { |
| 318 | - if ( ! isset( $count[ $id ] ) ) |
|
| 319 | - $count[ $id ] = 0; |
|
| 334 | + if ( ! isset( $count[ $id ] ) ) { |
|
| 335 | + $count[ $id ] = 0; |
|
| 336 | + } |
|
| 320 | 337 | } |
| 321 | 338 | |
| 322 | 339 | return $count; |
@@ -334,8 +351,9 @@ discard block |
||
| 334 | 351 | * @return int The current user's ID |
| 335 | 352 | */ |
| 336 | 353 | function get_current_user_id() { |
| 337 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
| 338 | - return 0; |
|
| 354 | + if ( ! function_exists( 'wp_get_current_user' ) ) { |
|
| 355 | + return 0; |
|
| 356 | + } |
|
| 339 | 357 | $user = wp_get_current_user(); |
| 340 | 358 | return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
| 341 | 359 | } |
@@ -362,22 +380,28 @@ discard block |
||
| 362 | 380 | function get_user_option( $option, $user = 0, $deprecated = '' ) { |
| 363 | 381 | global $wpdb; |
| 364 | 382 | |
| 365 | - if ( !empty( $deprecated ) ) |
|
| 366 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 383 | + if ( !empty( $deprecated ) ) { |
|
| 384 | + _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 385 | + } |
|
| 367 | 386 | |
| 368 | - if ( empty( $user ) ) |
|
| 369 | - $user = get_current_user_id(); |
|
| 387 | + if ( empty( $user ) ) { |
|
| 388 | + $user = get_current_user_id(); |
|
| 389 | + } |
|
| 370 | 390 | |
| 371 | - if ( ! $user = get_userdata( $user ) ) |
|
| 372 | - return false; |
|
| 391 | + if ( ! $user = get_userdata( $user ) ) { |
|
| 392 | + return false; |
|
| 393 | + } |
|
| 373 | 394 | |
| 374 | 395 | $prefix = $wpdb->get_blog_prefix(); |
| 375 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
| 396 | + if ( $user->has_prop( $prefix . $option ) ) { |
|
| 397 | + // Blog specific |
|
| 376 | 398 | $result = $user->get( $prefix . $option ); |
| 377 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
| 399 | + } elseif ( $user->has_prop( $option ) ) { |
|
| 400 | + // User specific and cross-blog |
|
| 378 | 401 | $result = $user->get( $option ); |
| 379 | - else |
|
| 380 | - $result = false; |
|
| 402 | + } else { |
|
| 403 | + $result = false; |
|
| 404 | + } |
|
| 381 | 405 | |
| 382 | 406 | /** |
| 383 | 407 | * Filter a specific user option value. |
@@ -417,8 +441,9 @@ discard block |
||
| 417 | 441 | function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
| 418 | 442 | global $wpdb; |
| 419 | 443 | |
| 420 | - if ( !$global ) |
|
| 421 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 444 | + if ( !$global ) { |
|
| 445 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 446 | + } |
|
| 422 | 447 | |
| 423 | 448 | return update_user_meta( $user_id, $option_name, $newvalue ); |
| 424 | 449 | } |
@@ -443,8 +468,9 @@ discard block |
||
| 443 | 468 | function delete_user_option( $user_id, $option_name, $global = false ) { |
| 444 | 469 | global $wpdb; |
| 445 | 470 | |
| 446 | - if ( !$global ) |
|
| 447 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 471 | + if ( !$global ) { |
|
| 472 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 473 | + } |
|
| 448 | 474 | return delete_user_meta( $user_id, $option_name ); |
| 449 | 475 | } |
| 450 | 476 | |
@@ -634,8 +660,9 @@ discard block |
||
| 634 | 660 | $this->query_fields = "$wpdb->users.ID"; |
| 635 | 661 | } |
| 636 | 662 | |
| 637 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
| 638 | - $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
| 663 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
| 664 | + $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
| 665 | + } |
|
| 639 | 666 | |
| 640 | 667 | $this->query_from = "FROM $wpdb->users"; |
| 641 | 668 | $this->query_where = "WHERE 1=1"; |
@@ -763,42 +790,48 @@ discard block |
||
| 763 | 790 | |
| 764 | 791 | // limit |
| 765 | 792 | if ( isset( $qv['number'] ) && $qv['number'] ) { |
| 766 | - if ( $qv['offset'] ) |
|
| 767 | - $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); |
|
| 768 | - else |
|
| 769 | - $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']); |
|
| 793 | + if ( $qv['offset'] ) { |
|
| 794 | + $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); |
|
| 795 | + } else { |
|
| 796 | + $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']); |
|
| 797 | + } |
|
| 770 | 798 | } |
| 771 | 799 | |
| 772 | 800 | $search = ''; |
| 773 | - if ( isset( $qv['search'] ) ) |
|
| 774 | - $search = trim( $qv['search'] ); |
|
| 801 | + if ( isset( $qv['search'] ) ) { |
|
| 802 | + $search = trim( $qv['search'] ); |
|
| 803 | + } |
|
| 775 | 804 | |
| 776 | 805 | if ( $search ) { |
| 777 | 806 | $leading_wild = ( ltrim($search, '*') != $search ); |
| 778 | 807 | $trailing_wild = ( rtrim($search, '*') != $search ); |
| 779 | - if ( $leading_wild && $trailing_wild ) |
|
| 780 | - $wild = 'both'; |
|
| 781 | - elseif ( $leading_wild ) |
|
| 782 | - $wild = 'leading'; |
|
| 783 | - elseif ( $trailing_wild ) |
|
| 784 | - $wild = 'trailing'; |
|
| 785 | - else |
|
| 786 | - $wild = false; |
|
| 787 | - if ( $wild ) |
|
| 788 | - $search = trim($search, '*'); |
|
| 808 | + if ( $leading_wild && $trailing_wild ) { |
|
| 809 | + $wild = 'both'; |
|
| 810 | + } elseif ( $leading_wild ) { |
|
| 811 | + $wild = 'leading'; |
|
| 812 | + } elseif ( $trailing_wild ) { |
|
| 813 | + $wild = 'trailing'; |
|
| 814 | + } else { |
|
| 815 | + $wild = false; |
|
| 816 | + } |
|
| 817 | + if ( $wild ) { |
|
| 818 | + $search = trim($search, '*'); |
|
| 819 | + } |
|
| 789 | 820 | |
| 790 | 821 | $search_columns = array(); |
| 791 | - if ( $qv['search_columns'] ) |
|
| 792 | - $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
| 822 | + if ( $qv['search_columns'] ) { |
|
| 823 | + $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
| 824 | + } |
|
| 793 | 825 | if ( ! $search_columns ) { |
| 794 | - if ( false !== strpos( $search, '@') ) |
|
| 795 | - $search_columns = array('user_email'); |
|
| 796 | - elseif ( is_numeric($search) ) |
|
| 797 | - $search_columns = array('user_login', 'ID'); |
|
| 798 | - elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) |
|
| 799 | - $search_columns = array('user_url'); |
|
| 800 | - else |
|
| 801 | - $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
|
| 826 | + if ( false !== strpos( $search, '@') ) { |
|
| 827 | + $search_columns = array('user_email'); |
|
| 828 | + } elseif ( is_numeric($search) ) { |
|
| 829 | + $search_columns = array('user_login', 'ID'); |
|
| 830 | + } elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) { |
|
| 831 | + $search_columns = array('user_url'); |
|
| 832 | + } else { |
|
| 833 | + $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
|
| 834 | + } |
|
| 802 | 835 | } |
| 803 | 836 | |
| 804 | 837 | /** |
@@ -877,18 +910,21 @@ discard block |
||
| 877 | 910 | * |
| 878 | 911 | * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. |
| 879 | 912 | */ |
| 880 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
| 881 | - $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
| 913 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
| 914 | + $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
| 915 | + } |
|
| 882 | 916 | |
| 883 | - if ( !$this->results ) |
|
| 884 | - return; |
|
| 917 | + if ( !$this->results ) { |
|
| 918 | + return; |
|
| 919 | + } |
|
| 885 | 920 | |
| 886 | 921 | if ( 'all_with_meta' == $qv['fields'] ) { |
| 887 | 922 | cache_users( $this->results ); |
| 888 | 923 | |
| 889 | 924 | $r = array(); |
| 890 | - foreach ( $this->results as $userid ) |
|
| 891 | - $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
| 925 | + foreach ( $this->results as $userid ) { |
|
| 926 | + $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
| 927 | + } |
|
| 892 | 928 | |
| 893 | 929 | $this->results = $r; |
| 894 | 930 | } elseif ( 'all' == $qv['fields'] ) { |
@@ -908,8 +944,9 @@ discard block |
||
| 908 | 944 | * @return mixed |
| 909 | 945 | */ |
| 910 | 946 | public function get( $query_var ) { |
| 911 | - if ( isset( $this->query_vars[$query_var] ) ) |
|
| 912 | - return $this->query_vars[$query_var]; |
|
| 947 | + if ( isset( $this->query_vars[$query_var] ) ) { |
|
| 948 | + return $this->query_vars[$query_var]; |
|
| 949 | + } |
|
| 913 | 950 | |
| 914 | 951 | return null; |
| 915 | 952 | } |
@@ -1175,12 +1212,14 @@ discard block |
||
| 1175 | 1212 | $user_id = (int) $user_id; |
| 1176 | 1213 | |
| 1177 | 1214 | // Logged out users can't have blogs |
| 1178 | - if ( empty( $user_id ) ) |
|
| 1179 | - return array(); |
|
| 1215 | + if ( empty( $user_id ) ) { |
|
| 1216 | + return array(); |
|
| 1217 | + } |
|
| 1180 | 1218 | |
| 1181 | 1219 | $keys = get_user_meta( $user_id ); |
| 1182 | - if ( empty( $keys ) ) |
|
| 1183 | - return array(); |
|
| 1220 | + if ( empty( $keys ) ) { |
|
| 1221 | + return array(); |
|
| 1222 | + } |
|
| 1184 | 1223 | |
| 1185 | 1224 | if ( ! is_multisite() ) { |
| 1186 | 1225 | $blog_id = get_current_blog_id(); |
@@ -1221,13 +1260,16 @@ discard block |
||
| 1221 | 1260 | $keys = array_keys( $keys ); |
| 1222 | 1261 | |
| 1223 | 1262 | foreach ( $keys as $key ) { |
| 1224 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
| 1225 | - continue; |
|
| 1226 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
| 1227 | - continue; |
|
| 1263 | + if ( 'capabilities' !== substr( $key, -12 ) ) { |
|
| 1264 | + continue; |
|
| 1265 | + } |
|
| 1266 | + if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { |
|
| 1267 | + continue; |
|
| 1268 | + } |
|
| 1228 | 1269 | $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
| 1229 | - if ( ! is_numeric( $blog_id ) ) |
|
| 1230 | - continue; |
|
| 1270 | + if ( ! is_numeric( $blog_id ) ) { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1231 | 1273 | |
| 1232 | 1274 | $blog_id = (int) $blog_id; |
| 1233 | 1275 | $blog = get_blog_details( $blog_id ); |
@@ -1273,11 +1315,13 @@ discard block |
||
| 1273 | 1315 | $user_id = (int) $user_id; |
| 1274 | 1316 | $blog_id = (int) $blog_id; |
| 1275 | 1317 | |
| 1276 | - if ( empty( $user_id ) ) |
|
| 1277 | - $user_id = get_current_user_id(); |
|
| 1318 | + if ( empty( $user_id ) ) { |
|
| 1319 | + $user_id = get_current_user_id(); |
|
| 1320 | + } |
|
| 1278 | 1321 | |
| 1279 | - if ( empty( $blog_id ) ) |
|
| 1280 | - $blog_id = get_current_blog_id(); |
|
| 1322 | + if ( empty( $blog_id ) ) { |
|
| 1323 | + $blog_id = get_current_blog_id(); |
|
| 1324 | + } |
|
| 1281 | 1325 | |
| 1282 | 1326 | $blogs = get_blogs_of_user( $user_id ); |
| 1283 | 1327 | return array_key_exists( $blog_id, $blogs ); |
@@ -1414,8 +1458,9 @@ discard block |
||
| 1414 | 1458 | |
| 1415 | 1459 | foreach ( $users_of_blog as $caps_meta ) { |
| 1416 | 1460 | $b_roles = maybe_unserialize($caps_meta); |
| 1417 | - if ( ! is_array( $b_roles ) ) |
|
| 1418 | - continue; |
|
| 1461 | + if ( ! is_array( $b_roles ) ) { |
|
| 1462 | + continue; |
|
| 1463 | + } |
|
| 1419 | 1464 | foreach ( $b_roles as $b_role => $val ) { |
| 1420 | 1465 | if ( isset($avail_roles[$b_role]) ) { |
| 1421 | 1466 | $avail_roles[$b_role]++; |
@@ -1456,8 +1501,9 @@ discard block |
||
| 1456 | 1501 | function setup_userdata($for_user_id = '') { |
| 1457 | 1502 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
| 1458 | 1503 | |
| 1459 | - if ( '' == $for_user_id ) |
|
| 1460 | - $for_user_id = get_current_user_id(); |
|
| 1504 | + if ( '' == $for_user_id ) { |
|
| 1505 | + $for_user_id = get_current_user_id(); |
|
| 1506 | + } |
|
| 1461 | 1507 | $user = get_userdata( $for_user_id ); |
| 1462 | 1508 | |
| 1463 | 1509 | if ( ! $user ) { |
@@ -1628,14 +1674,17 @@ discard block |
||
| 1628 | 1674 | */ |
| 1629 | 1675 | function sanitize_user_field($field, $value, $user_id, $context) { |
| 1630 | 1676 | $int_fields = array('ID'); |
| 1631 | - if ( in_array($field, $int_fields) ) |
|
| 1632 | - $value = (int) $value; |
|
| 1677 | + if ( in_array($field, $int_fields) ) { |
|
| 1678 | + $value = (int) $value; |
|
| 1679 | + } |
|
| 1633 | 1680 | |
| 1634 | - if ( 'raw' == $context ) |
|
| 1635 | - return $value; |
|
| 1681 | + if ( 'raw' == $context ) { |
|
| 1682 | + return $value; |
|
| 1683 | + } |
|
| 1636 | 1684 | |
| 1637 | - if ( !is_string($value) && !is_numeric($value) ) |
|
| 1638 | - return $value; |
|
| 1685 | + if ( !is_string($value) && !is_numeric($value) ) { |
|
| 1686 | + return $value; |
|
| 1687 | + } |
|
| 1639 | 1688 | |
| 1640 | 1689 | $prefixed = false !== strpos( $field, 'user_' ); |
| 1641 | 1690 | |
@@ -1660,10 +1709,13 @@ discard block |
||
| 1660 | 1709 | $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
| 1661 | 1710 | } |
| 1662 | 1711 | |
| 1663 | - if ( 'description' == $field ) |
|
| 1664 | - $value = esc_html( $value ); // textarea_escaped? |
|
| 1665 | - else |
|
| 1666 | - $value = esc_attr($value); |
|
| 1712 | + if ( 'description' == $field ) { |
|
| 1713 | + $value = esc_html( $value ); |
|
| 1714 | + } |
|
| 1715 | + // textarea_escaped? |
|
| 1716 | + else { |
|
| 1717 | + $value = esc_attr($value); |
|
| 1718 | + } |
|
| 1667 | 1719 | } elseif ( 'db' == $context ) { |
| 1668 | 1720 | if ( $prefixed ) { |
| 1669 | 1721 | /** This filter is documented in wp-includes/post.php */ |
@@ -1706,8 +1758,9 @@ discard block |
||
| 1706 | 1758 | } |
| 1707 | 1759 | } |
| 1708 | 1760 | |
| 1709 | - if ( 'user_url' == $field ) |
|
| 1710 | - $value = esc_url($value); |
|
| 1761 | + if ( 'user_url' == $field ) { |
|
| 1762 | + $value = esc_url($value); |
|
| 1763 | + } |
|
| 1711 | 1764 | |
| 1712 | 1765 | if ( 'attribute' == $context ) { |
| 1713 | 1766 | $value = esc_attr( $value ); |
@@ -1739,11 +1792,13 @@ discard block |
||
| 1739 | 1792 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
| 1740 | 1793 | */ |
| 1741 | 1794 | function clean_user_cache( $user ) { |
| 1742 | - if ( is_numeric( $user ) ) |
|
| 1743 | - $user = new WP_User( $user ); |
|
| 1795 | + if ( is_numeric( $user ) ) { |
|
| 1796 | + $user = new WP_User( $user ); |
|
| 1797 | + } |
|
| 1744 | 1798 | |
| 1745 | - if ( ! $user->exists() ) |
|
| 1746 | - return; |
|
| 1799 | + if ( ! $user->exists() ) { |
|
| 1800 | + return; |
|
| 1801 | + } |
|
| 1747 | 1802 | |
| 1748 | 1803 | wp_cache_delete( $user->ID, 'users' ); |
| 1749 | 1804 | wp_cache_delete( $user->user_login, 'userlogins' ); |
@@ -2447,15 +2502,18 @@ discard block |
||
| 2447 | 2502 | |
| 2448 | 2503 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
| 2449 | 2504 | |
| 2450 | - if ( empty( $key ) || !is_string( $key ) ) |
|
| 2451 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2505 | + if ( empty( $key ) || !is_string( $key ) ) { |
|
| 2506 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2507 | + } |
|
| 2452 | 2508 | |
| 2453 | - if ( empty($login) || !is_string($login) ) |
|
| 2454 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2509 | + if ( empty($login) || !is_string($login) ) { |
|
| 2510 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2511 | + } |
|
| 2455 | 2512 | |
| 2456 | 2513 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
| 2457 | - if ( ! $row ) |
|
| 2458 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2514 | + if ( ! $row ) { |
|
| 2515 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2516 | + } |
|
| 2459 | 2517 | |
| 2460 | 2518 | if ( empty( $wp_hasher ) ) { |
| 2461 | 2519 | require_once ABSPATH . WPINC . '/class-phpass.php'; |
@@ -2607,8 +2665,9 @@ discard block |
||
| 2607 | 2665 | */ |
| 2608 | 2666 | $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
| 2609 | 2667 | |
| 2610 | - if ( $errors->get_error_code() ) |
|
| 2611 | - return $errors; |
|
| 2668 | + if ( $errors->get_error_code() ) { |
|
| 2669 | + return $errors; |
|
| 2670 | + } |
|
| 2612 | 2671 | |
| 2613 | 2672 | $user_pass = wp_generate_password( 12, false ); |
| 2614 | 2673 | $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @param array $args Display arguments. See {@see WP_Widget::widget()} for information |
| 302 | 302 | * on accepted arguments. |
| 303 | - * @param int|array $widget_args { |
|
| 303 | + * @param integer $widget_args { |
|
| 304 | 304 | * Optional. Internal order number of the widget instance, or array of multi-widget arguments. |
| 305 | 305 | * Default 1. |
| 306 | 306 | * |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * @since 2.8.0 |
| 441 | 441 | * @access public |
| 442 | 442 | * |
| 443 | - * @param int|array $widget_args Widget instance number or array of widget arguments. |
|
| 443 | + * @param integer $widget_args Widget instance number or array of widget arguments. |
|
| 444 | 444 | * @return string|null |
| 445 | 445 | */ |
| 446 | 446 | public function form_callback( $widget_args = 1 ) { |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | * |
| 1132 | 1132 | * @global array $wp_registered_widget_controls |
| 1133 | 1133 | * |
| 1134 | - * @param int|string $id |
|
| 1134 | + * @param boolean|string $id |
|
| 1135 | 1135 | * @param string $name |
| 1136 | 1136 | * @param callable $form_callback |
| 1137 | 1137 | * @param array $options |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | * @global array $wp_registered_sidebars |
| 1189 | 1189 | * @global array $wp_registered_widgets |
| 1190 | 1190 | * |
| 1191 | - * @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
|
| 1191 | + * @param integer $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
|
| 1192 | 1192 | * @return bool True, if widget sidebar was found and called. False if not found or not called. |
| 1193 | 1193 | */ |
| 1194 | 1194 | function dynamic_sidebar($index = 1) { |
@@ -1425,7 +1425,7 @@ discard block |
||
| 1425 | 1425 | * |
| 1426 | 1426 | * @since 2.8.0 |
| 1427 | 1427 | * |
| 1428 | - * @param string|int $index Sidebar name, id or number to check. |
|
| 1428 | + * @param string $index Sidebar name, id or number to check. |
|
| 1429 | 1429 | * @return bool true if the sidebar is in use, false otherwise. |
| 1430 | 1430 | */ |
| 1431 | 1431 | function is_active_sidebar( $index ) { |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * API for creating dynamic sidebar without hardcoding functionality into |
|
| 4 | - * themes. Includes both internal WordPress routines and theme use routines. |
|
| 5 | - * |
|
| 6 | - * This functionality was found in a plugin before WordPress 2.2 release which |
|
| 7 | - * included it in the core from that point on. |
|
| 8 | - * |
|
| 9 | - * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
|
| 10 | - * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
|
| 11 | - * |
|
| 12 | - * @package WordPress |
|
| 13 | - * @subpackage Widgets |
|
| 14 | - */ |
|
| 3 | + * API for creating dynamic sidebar without hardcoding functionality into |
|
| 4 | + * themes. Includes both internal WordPress routines and theme use routines. |
|
| 5 | + * |
|
| 6 | + * This functionality was found in a plugin before WordPress 2.2 release which |
|
| 7 | + * included it in the core from that point on. |
|
| 8 | + * |
|
| 9 | + * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
|
| 10 | + * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
|
| 11 | + * |
|
| 12 | + * @package WordPress |
|
| 13 | + * @subpackage Widgets |
|
| 14 | + */ |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * This class must be extended for each widget and WP_Widget::widget(), WP_Widget::update() |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * before_widget, and after_widget. |
| 104 | 104 | * @param array $instance The settings for the particular instance of the widget. |
| 105 | 105 | */ |
| 106 | - public function widget( $args, $instance ) { |
|
| 106 | + public function widget($args, $instance) { |
|
| 107 | 107 | die('function WP_Widget::widget() must be over-ridden in a sub-class.'); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param array $old_instance Old settings for this instance. |
| 123 | 123 | * @return array Settings to save or bool false to cancel saving. |
| 124 | 124 | */ |
| 125 | - public function update( $new_instance, $old_instance ) { |
|
| 125 | + public function update($new_instance, $old_instance) { |
|
| 126 | 126 | return $new_instance; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @return string Default return is 'noform'. |
| 137 | 137 | */ |
| 138 | 138 | public function form($instance) { |
| 139 | - echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>'; |
|
| 139 | + echo '<p class="no-options-widget">'.__('There are no options for this widget.').'</p>'; |
|
| 140 | 140 | return 'noform'; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -156,12 +156,12 @@ discard block |
||
| 156 | 156 | * @param array $control_options Optional. Widget control options. See {@see wp_register_widget_control()} |
| 157 | 157 | * for information on accepted arguments. Default empty array. |
| 158 | 158 | */ |
| 159 | - public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { |
|
| 160 | - $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base); |
|
| 159 | + public function __construct($id_base, $name, $widget_options = array(), $control_options = array()) { |
|
| 160 | + $this->id_base = empty($id_base) ? preg_replace('/(wp_)?widget_/', '', strtolower(get_class($this))) : strtolower($id_base); |
|
| 161 | 161 | $this->name = $name; |
| 162 | - $this->option_name = 'widget_' . $this->id_base; |
|
| 163 | - $this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) ); |
|
| 164 | - $this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) ); |
|
| 162 | + $this->option_name = 'widget_'.$this->id_base; |
|
| 163 | + $this->widget_options = wp_parse_args($widget_options, array('classname' => $this->option_name)); |
|
| 164 | + $this->control_options = wp_parse_args($control_options, array('id_base' => $this->id_base)); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * @param array $widget_options |
| 173 | 173 | * @param array $control_options |
| 174 | 174 | */ |
| 175 | - public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) { |
|
| 176 | - _deprecated_constructor( 'WP_Widget', '4.3.0' ); |
|
| 177 | - WP_Widget::__construct( $id_base, $name, $widget_options, $control_options ); |
|
| 175 | + public function WP_Widget($id_base, $name, $widget_options = array(), $control_options = array()) { |
|
| 176 | + _deprecated_constructor('WP_Widget', '4.3.0'); |
|
| 177 | + WP_Widget::__construct($id_base, $name, $widget_options, $control_options); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @return string Name attribute for $field_name |
| 187 | 187 | */ |
| 188 | 188 | public function get_field_name($field_name) { |
| 189 | - return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; |
|
| 189 | + return 'widget-'.$this->id_base.'['.$this->number.']['.$field_name.']'; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @param string $field_name Field name. |
| 202 | 202 | * @return string ID attribute for `$field_name`. |
| 203 | 203 | */ |
| 204 | - public function get_field_id( $field_name ) { |
|
| 205 | - return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; |
|
| 204 | + public function get_field_id($field_name) { |
|
| 205 | + return 'widget-'.$this->id_base.'-'.$this->number.'-'.$field_name; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -216,23 +216,23 @@ discard block |
||
| 216 | 216 | $empty = true; |
| 217 | 217 | |
| 218 | 218 | // When $settings is an array-like object, get an intrinsic array for use with array_keys(). |
| 219 | - if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { |
|
| 219 | + if ($settings instanceof ArrayObject || $settings instanceof ArrayIterator) { |
|
| 220 | 220 | $settings = $settings->getArrayCopy(); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( is_array( $settings ) ) { |
|
| 224 | - foreach ( array_keys( $settings ) as $number ) { |
|
| 225 | - if ( is_numeric( $number ) ) { |
|
| 226 | - $this->_set( $number ); |
|
| 227 | - $this->_register_one( $number ); |
|
| 223 | + if (is_array($settings)) { |
|
| 224 | + foreach (array_keys($settings) as $number) { |
|
| 225 | + if (is_numeric($number)) { |
|
| 226 | + $this->_set($number); |
|
| 227 | + $this->_register_one($number); |
|
| 228 | 228 | $empty = false; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if ( $empty ) { |
|
| 233 | + if ($empty) { |
|
| 234 | 234 | // If there are none, we register the widget's existence with a generic template. |
| 235 | - $this->_set( 1 ); |
|
| 235 | + $this->_set(1); |
|
| 236 | 236 | $this->_register_one(); |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function _set($number) { |
| 250 | 250 | $this->number = $number; |
| 251 | - $this->id = $this->id_base . '-' . $number; |
|
| 251 | + $this->id = $this->id_base.'-'.$number; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public function is_preview() { |
| 289 | 289 | global $wp_customize; |
| 290 | - return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ; |
|
| 290 | + return (isset($wp_customize) && $wp_customize->is_preview()); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -307,17 +307,17 @@ discard block |
||
| 307 | 307 | * @type int $number Number increment used for multiples of the same widget. |
| 308 | 308 | * } |
| 309 | 309 | */ |
| 310 | - public function display_callback( $args, $widget_args = 1 ) { |
|
| 311 | - if ( is_numeric( $widget_args ) ) { |
|
| 312 | - $widget_args = array( 'number' => $widget_args ); |
|
| 310 | + public function display_callback($args, $widget_args = 1) { |
|
| 311 | + if (is_numeric($widget_args)) { |
|
| 312 | + $widget_args = array('number' => $widget_args); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
|
| 316 | - $this->_set( $widget_args['number'] ); |
|
| 315 | + $widget_args = wp_parse_args($widget_args, array('number' => -1)); |
|
| 316 | + $this->_set($widget_args['number']); |
|
| 317 | 317 | $instances = $this->get_settings(); |
| 318 | 318 | |
| 319 | - if ( isset( $instances[ $this->number ] ) ) { |
|
| 320 | - $instance = $instances[ $this->number ]; |
|
| 319 | + if (isset($instances[$this->number])) { |
|
| 320 | + $instance = $instances[$this->number]; |
|
| 321 | 321 | |
| 322 | 322 | /** |
| 323 | 323 | * Filter the settings for a particular widget instance. |
@@ -330,21 +330,21 @@ discard block |
||
| 330 | 330 | * @param WP_Widget $this The current widget instance. |
| 331 | 331 | * @param array $args An array of default widget arguments. |
| 332 | 332 | */ |
| 333 | - $instance = apply_filters( 'widget_display_callback', $instance, $this, $args ); |
|
| 333 | + $instance = apply_filters('widget_display_callback', $instance, $this, $args); |
|
| 334 | 334 | |
| 335 | - if ( false === $instance ) { |
|
| 335 | + if (false === $instance) { |
|
| 336 | 336 | return; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
| 340 | - if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
|
| 341 | - wp_suspend_cache_addition( true ); |
|
| 340 | + if ($this->is_preview() && ! $was_cache_addition_suspended) { |
|
| 341 | + wp_suspend_cache_addition(true); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $this->widget( $args, $instance ); |
|
| 344 | + $this->widget($args, $instance); |
|
| 345 | 345 | |
| 346 | - if ( $this->is_preview() ) { |
|
| 347 | - wp_suspend_cache_addition( $was_cache_addition_suspended ); |
|
| 346 | + if ($this->is_preview()) { |
|
| 347 | + wp_suspend_cache_addition($was_cache_addition_suspended); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | } |
@@ -359,53 +359,53 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | * @param int $deprecated Not used. |
| 361 | 361 | */ |
| 362 | - public function update_callback( $deprecated = 1 ) { |
|
| 362 | + public function update_callback($deprecated = 1) { |
|
| 363 | 363 | global $wp_registered_widgets; |
| 364 | 364 | |
| 365 | 365 | $all_instances = $this->get_settings(); |
| 366 | 366 | |
| 367 | 367 | // We need to update the data |
| 368 | - if ( $this->updated ) |
|
| 368 | + if ($this->updated) |
|
| 369 | 369 | return; |
| 370 | 370 | |
| 371 | - if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { |
|
| 371 | + if (isset($_POST['delete_widget']) && $_POST['delete_widget']) { |
|
| 372 | 372 | // Delete the settings for this instance of the widget |
| 373 | - if ( isset($_POST['the-widget-id']) ) |
|
| 373 | + if (isset($_POST['the-widget-id'])) |
|
| 374 | 374 | $del_id = $_POST['the-widget-id']; |
| 375 | 375 | else |
| 376 | 376 | return; |
| 377 | 377 | |
| 378 | - if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { |
|
| 378 | + if (isset($wp_registered_widgets[$del_id]['params'][0]['number'])) { |
|
| 379 | 379 | $number = $wp_registered_widgets[$del_id]['params'][0]['number']; |
| 380 | 380 | |
| 381 | - if ( $this->id_base . '-' . $number == $del_id ) |
|
| 381 | + if ($this->id_base.'-'.$number == $del_id) |
|
| 382 | 382 | unset($all_instances[$number]); |
| 383 | 383 | } |
| 384 | 384 | } else { |
| 385 | - if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) { |
|
| 386 | - $settings = $_POST['widget-' . $this->id_base]; |
|
| 387 | - } elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) { |
|
| 385 | + if (isset($_POST['widget-'.$this->id_base]) && is_array($_POST['widget-'.$this->id_base])) { |
|
| 386 | + $settings = $_POST['widget-'.$this->id_base]; |
|
| 387 | + } elseif (isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base) { |
|
| 388 | 388 | $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; |
| 389 | - $settings = array( $num => array() ); |
|
| 389 | + $settings = array($num => array()); |
|
| 390 | 390 | } else { |
| 391 | 391 | return; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - foreach ( $settings as $number => $new_instance ) { |
|
| 394 | + foreach ($settings as $number => $new_instance) { |
|
| 395 | 395 | $new_instance = stripslashes_deep($new_instance); |
| 396 | 396 | $this->_set($number); |
| 397 | 397 | |
| 398 | 398 | $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array(); |
| 399 | 399 | |
| 400 | 400 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
| 401 | - if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
|
| 402 | - wp_suspend_cache_addition( true ); |
|
| 401 | + if ($this->is_preview() && ! $was_cache_addition_suspended) { |
|
| 402 | + wp_suspend_cache_addition(true); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - $instance = $this->update( $new_instance, $old_instance ); |
|
| 405 | + $instance = $this->update($new_instance, $old_instance); |
|
| 406 | 406 | |
| 407 | - if ( $this->is_preview() ) { |
|
| 408 | - wp_suspend_cache_addition( $was_cache_addition_suspended ); |
|
| 407 | + if ($this->is_preview()) { |
|
| 408 | + wp_suspend_cache_addition($was_cache_addition_suspended); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | * @param array $old_instance Array of old widget settings. |
| 422 | 422 | * @param WP_Widget $this The current widget instance. |
| 423 | 423 | */ |
| 424 | - $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); |
|
| 425 | - if ( false !== $instance ) { |
|
| 424 | + $instance = apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $this); |
|
| 425 | + if (false !== $instance) { |
|
| 426 | 426 | $all_instances[$number] = $instance; |
| 427 | 427 | } |
| 428 | 428 | |
@@ -443,11 +443,11 @@ discard block |
||
| 443 | 443 | * @param int|array $widget_args Widget instance number or array of widget arguments. |
| 444 | 444 | * @return string|null |
| 445 | 445 | */ |
| 446 | - public function form_callback( $widget_args = 1 ) { |
|
| 447 | - if ( is_numeric($widget_args) ) |
|
| 448 | - $widget_args = array( 'number' => $widget_args ); |
|
| 446 | + public function form_callback($widget_args = 1) { |
|
| 447 | + if (is_numeric($widget_args)) |
|
| 448 | + $widget_args = array('number' => $widget_args); |
|
| 449 | 449 | |
| 450 | - $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
|
| 450 | + $widget_args = wp_parse_args($widget_args, array('number' => -1)); |
|
| 451 | 451 | $all_instances = $this->get_settings(); |
| 452 | 452 | |
| 453 | 453 | if ( -1 == $widget_args['number'] ) { |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | $instance = array(); |
| 457 | 457 | } else { |
| 458 | 458 | $this->_set($widget_args['number']); |
| 459 | - $instance = $all_instances[ $widget_args['number'] ]; |
|
| 459 | + $instance = $all_instances[$widget_args['number']]; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | * @param array $instance The current widget instance's settings. |
| 470 | 470 | * @param WP_Widget $this The current widget instance. |
| 471 | 471 | */ |
| 472 | - $instance = apply_filters( 'widget_form_callback', $instance, $this ); |
|
| 472 | + $instance = apply_filters('widget_form_callback', $instance, $this); |
|
| 473 | 473 | |
| 474 | 474 | $return = null; |
| 475 | - if ( false !== $instance ) { |
|
| 475 | + if (false !== $instance) { |
|
| 476 | 476 | $return = $this->form($instance); |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * @param null $return Return null if new fields are added. |
| 492 | 492 | * @param array $instance An array of the widget's settings. |
| 493 | 493 | */ |
| 494 | - do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) ); |
|
| 494 | + do_action_ref_array('in_widget_form', array(&$this, &$return, $instance)); |
|
| 495 | 495 | } |
| 496 | 496 | return $return; |
| 497 | 497 | } |
@@ -505,10 +505,10 @@ discard block |
||
| 505 | 505 | * @param integer $number Optional. The unique order number of this widget instance |
| 506 | 506 | * compared to other instances of the same class. Default -1. |
| 507 | 507 | */ |
| 508 | - public function _register_one( $number = -1 ) { |
|
| 509 | - wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); |
|
| 510 | - _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); |
|
| 511 | - _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); |
|
| 508 | + public function _register_one($number = -1) { |
|
| 509 | + wp_register_sidebar_widget($this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array('number' => $number)); |
|
| 510 | + _register_widget_update_callback($this->id_base, $this->_get_update_callback(), $this->control_options, array('number' => -1)); |
|
| 511 | + _register_widget_form_callback($this->id, $this->name, $this->_get_form_callback(), $this->control_options, array('number' => $number)); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -519,9 +519,9 @@ discard block |
||
| 519 | 519 | * |
| 520 | 520 | * @param array $settings Multi-dimensional array of widget instance settings. |
| 521 | 521 | */ |
| 522 | - public function save_settings( $settings ) { |
|
| 522 | + public function save_settings($settings) { |
|
| 523 | 523 | $settings['_multiwidget'] = 1; |
| 524 | - update_option( $this->option_name, $settings ); |
|
| 524 | + update_option($this->option_name, $settings); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -534,22 +534,22 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | public function get_settings() { |
| 536 | 536 | |
| 537 | - $settings = get_option( $this->option_name ); |
|
| 537 | + $settings = get_option($this->option_name); |
|
| 538 | 538 | |
| 539 | - if ( false === $settings && isset( $this->alt_option_name ) ) { |
|
| 540 | - $settings = get_option( $this->alt_option_name ); |
|
| 539 | + if (false === $settings && isset($this->alt_option_name)) { |
|
| 540 | + $settings = get_option($this->alt_option_name); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if ( ! is_array( $settings ) && ! ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) ) { |
|
| 543 | + if ( ! is_array($settings) && ! ($settings instanceof ArrayObject || $settings instanceof ArrayIterator)) { |
|
| 544 | 544 | $settings = array(); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - if ( ! empty( $settings ) && ! isset( $settings['_multiwidget'] ) ) { |
|
| 547 | + if ( ! empty($settings) && ! isset($settings['_multiwidget'])) { |
|
| 548 | 548 | // Old format, convert if single widget. |
| 549 | - $settings = wp_convert_widget_settings( $this->id_base, $this->option_name, $settings ); |
|
| 549 | + $settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - unset( $settings['_multiwidget'], $settings['__i__'] ); |
|
| 552 | + unset($settings['_multiwidget'], $settings['__i__']); |
|
| 553 | 553 | return $settings; |
| 554 | 554 | } |
| 555 | 555 | } |
@@ -568,14 +568,14 @@ discard block |
||
| 568 | 568 | * PHP5 constructor. |
| 569 | 569 | */ |
| 570 | 570 | public function __construct() { |
| 571 | - add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 ); |
|
| 571 | + add_action('widgets_init', array($this, '_register_widgets'), 100); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | 575 | * PHP4 constructor. |
| 576 | 576 | */ |
| 577 | 577 | public function WP_Widget_Factory() { |
| 578 | - _deprecated_constructor( 'WP_Widget_Factory', '4.2.0' ); |
|
| 578 | + _deprecated_constructor('WP_Widget_Factory', '4.2.0'); |
|
| 579 | 579 | self::__construct(); |
| 580 | 580 | } |
| 581 | 581 | |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * |
| 588 | 588 | * @param string $widget_class The name of a {@see WP_Widget} subclass. |
| 589 | 589 | */ |
| 590 | - public function register( $widget_class ) { |
|
| 590 | + public function register($widget_class) { |
|
| 591 | 591 | $this->widgets[$widget_class] = new $widget_class(); |
| 592 | 592 | } |
| 593 | 593 | |
@@ -599,8 +599,8 @@ discard block |
||
| 599 | 599 | * |
| 600 | 600 | * @param string $widget_class The name of a {@see WP_Widget} subclass. |
| 601 | 601 | */ |
| 602 | - public function unregister( $widget_class ) { |
|
| 603 | - unset( $this->widgets[ $widget_class ] ); |
|
| 602 | + public function unregister($widget_class) { |
|
| 603 | + unset($this->widgets[$widget_class]); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -617,9 +617,9 @@ discard block |
||
| 617 | 617 | $registered = array_keys($wp_registered_widgets); |
| 618 | 618 | $registered = array_map('_get_widget_id_base', $registered); |
| 619 | 619 | |
| 620 | - foreach ( $keys as $key ) { |
|
| 620 | + foreach ($keys as $key) { |
|
| 621 | 621 | // don't register new widget if old widget with the same id is already registered |
| 622 | - if ( in_array($this->widgets[$key]->id_base, $registered, true) ) { |
|
| 622 | + if (in_array($this->widgets[$key]->id_base, $registered, true)) { |
|
| 623 | 623 | unset($this->widgets[$key]); |
| 624 | 624 | continue; |
| 625 | 625 | } |
@@ -766,33 +766,33 @@ discard block |
||
| 766 | 766 | * Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'. |
| 767 | 767 | * } |
| 768 | 768 | */ |
| 769 | -function register_sidebars( $number = 1, $args = array() ) { |
|
| 769 | +function register_sidebars($number = 1, $args = array()) { |
|
| 770 | 770 | global $wp_registered_sidebars; |
| 771 | 771 | $number = (int) $number; |
| 772 | 772 | |
| 773 | - if ( is_string($args) ) |
|
| 773 | + if (is_string($args)) |
|
| 774 | 774 | parse_str($args, $args); |
| 775 | 775 | |
| 776 | - for ( $i = 1; $i <= $number; $i++ ) { |
|
| 776 | + for ($i = 1; $i <= $number; $i++) { |
|
| 777 | 777 | $_args = $args; |
| 778 | 778 | |
| 779 | - if ( $number > 1 ) |
|
| 779 | + if ($number > 1) |
|
| 780 | 780 | $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
| 781 | 781 | else |
| 782 | 782 | $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
| 783 | 783 | |
| 784 | 784 | // Custom specified ID's are suffixed if they exist already. |
| 785 | 785 | // Automatically generated sidebar names need to be suffixed regardless starting at -0 |
| 786 | - if ( isset($args['id']) ) { |
|
| 786 | + if (isset($args['id'])) { |
|
| 787 | 787 | $_args['id'] = $args['id']; |
| 788 | 788 | $n = 2; // Start at -2 for conflicting custom ID's |
| 789 | - while ( isset($wp_registered_sidebars[$_args['id']]) ) |
|
| 790 | - $_args['id'] = $args['id'] . '-' . $n++; |
|
| 789 | + while (isset($wp_registered_sidebars[$_args['id']])) |
|
| 790 | + $_args['id'] = $args['id'].'-'.$n++; |
|
| 791 | 791 | } else { |
| 792 | 792 | $n = count($wp_registered_sidebars); |
| 793 | 793 | do { |
| 794 | - $_args['id'] = 'sidebar-' . ++$n; |
|
| 795 | - } while ( isset($wp_registered_sidebars[$_args['id']]) ); |
|
| 794 | + $_args['id'] = 'sidebar-'.++$n; |
|
| 795 | + } while (isset($wp_registered_sidebars[$_args['id']])); |
|
| 796 | 796 | } |
| 797 | 797 | register_sidebar($_args); |
| 798 | 798 | } |
@@ -844,10 +844,10 @@ discard block |
||
| 844 | 844 | |
| 845 | 845 | $i = count($wp_registered_sidebars) + 1; |
| 846 | 846 | |
| 847 | - $id_is_empty = empty( $args['id'] ); |
|
| 847 | + $id_is_empty = empty($args['id']); |
|
| 848 | 848 | |
| 849 | 849 | $defaults = array( |
| 850 | - 'name' => sprintf(__('Sidebar %d'), $i ), |
|
| 850 | + 'name' => sprintf(__('Sidebar %d'), $i), |
|
| 851 | 851 | 'id' => "sidebar-$i", |
| 852 | 852 | 'description' => '', |
| 853 | 853 | 'class' => '', |
@@ -857,11 +857,11 @@ discard block |
||
| 857 | 857 | 'after_title' => "</h2>\n", |
| 858 | 858 | ); |
| 859 | 859 | |
| 860 | - $sidebar = wp_parse_args( $args, $defaults ); |
|
| 860 | + $sidebar = wp_parse_args($args, $defaults); |
|
| 861 | 861 | |
| 862 | - if ( $id_is_empty ) { |
|
| 862 | + if ($id_is_empty) { |
|
| 863 | 863 | /* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */ |
| 864 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' ); |
|
| 864 | + _doing_it_wrong(__FUNCTION__, sprintf(__('No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.'), '<code>id</code>', $sidebar['name'], $sidebar['id']), '4.2.0'); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | $wp_registered_sidebars[$sidebar['id']] = $sidebar; |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | * |
| 876 | 876 | * @param array $sidebar Parsed arguments for the registered sidebar. |
| 877 | 877 | */ |
| 878 | - do_action( 'register_sidebar', $sidebar ); |
|
| 878 | + do_action('register_sidebar', $sidebar); |
|
| 879 | 879 | |
| 880 | 880 | return $sidebar['id']; |
| 881 | 881 | } |
@@ -889,10 +889,10 @@ discard block |
||
| 889 | 889 | * |
| 890 | 890 | * @param string $name The ID of the sidebar when it was added. |
| 891 | 891 | */ |
| 892 | -function unregister_sidebar( $name ) { |
|
| 892 | +function unregister_sidebar($name) { |
|
| 893 | 893 | global $wp_registered_sidebars; |
| 894 | 894 | |
| 895 | - unset( $wp_registered_sidebars[ $name ] ); |
|
| 895 | + unset($wp_registered_sidebars[$name]); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -922,20 +922,20 @@ discard block |
||
| 922 | 922 | * panel and/or theme. |
| 923 | 923 | * } |
| 924 | 924 | */ |
| 925 | -function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) { |
|
| 925 | +function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) { |
|
| 926 | 926 | global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; |
| 927 | 927 | |
| 928 | 928 | $id = strtolower($id); |
| 929 | 929 | |
| 930 | - if ( empty($output_callback) ) { |
|
| 930 | + if (empty($output_callback)) { |
|
| 931 | 931 | unset($wp_registered_widgets[$id]); |
| 932 | 932 | return; |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | $id_base = _get_widget_id_base($id); |
| 936 | - if ( in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback) ) { |
|
| 937 | - unset( $wp_registered_widget_controls[ $id ] ); |
|
| 938 | - unset( $wp_registered_widget_updates[ $id_base ] ); |
|
| 936 | + if (in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && ! is_callable($output_callback)) { |
|
| 937 | + unset($wp_registered_widget_controls[$id]); |
|
| 938 | + unset($wp_registered_widget_updates[$id_base]); |
|
| 939 | 939 | return; |
| 940 | 940 | } |
| 941 | 941 | |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | ); |
| 950 | 950 | $widget = array_merge($widget, $options); |
| 951 | 951 | |
| 952 | - if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) { |
|
| 952 | + if (is_callable($output_callback) && ( ! isset($wp_registered_widgets[$id]) || did_action('widgets_init'))) { |
|
| 953 | 953 | |
| 954 | 954 | /** |
| 955 | 955 | * Fires once for each registered widget. |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | * |
| 959 | 959 | * @param array $widget An array of default widget arguments. |
| 960 | 960 | */ |
| 961 | - do_action( 'wp_register_sidebar_widget', $widget ); |
|
| 961 | + do_action('wp_register_sidebar_widget', $widget); |
|
| 962 | 962 | $wp_registered_widgets[$id] = $widget; |
| 963 | 963 | } |
| 964 | 964 | } |
@@ -977,14 +977,14 @@ discard block |
||
| 977 | 977 | * @param int|string $id Widget ID. |
| 978 | 978 | * @return string|void Widget description, if available. |
| 979 | 979 | */ |
| 980 | -function wp_widget_description( $id ) { |
|
| 981 | - if ( !is_scalar($id) ) |
|
| 980 | +function wp_widget_description($id) { |
|
| 981 | + if ( ! is_scalar($id)) |
|
| 982 | 982 | return; |
| 983 | 983 | |
| 984 | 984 | global $wp_registered_widgets; |
| 985 | 985 | |
| 986 | - if ( isset($wp_registered_widgets[$id]['description']) ) |
|
| 987 | - return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
| 986 | + if (isset($wp_registered_widgets[$id]['description'])) |
|
| 987 | + return esc_html($wp_registered_widgets[$id]['description']); |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -1000,14 +1000,14 @@ discard block |
||
| 1000 | 1000 | * @param string $id sidebar ID. |
| 1001 | 1001 | * @return string|void Sidebar description, if available. |
| 1002 | 1002 | */ |
| 1003 | -function wp_sidebar_description( $id ) { |
|
| 1004 | - if ( !is_scalar($id) ) |
|
| 1003 | +function wp_sidebar_description($id) { |
|
| 1004 | + if ( ! is_scalar($id)) |
|
| 1005 | 1005 | return; |
| 1006 | 1006 | |
| 1007 | 1007 | global $wp_registered_sidebars; |
| 1008 | 1008 | |
| 1009 | - if ( isset($wp_registered_sidebars[$id]['description']) ) |
|
| 1010 | - return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
| 1009 | + if (isset($wp_registered_sidebars[$id]['description'])) |
|
| 1010 | + return esc_html($wp_registered_sidebars[$id]['description']); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | * |
| 1027 | 1027 | * @param int $id The widget ID. |
| 1028 | 1028 | */ |
| 1029 | - do_action( 'wp_unregister_sidebar_widget', $id ); |
|
| 1029 | + do_action('wp_unregister_sidebar_widget', $id); |
|
| 1030 | 1030 | |
| 1031 | 1031 | wp_register_sidebar_widget($id, '', ''); |
| 1032 | 1032 | wp_unregister_widget_control($id); |
@@ -1057,27 +1057,27 @@ discard block |
||
| 1057 | 1057 | * @param callback $control_callback Run when sidebar is displayed. |
| 1058 | 1058 | * @param array|string $options Optional. Widget options. See description above. Default empty array. |
| 1059 | 1059 | */ |
| 1060 | -function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) { |
|
| 1060 | +function wp_register_widget_control($id, $name, $control_callback, $options = array()) { |
|
| 1061 | 1061 | global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks; |
| 1062 | 1062 | |
| 1063 | 1063 | $id = strtolower($id); |
| 1064 | 1064 | $id_base = _get_widget_id_base($id); |
| 1065 | 1065 | |
| 1066 | - if ( empty($control_callback) ) { |
|
| 1066 | + if (empty($control_callback)) { |
|
| 1067 | 1067 | unset($wp_registered_widget_controls[$id]); |
| 1068 | 1068 | unset($wp_registered_widget_updates[$id_base]); |
| 1069 | 1069 | return; |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | - if ( in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($control_callback) ) { |
|
| 1073 | - unset( $wp_registered_widgets[ $id ] ); |
|
| 1072 | + if (in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && ! is_callable($control_callback)) { |
|
| 1073 | + unset($wp_registered_widgets[$id]); |
|
| 1074 | 1074 | return; |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
| 1077 | + if (isset($wp_registered_widget_controls[$id]) && ! did_action('widgets_init')) |
|
| 1078 | 1078 | return; |
| 1079 | 1079 | |
| 1080 | - $defaults = array('width' => 250, 'height' => 200 ); // height is never used |
|
| 1080 | + $defaults = array('width' => 250, 'height' => 200); // height is never used |
|
| 1081 | 1081 | $options = wp_parse_args($options, $defaults); |
| 1082 | 1082 | $options['width'] = (int) $options['width']; |
| 1083 | 1083 | $options['height'] = (int) $options['height']; |
@@ -1092,10 +1092,10 @@ discard block |
||
| 1092 | 1092 | |
| 1093 | 1093 | $wp_registered_widget_controls[$id] = $widget; |
| 1094 | 1094 | |
| 1095 | - if ( isset($wp_registered_widget_updates[$id_base]) ) |
|
| 1095 | + if (isset($wp_registered_widget_updates[$id_base])) |
|
| 1096 | 1096 | return; |
| 1097 | 1097 | |
| 1098 | - if ( isset($widget['params'][0]['number']) ) |
|
| 1098 | + if (isset($widget['params'][0]['number'])) |
|
| 1099 | 1099 | $widget['params'][0]['number'] = -1; |
| 1100 | 1100 | |
| 1101 | 1101 | unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); |
@@ -1112,8 +1112,8 @@ discard block |
||
| 1112 | 1112 | function _register_widget_update_callback($id_base, $update_callback, $options = array()) { |
| 1113 | 1113 | global $wp_registered_widget_updates; |
| 1114 | 1114 | |
| 1115 | - if ( isset($wp_registered_widget_updates[$id_base]) ) { |
|
| 1116 | - if ( empty($update_callback) ) |
|
| 1115 | + if (isset($wp_registered_widget_updates[$id_base])) { |
|
| 1116 | + if (empty($update_callback)) |
|
| 1117 | 1117 | unset($wp_registered_widget_updates[$id_base]); |
| 1118 | 1118 | return; |
| 1119 | 1119 | } |
@@ -1141,15 +1141,15 @@ discard block |
||
| 1141 | 1141 | |
| 1142 | 1142 | $id = strtolower($id); |
| 1143 | 1143 | |
| 1144 | - if ( empty($form_callback) ) { |
|
| 1144 | + if (empty($form_callback)) { |
|
| 1145 | 1145 | unset($wp_registered_widget_controls[$id]); |
| 1146 | 1146 | return; |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
| 1149 | + if (isset($wp_registered_widget_controls[$id]) && ! did_action('widgets_init')) |
|
| 1150 | 1150 | return; |
| 1151 | 1151 | |
| 1152 | - $defaults = array('width' => 250, 'height' => 200 ); |
|
| 1152 | + $defaults = array('width' => 250, 'height' => 200); |
|
| 1153 | 1153 | $options = wp_parse_args($options, $defaults); |
| 1154 | 1154 | $options['width'] = (int) $options['width']; |
| 1155 | 1155 | $options['height'] = (int) $options['height']; |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | * @param int|string $id Widget ID. |
| 1174 | 1174 | */ |
| 1175 | 1175 | function wp_unregister_widget_control($id) { |
| 1176 | - wp_register_widget_control( $id, '', '' ); |
|
| 1176 | + wp_register_widget_control($id, '', ''); |
|
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | 1179 | /** |
@@ -1194,12 +1194,12 @@ discard block |
||
| 1194 | 1194 | function dynamic_sidebar($index = 1) { |
| 1195 | 1195 | global $wp_registered_sidebars, $wp_registered_widgets; |
| 1196 | 1196 | |
| 1197 | - if ( is_int($index) ) { |
|
| 1197 | + if (is_int($index)) { |
|
| 1198 | 1198 | $index = "sidebar-$index"; |
| 1199 | 1199 | } else { |
| 1200 | 1200 | $index = sanitize_title($index); |
| 1201 | - foreach ( (array) $wp_registered_sidebars as $key => $value ) { |
|
| 1202 | - if ( sanitize_title($value['name']) == $index ) { |
|
| 1201 | + foreach ((array) $wp_registered_sidebars as $key => $value) { |
|
| 1202 | + if (sanitize_title($value['name']) == $index) { |
|
| 1203 | 1203 | $index = $key; |
| 1204 | 1204 | break; |
| 1205 | 1205 | } |
@@ -1207,13 +1207,13 @@ discard block |
||
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | $sidebars_widgets = wp_get_sidebars_widgets(); |
| 1210 | - if ( empty( $wp_registered_sidebars[ $index ] ) || empty( $sidebars_widgets[ $index ] ) || ! is_array( $sidebars_widgets[ $index ] ) ) { |
|
| 1210 | + if (empty($wp_registered_sidebars[$index]) || empty($sidebars_widgets[$index]) || ! is_array($sidebars_widgets[$index])) { |
|
| 1211 | 1211 | /** This action is documented in wp-includes/widgets.php */ |
| 1212 | - do_action( 'dynamic_sidebar_before', $index, false ); |
|
| 1212 | + do_action('dynamic_sidebar_before', $index, false); |
|
| 1213 | 1213 | /** This action is documented in wp-includes/widgets.php */ |
| 1214 | - do_action( 'dynamic_sidebar_after', $index, false ); |
|
| 1214 | + do_action('dynamic_sidebar_after', $index, false); |
|
| 1215 | 1215 | /** This filter is documented in wp-includes/widgets.php */ |
| 1216 | - return apply_filters( 'dynamic_sidebar_has_widgets', false, $index ); |
|
| 1216 | + return apply_filters('dynamic_sidebar_has_widgets', false, $index); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | /** |
@@ -1228,26 +1228,26 @@ discard block |
||
| 1228 | 1228 | * @param bool $has_widgets Whether the sidebar is populated with widgets. |
| 1229 | 1229 | * Default true. |
| 1230 | 1230 | */ |
| 1231 | - do_action( 'dynamic_sidebar_before', $index, true ); |
|
| 1231 | + do_action('dynamic_sidebar_before', $index, true); |
|
| 1232 | 1232 | $sidebar = $wp_registered_sidebars[$index]; |
| 1233 | 1233 | |
| 1234 | 1234 | $did_one = false; |
| 1235 | - foreach ( (array) $sidebars_widgets[$index] as $id ) { |
|
| 1235 | + foreach ((array) $sidebars_widgets[$index] as $id) { |
|
| 1236 | 1236 | |
| 1237 | - if ( !isset($wp_registered_widgets[$id]) ) continue; |
|
| 1237 | + if ( ! isset($wp_registered_widgets[$id])) continue; |
|
| 1238 | 1238 | |
| 1239 | 1239 | $params = array_merge( |
| 1240 | - array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
|
| 1240 | + array(array_merge($sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']))), |
|
| 1241 | 1241 | (array) $wp_registered_widgets[$id]['params'] |
| 1242 | 1242 | ); |
| 1243 | 1243 | |
| 1244 | 1244 | // Substitute HTML id and class attributes into before_widget |
| 1245 | 1245 | $classname_ = ''; |
| 1246 | - foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
|
| 1247 | - if ( is_string($cn) ) |
|
| 1248 | - $classname_ .= '_' . $cn; |
|
| 1249 | - elseif ( is_object($cn) ) |
|
| 1250 | - $classname_ .= '_' . get_class($cn); |
|
| 1246 | + foreach ((array) $wp_registered_widgets[$id]['classname'] as $cn) { |
|
| 1247 | + if (is_string($cn)) |
|
| 1248 | + $classname_ .= '_'.$cn; |
|
| 1249 | + elseif (is_object($cn)) |
|
| 1250 | + $classname_ .= '_'.get_class($cn); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | $classname_ = ltrim($classname_, '_'); |
| 1253 | 1253 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
@@ -1284,7 +1284,7 @@ discard block |
||
| 1284 | 1284 | * } |
| 1285 | 1285 | * } |
| 1286 | 1286 | */ |
| 1287 | - $params = apply_filters( 'dynamic_sidebar_params', $params ); |
|
| 1287 | + $params = apply_filters('dynamic_sidebar_params', $params); |
|
| 1288 | 1288 | |
| 1289 | 1289 | $callback = $wp_registered_widgets[$id]['callback']; |
| 1290 | 1290 | |
@@ -1313,9 +1313,9 @@ discard block |
||
| 1313 | 1313 | * with an array containing the widget object, see $callback. |
| 1314 | 1314 | * } |
| 1315 | 1315 | */ |
| 1316 | - do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); |
|
| 1316 | + do_action('dynamic_sidebar', $wp_registered_widgets[$id]); |
|
| 1317 | 1317 | |
| 1318 | - if ( is_callable($callback) ) { |
|
| 1318 | + if (is_callable($callback)) { |
|
| 1319 | 1319 | call_user_func_array($callback, $params); |
| 1320 | 1320 | $did_one = true; |
| 1321 | 1321 | } |
@@ -1333,7 +1333,7 @@ discard block |
||
| 1333 | 1333 | * @param bool $has_widgets Whether the sidebar is populated with widgets. |
| 1334 | 1334 | * Default true. |
| 1335 | 1335 | */ |
| 1336 | - do_action( 'dynamic_sidebar_after', $index, true ); |
|
| 1336 | + do_action('dynamic_sidebar_after', $index, true); |
|
| 1337 | 1337 | |
| 1338 | 1338 | /** |
| 1339 | 1339 | * Filter whether a sidebar has widgets. |
@@ -1347,7 +1347,7 @@ discard block |
||
| 1347 | 1347 | * Default false. |
| 1348 | 1348 | * @param int|string $index Index, name, or ID of the dynamic sidebar. |
| 1349 | 1349 | */ |
| 1350 | - return apply_filters( 'dynamic_sidebar_has_widgets', $did_one, $index ); |
|
| 1350 | + return apply_filters('dynamic_sidebar_has_widgets', $did_one, $index); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | /** |
@@ -1378,16 +1378,16 @@ discard block |
||
| 1378 | 1378 | |
| 1379 | 1379 | $sidebars_widgets = wp_get_sidebars_widgets(); |
| 1380 | 1380 | |
| 1381 | - if ( is_array($sidebars_widgets) ) { |
|
| 1382 | - foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
|
| 1383 | - if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) { |
|
| 1381 | + if (is_array($sidebars_widgets)) { |
|
| 1382 | + foreach ($sidebars_widgets as $sidebar => $widgets) { |
|
| 1383 | + if ($skip_inactive && ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16))) { |
|
| 1384 | 1384 | continue; |
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | - if ( is_array($widgets) ) { |
|
| 1388 | - foreach ( $widgets as $widget ) { |
|
| 1389 | - if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) { |
|
| 1390 | - if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) |
|
| 1387 | + if (is_array($widgets)) { |
|
| 1388 | + foreach ($widgets as $widget) { |
|
| 1389 | + if (($callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback) || ($id_base && _get_widget_id_base($widget) == $id_base)) { |
|
| 1390 | + if ( ! $widget_id || $widget_id == $wp_registered_widgets[$widget]['id']) |
|
| 1391 | 1391 | return $sidebar; |
| 1392 | 1392 | } |
| 1393 | 1393 | } |
@@ -1410,10 +1410,10 @@ discard block |
||
| 1410 | 1410 | function is_dynamic_sidebar() { |
| 1411 | 1411 | global $wp_registered_widgets, $wp_registered_sidebars; |
| 1412 | 1412 | $sidebars_widgets = get_option('sidebars_widgets'); |
| 1413 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
|
| 1414 | - if ( count($sidebars_widgets[$index]) ) { |
|
| 1415 | - foreach ( (array) $sidebars_widgets[$index] as $widget ) |
|
| 1416 | - if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
| 1413 | + foreach ((array) $wp_registered_sidebars as $index => $sidebar) { |
|
| 1414 | + if (count($sidebars_widgets[$index])) { |
|
| 1415 | + foreach ((array) $sidebars_widgets[$index] as $widget) |
|
| 1416 | + if (array_key_exists($widget, $wp_registered_widgets)) |
|
| 1417 | 1417 | return true; |
| 1418 | 1418 | } |
| 1419 | 1419 | } |
@@ -1428,10 +1428,10 @@ discard block |
||
| 1428 | 1428 | * @param string|int $index Sidebar name, id or number to check. |
| 1429 | 1429 | * @return bool true if the sidebar is in use, false otherwise. |
| 1430 | 1430 | */ |
| 1431 | -function is_active_sidebar( $index ) { |
|
| 1432 | - $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); |
|
| 1431 | +function is_active_sidebar($index) { |
|
| 1432 | + $index = (is_int($index)) ? "sidebar-$index" : sanitize_title($index); |
|
| 1433 | 1433 | $sidebars_widgets = wp_get_sidebars_widgets(); |
| 1434 | - $is_active_sidebar = ! empty( $sidebars_widgets[$index] ); |
|
| 1434 | + $is_active_sidebar = ! empty($sidebars_widgets[$index]); |
|
| 1435 | 1435 | |
| 1436 | 1436 | /** |
| 1437 | 1437 | * Filter whether a dynamic sidebar is considered "active". |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | * In other words, whether the sidebar contains any widgets. |
| 1443 | 1443 | * @param int|string $index Index, name, or ID of the dynamic sidebar. |
| 1444 | 1444 | */ |
| 1445 | - return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index ); |
|
| 1445 | + return apply_filters('is_active_sidebar', $is_active_sidebar, $index); |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | /* Internal Functions */ |
@@ -1462,16 +1462,16 @@ discard block |
||
| 1462 | 1462 | * @param bool $deprecated Not used (argument deprecated). |
| 1463 | 1463 | * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
| 1464 | 1464 | */ |
| 1465 | -function wp_get_sidebars_widgets( $deprecated = true ) { |
|
| 1466 | - if ( $deprecated !== true ) |
|
| 1467 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
| 1465 | +function wp_get_sidebars_widgets($deprecated = true) { |
|
| 1466 | + if ($deprecated !== true) |
|
| 1467 | + _deprecated_argument(__FUNCTION__, '2.8.1'); |
|
| 1468 | 1468 | |
| 1469 | 1469 | global $_wp_sidebars_widgets, $sidebars_widgets; |
| 1470 | 1470 | |
| 1471 | 1471 | // If loading from front page, consult $_wp_sidebars_widgets rather than options |
| 1472 | 1472 | // to see if wp_convert_widget_settings() has made manipulations in memory. |
| 1473 | - if ( !is_admin() ) { |
|
| 1474 | - if ( empty($_wp_sidebars_widgets) ) |
|
| 1473 | + if ( ! is_admin()) { |
|
| 1474 | + if (empty($_wp_sidebars_widgets)) |
|
| 1475 | 1475 | $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
| 1476 | 1476 | |
| 1477 | 1477 | $sidebars_widgets = $_wp_sidebars_widgets; |
@@ -1479,7 +1479,7 @@ discard block |
||
| 1479 | 1479 | $sidebars_widgets = get_option('sidebars_widgets', array()); |
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | - if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) |
|
| 1482 | + if (is_array($sidebars_widgets) && isset($sidebars_widgets['array_version'])) |
|
| 1483 | 1483 | unset($sidebars_widgets['array_version']); |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1489,7 +1489,7 @@ discard block |
||
| 1489 | 1489 | * |
| 1490 | 1490 | * @param array $sidebars_widgets An associative array of sidebars and their widgets. |
| 1491 | 1491 | */ |
| 1492 | - return apply_filters( 'sidebars_widgets', $sidebars_widgets ); |
|
| 1492 | + return apply_filters('sidebars_widgets', $sidebars_widgets); |
|
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | /** |
@@ -1500,10 +1500,10 @@ discard block |
||
| 1500 | 1500 | * |
| 1501 | 1501 | * @param array $sidebars_widgets Sidebar widgets and their settings. |
| 1502 | 1502 | */ |
| 1503 | -function wp_set_sidebars_widgets( $sidebars_widgets ) { |
|
| 1504 | - if ( !isset( $sidebars_widgets['array_version'] ) ) |
|
| 1503 | +function wp_set_sidebars_widgets($sidebars_widgets) { |
|
| 1504 | + if ( ! isset($sidebars_widgets['array_version'])) |
|
| 1505 | 1505 | $sidebars_widgets['array_version'] = 3; |
| 1506 | - update_option( 'sidebars_widgets', $sidebars_widgets ); |
|
| 1506 | + update_option('sidebars_widgets', $sidebars_widgets); |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | /** |
@@ -1521,7 +1521,7 @@ discard block |
||
| 1521 | 1521 | |
| 1522 | 1522 | $defaults = array(); |
| 1523 | 1523 | |
| 1524 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) |
|
| 1524 | + foreach ((array) $wp_registered_sidebars as $index => $sidebar) |
|
| 1525 | 1525 | $defaults[$index] = array(); |
| 1526 | 1526 | |
| 1527 | 1527 | return $defaults; |
@@ -1542,35 +1542,35 @@ discard block |
||
| 1542 | 1542 | function wp_convert_widget_settings($base_name, $option_name, $settings) { |
| 1543 | 1543 | // This test may need expanding. |
| 1544 | 1544 | $single = $changed = false; |
| 1545 | - if ( empty($settings) ) { |
|
| 1545 | + if (empty($settings)) { |
|
| 1546 | 1546 | $single = true; |
| 1547 | 1547 | } else { |
| 1548 | - foreach ( array_keys($settings) as $number ) { |
|
| 1549 | - if ( 'number' == $number ) |
|
| 1548 | + foreach (array_keys($settings) as $number) { |
|
| 1549 | + if ('number' == $number) |
|
| 1550 | 1550 | continue; |
| 1551 | - if ( !is_numeric($number) ) { |
|
| 1551 | + if ( ! is_numeric($number)) { |
|
| 1552 | 1552 | $single = true; |
| 1553 | 1553 | break; |
| 1554 | 1554 | } |
| 1555 | 1555 | } |
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | - if ( $single ) { |
|
| 1559 | - $settings = array( 2 => $settings ); |
|
| 1558 | + if ($single) { |
|
| 1559 | + $settings = array(2 => $settings); |
|
| 1560 | 1560 | |
| 1561 | 1561 | // If loading from the front page, update sidebar in memory but don't save to options |
| 1562 | - if ( is_admin() ) { |
|
| 1562 | + if (is_admin()) { |
|
| 1563 | 1563 | $sidebars_widgets = get_option('sidebars_widgets'); |
| 1564 | 1564 | } else { |
| 1565 | - if ( empty($GLOBALS['_wp_sidebars_widgets']) ) |
|
| 1565 | + if (empty($GLOBALS['_wp_sidebars_widgets'])) |
|
| 1566 | 1566 | $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
| 1567 | 1567 | $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; |
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | - foreach ( (array) $sidebars_widgets as $index => $sidebar ) { |
|
| 1571 | - if ( is_array($sidebar) ) { |
|
| 1572 | - foreach ( $sidebar as $i => $name ) { |
|
| 1573 | - if ( $base_name == $name ) { |
|
| 1570 | + foreach ((array) $sidebars_widgets as $index => $sidebar) { |
|
| 1571 | + if (is_array($sidebar)) { |
|
| 1572 | + foreach ($sidebar as $i => $name) { |
|
| 1573 | + if ($base_name == $name) { |
|
| 1574 | 1574 | $sidebars_widgets[$index][$i] = "$name-2"; |
| 1575 | 1575 | $changed = true; |
| 1576 | 1576 | break 2; |
@@ -1579,13 +1579,13 @@ discard block |
||
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - if ( is_admin() && $changed ) |
|
| 1582 | + if (is_admin() && $changed) |
|
| 1583 | 1583 | update_option('sidebars_widgets', $sidebars_widgets); |
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | $settings['_multiwidget'] = 1; |
| 1587 | - if ( is_admin() ) |
|
| 1588 | - update_option( $option_name, $settings ); |
|
| 1587 | + if (is_admin()) |
|
| 1588 | + update_option($option_name, $settings); |
|
| 1589 | 1589 | |
| 1590 | 1590 | return $settings; |
| 1591 | 1591 | } |
@@ -1612,16 +1612,16 @@ discard block |
||
| 1612 | 1612 | * Default `</h2>`. |
| 1613 | 1613 | * } |
| 1614 | 1614 | */ |
| 1615 | -function the_widget( $widget, $instance = array(), $args = array() ) { |
|
| 1615 | +function the_widget($widget, $instance = array(), $args = array()) { |
|
| 1616 | 1616 | global $wp_widget_factory; |
| 1617 | 1617 | |
| 1618 | 1618 | $widget_obj = $wp_widget_factory->widgets[$widget]; |
| 1619 | - if ( ! ( $widget_obj instanceof WP_Widget ) ) { |
|
| 1619 | + if ( ! ($widget_obj instanceof WP_Widget)) { |
|
| 1620 | 1620 | return; |
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | - $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] ); |
|
| 1624 | - $default_args = array( 'before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); |
|
| 1623 | + $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']); |
|
| 1624 | + $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>'); |
|
| 1625 | 1625 | |
| 1626 | 1626 | $args = wp_parse_args($args, $default_args); |
| 1627 | 1627 | $instance = wp_parse_args($instance); |
@@ -1635,7 +1635,7 @@ discard block |
||
| 1635 | 1635 | * @param array $instance The current widget instance's settings. |
| 1636 | 1636 | * @param array $args An array of the widget's sidebar arguments. |
| 1637 | 1637 | */ |
| 1638 | - do_action( 'the_widget', $widget, $instance, $args ); |
|
| 1638 | + do_action('the_widget', $widget, $instance, $args); |
|
| 1639 | 1639 | |
| 1640 | 1640 | $widget_obj->_set(-1); |
| 1641 | 1641 | $widget_obj->widget($args, $instance); |
@@ -1647,7 +1647,7 @@ discard block |
||
| 1647 | 1647 | * @return string |
| 1648 | 1648 | */ |
| 1649 | 1649 | function _get_widget_id_base($id) { |
| 1650 | - return preg_replace( '/-[0-9]+$/', '', $id ); |
|
| 1650 | + return preg_replace('/-[0-9]+$/', '', $id); |
|
| 1651 | 1651 | } |
| 1652 | 1652 | |
| 1653 | 1653 | /** |
@@ -1661,7 +1661,7 @@ discard block |
||
| 1661 | 1661 | function _wp_sidebars_changed() { |
| 1662 | 1662 | global $sidebars_widgets; |
| 1663 | 1663 | |
| 1664 | - if ( ! is_array( $sidebars_widgets ) ) |
|
| 1664 | + if ( ! is_array($sidebars_widgets)) |
|
| 1665 | 1665 | $sidebars_widgets = wp_get_sidebars_widgets(); |
| 1666 | 1666 | |
| 1667 | 1667 | retrieve_widgets(true); |
@@ -1680,78 +1680,78 @@ discard block |
||
| 1680 | 1680 | * of 'customize' defers updates for the Customizer. |
| 1681 | 1681 | * @return array|void |
| 1682 | 1682 | */ |
| 1683 | -function retrieve_widgets( $theme_changed = false ) { |
|
| 1683 | +function retrieve_widgets($theme_changed = false) { |
|
| 1684 | 1684 | global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; |
| 1685 | 1685 | |
| 1686 | - $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); |
|
| 1686 | + $registered_sidebar_keys = array_keys($wp_registered_sidebars); |
|
| 1687 | 1687 | $orphaned = 0; |
| 1688 | 1688 | |
| 1689 | - $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); |
|
| 1690 | - if ( is_array( $old_sidebars_widgets ) ) { |
|
| 1689 | + $old_sidebars_widgets = get_theme_mod('sidebars_widgets'); |
|
| 1690 | + if (is_array($old_sidebars_widgets)) { |
|
| 1691 | 1691 | // time() that sidebars were stored is in $old_sidebars_widgets['time'] |
| 1692 | 1692 | $_sidebars_widgets = $old_sidebars_widgets['data']; |
| 1693 | 1693 | |
| 1694 | - if ( 'customize' !== $theme_changed ) { |
|
| 1695 | - remove_theme_mod( 'sidebars_widgets' ); |
|
| 1694 | + if ('customize' !== $theme_changed) { |
|
| 1695 | + remove_theme_mod('sidebars_widgets'); |
|
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | - foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
|
| 1699 | - if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) { |
|
| 1698 | + foreach ($_sidebars_widgets as $sidebar => $widgets) { |
|
| 1699 | + if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) { |
|
| 1700 | 1700 | continue; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | - if ( !in_array( $sidebar, $registered_sidebar_keys ) ) { |
|
| 1704 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets; |
|
| 1705 | - unset( $_sidebars_widgets[$sidebar] ); |
|
| 1703 | + if ( ! in_array($sidebar, $registered_sidebar_keys)) { |
|
| 1704 | + $_sidebars_widgets['orphaned_widgets_'.++$orphaned] = $widgets; |
|
| 1705 | + unset($_sidebars_widgets[$sidebar]); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | } |
| 1708 | 1708 | } else { |
| 1709 | - if ( empty( $sidebars_widgets ) ) |
|
| 1709 | + if (empty($sidebars_widgets)) |
|
| 1710 | 1710 | return; |
| 1711 | 1711 | |
| 1712 | - unset( $sidebars_widgets['array_version'] ); |
|
| 1712 | + unset($sidebars_widgets['array_version']); |
|
| 1713 | 1713 | |
| 1714 | 1714 | $old = array_keys($sidebars_widgets); |
| 1715 | 1715 | sort($old); |
| 1716 | 1716 | sort($registered_sidebar_keys); |
| 1717 | 1717 | |
| 1718 | - if ( $old == $registered_sidebar_keys ) |
|
| 1718 | + if ($old == $registered_sidebar_keys) |
|
| 1719 | 1719 | return; |
| 1720 | 1720 | |
| 1721 | 1721 | $_sidebars_widgets = array( |
| 1722 | - 'wp_inactive_widgets' => !empty( $sidebars_widgets['wp_inactive_widgets'] ) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
|
| 1722 | + 'wp_inactive_widgets' => ! empty($sidebars_widgets['wp_inactive_widgets']) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
|
| 1723 | 1723 | ); |
| 1724 | 1724 | |
| 1725 | - unset( $sidebars_widgets['wp_inactive_widgets'] ); |
|
| 1725 | + unset($sidebars_widgets['wp_inactive_widgets']); |
|
| 1726 | 1726 | |
| 1727 | - foreach ( $wp_registered_sidebars as $id => $settings ) { |
|
| 1728 | - if ( $theme_changed ) { |
|
| 1729 | - $_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); |
|
| 1727 | + foreach ($wp_registered_sidebars as $id => $settings) { |
|
| 1728 | + if ($theme_changed) { |
|
| 1729 | + $_sidebars_widgets[$id] = array_shift($sidebars_widgets); |
|
| 1730 | 1730 | } else { |
| 1731 | 1731 | // no theme change, grab only sidebars that are currently registered |
| 1732 | - if ( isset( $sidebars_widgets[$id] ) ) { |
|
| 1732 | + if (isset($sidebars_widgets[$id])) { |
|
| 1733 | 1733 | $_sidebars_widgets[$id] = $sidebars_widgets[$id]; |
| 1734 | - unset( $sidebars_widgets[$id] ); |
|
| 1734 | + unset($sidebars_widgets[$id]); |
|
| 1735 | 1735 | } |
| 1736 | 1736 | } |
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | - foreach ( $sidebars_widgets as $val ) { |
|
| 1740 | - if ( is_array($val) && ! empty( $val ) ) |
|
| 1741 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
| 1739 | + foreach ($sidebars_widgets as $val) { |
|
| 1740 | + if (is_array($val) && ! empty($val)) |
|
| 1741 | + $_sidebars_widgets['orphaned_widgets_'.++$orphaned] = $val; |
|
| 1742 | 1742 | } |
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | 1745 | // discard invalid, theme-specific widgets from sidebars |
| 1746 | 1746 | $shown_widgets = array(); |
| 1747 | 1747 | |
| 1748 | - foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
|
| 1749 | - if ( !is_array($widgets) ) |
|
| 1748 | + foreach ($_sidebars_widgets as $sidebar => $widgets) { |
|
| 1749 | + if ( ! is_array($widgets)) |
|
| 1750 | 1750 | continue; |
| 1751 | 1751 | |
| 1752 | 1752 | $_widgets = array(); |
| 1753 | - foreach ( $widgets as $widget ) { |
|
| 1754 | - if ( isset($wp_registered_widgets[$widget]) ) |
|
| 1753 | + foreach ($widgets as $widget) { |
|
| 1754 | + if (isset($wp_registered_widgets[$widget])) |
|
| 1755 | 1755 | $_widgets[] = $widget; |
| 1756 | 1756 | } |
| 1757 | 1757 | |
@@ -1764,21 +1764,21 @@ discard block |
||
| 1764 | 1764 | |
| 1765 | 1765 | // find hidden/lost multi-widget instances |
| 1766 | 1766 | $lost_widgets = array(); |
| 1767 | - foreach ( $wp_registered_widgets as $key => $val ) { |
|
| 1768 | - if ( in_array($key, $shown_widgets, true) ) |
|
| 1767 | + foreach ($wp_registered_widgets as $key => $val) { |
|
| 1768 | + if (in_array($key, $shown_widgets, true)) |
|
| 1769 | 1769 | continue; |
| 1770 | 1770 | |
| 1771 | 1771 | $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key); |
| 1772 | 1772 | |
| 1773 | - if ( 2 > (int) $number ) |
|
| 1773 | + if (2 > (int) $number) |
|
| 1774 | 1774 | continue; |
| 1775 | 1775 | |
| 1776 | 1776 | $lost_widgets[] = $key; |
| 1777 | 1777 | } |
| 1778 | 1778 | |
| 1779 | 1779 | $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); |
| 1780 | - if ( 'customize' !== $theme_changed ) { |
|
| 1781 | - wp_set_sidebars_widgets( $sidebars_widgets ); |
|
| 1780 | + if ('customize' !== $theme_changed) { |
|
| 1781 | + wp_set_sidebars_widgets($sidebars_widgets); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | return $sidebars_widgets; |
@@ -365,21 +365,24 @@ discard block |
||
| 365 | 365 | $all_instances = $this->get_settings(); |
| 366 | 366 | |
| 367 | 367 | // We need to update the data |
| 368 | - if ( $this->updated ) |
|
| 369 | - return; |
|
| 368 | + if ( $this->updated ) { |
|
| 369 | + return; |
|
| 370 | + } |
|
| 370 | 371 | |
| 371 | 372 | if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { |
| 372 | 373 | // Delete the settings for this instance of the widget |
| 373 | - if ( isset($_POST['the-widget-id']) ) |
|
| 374 | - $del_id = $_POST['the-widget-id']; |
|
| 375 | - else |
|
| 376 | - return; |
|
| 374 | + if ( isset($_POST['the-widget-id']) ) { |
|
| 375 | + $del_id = $_POST['the-widget-id']; |
|
| 376 | + } else { |
|
| 377 | + return; |
|
| 378 | + } |
|
| 377 | 379 | |
| 378 | 380 | if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { |
| 379 | 381 | $number = $wp_registered_widgets[$del_id]['params'][0]['number']; |
| 380 | 382 | |
| 381 | - if ( $this->id_base . '-' . $number == $del_id ) |
|
| 382 | - unset($all_instances[$number]); |
|
| 383 | + if ( $this->id_base . '-' . $number == $del_id ) { |
|
| 384 | + unset($all_instances[$number]); |
|
| 385 | + } |
|
| 383 | 386 | } |
| 384 | 387 | } else { |
| 385 | 388 | if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) { |
@@ -444,8 +447,9 @@ discard block |
||
| 444 | 447 | * @return string|null |
| 445 | 448 | */ |
| 446 | 449 | public function form_callback( $widget_args = 1 ) { |
| 447 | - if ( is_numeric($widget_args) ) |
|
| 448 | - $widget_args = array( 'number' => $widget_args ); |
|
| 450 | + if ( is_numeric($widget_args) ) { |
|
| 451 | + $widget_args = array( 'number' => $widget_args ); |
|
| 452 | + } |
|
| 449 | 453 | |
| 450 | 454 | $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
| 451 | 455 | $all_instances = $this->get_settings(); |
@@ -770,24 +774,27 @@ discard block |
||
| 770 | 774 | global $wp_registered_sidebars; |
| 771 | 775 | $number = (int) $number; |
| 772 | 776 | |
| 773 | - if ( is_string($args) ) |
|
| 774 | - parse_str($args, $args); |
|
| 777 | + if ( is_string($args) ) { |
|
| 778 | + parse_str($args, $args); |
|
| 779 | + } |
|
| 775 | 780 | |
| 776 | 781 | for ( $i = 1; $i <= $number; $i++ ) { |
| 777 | 782 | $_args = $args; |
| 778 | 783 | |
| 779 | - if ( $number > 1 ) |
|
| 780 | - $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
|
| 781 | - else |
|
| 782 | - $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
|
| 784 | + if ( $number > 1 ) { |
|
| 785 | + $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
|
| 786 | + } else { |
|
| 787 | + $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
|
| 788 | + } |
|
| 783 | 789 | |
| 784 | 790 | // Custom specified ID's are suffixed if they exist already. |
| 785 | 791 | // Automatically generated sidebar names need to be suffixed regardless starting at -0 |
| 786 | 792 | if ( isset($args['id']) ) { |
| 787 | 793 | $_args['id'] = $args['id']; |
| 788 | 794 | $n = 2; // Start at -2 for conflicting custom ID's |
| 789 | - while ( isset($wp_registered_sidebars[$_args['id']]) ) |
|
| 790 | - $_args['id'] = $args['id'] . '-' . $n++; |
|
| 795 | + while ( isset($wp_registered_sidebars[$_args['id']]) ) { |
|
| 796 | + $_args['id'] = $args['id'] . '-' . $n++; |
|
| 797 | + } |
|
| 791 | 798 | } else { |
| 792 | 799 | $n = count($wp_registered_sidebars); |
| 793 | 800 | do { |
@@ -978,14 +985,16 @@ discard block |
||
| 978 | 985 | * @return string|void Widget description, if available. |
| 979 | 986 | */ |
| 980 | 987 | function wp_widget_description( $id ) { |
| 981 | - if ( !is_scalar($id) ) |
|
| 982 | - return; |
|
| 988 | + if ( !is_scalar($id) ) { |
|
| 989 | + return; |
|
| 990 | + } |
|
| 983 | 991 | |
| 984 | 992 | global $wp_registered_widgets; |
| 985 | 993 | |
| 986 | - if ( isset($wp_registered_widgets[$id]['description']) ) |
|
| 987 | - return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
| 988 | -} |
|
| 994 | + if ( isset($wp_registered_widgets[$id]['description']) ) { |
|
| 995 | + return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
| 996 | + } |
|
| 997 | + } |
|
| 989 | 998 | |
| 990 | 999 | /** |
| 991 | 1000 | * Retrieve description for a sidebar. |
@@ -1001,14 +1010,16 @@ discard block |
||
| 1001 | 1010 | * @return string|void Sidebar description, if available. |
| 1002 | 1011 | */ |
| 1003 | 1012 | function wp_sidebar_description( $id ) { |
| 1004 | - if ( !is_scalar($id) ) |
|
| 1005 | - return; |
|
| 1013 | + if ( !is_scalar($id) ) { |
|
| 1014 | + return; |
|
| 1015 | + } |
|
| 1006 | 1016 | |
| 1007 | 1017 | global $wp_registered_sidebars; |
| 1008 | 1018 | |
| 1009 | - if ( isset($wp_registered_sidebars[$id]['description']) ) |
|
| 1010 | - return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
| 1011 | -} |
|
| 1019 | + if ( isset($wp_registered_sidebars[$id]['description']) ) { |
|
| 1020 | + return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1012 | 1023 | |
| 1013 | 1024 | /** |
| 1014 | 1025 | * Remove widget from sidebar. |
@@ -1074,8 +1085,9 @@ discard block |
||
| 1074 | 1085 | return; |
| 1075 | 1086 | } |
| 1076 | 1087 | |
| 1077 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
| 1078 | - return; |
|
| 1088 | + if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) { |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1079 | 1091 | |
| 1080 | 1092 | $defaults = array('width' => 250, 'height' => 200 ); // height is never used |
| 1081 | 1093 | $options = wp_parse_args($options, $defaults); |
@@ -1092,11 +1104,13 @@ discard block |
||
| 1092 | 1104 | |
| 1093 | 1105 | $wp_registered_widget_controls[$id] = $widget; |
| 1094 | 1106 | |
| 1095 | - if ( isset($wp_registered_widget_updates[$id_base]) ) |
|
| 1096 | - return; |
|
| 1107 | + if ( isset($wp_registered_widget_updates[$id_base]) ) { |
|
| 1108 | + return; |
|
| 1109 | + } |
|
| 1097 | 1110 | |
| 1098 | - if ( isset($widget['params'][0]['number']) ) |
|
| 1099 | - $widget['params'][0]['number'] = -1; |
|
| 1111 | + if ( isset($widget['params'][0]['number']) ) { |
|
| 1112 | + $widget['params'][0]['number'] = -1; |
|
| 1113 | + } |
|
| 1100 | 1114 | |
| 1101 | 1115 | unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); |
| 1102 | 1116 | $wp_registered_widget_updates[$id_base] = $widget; |
@@ -1113,8 +1127,9 @@ discard block |
||
| 1113 | 1127 | global $wp_registered_widget_updates; |
| 1114 | 1128 | |
| 1115 | 1129 | if ( isset($wp_registered_widget_updates[$id_base]) ) { |
| 1116 | - if ( empty($update_callback) ) |
|
| 1117 | - unset($wp_registered_widget_updates[$id_base]); |
|
| 1130 | + if ( empty($update_callback) ) { |
|
| 1131 | + unset($wp_registered_widget_updates[$id_base]); |
|
| 1132 | + } |
|
| 1118 | 1133 | return; |
| 1119 | 1134 | } |
| 1120 | 1135 | |
@@ -1146,8 +1161,9 @@ discard block |
||
| 1146 | 1161 | return; |
| 1147 | 1162 | } |
| 1148 | 1163 | |
| 1149 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
| 1150 | - return; |
|
| 1164 | + if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) { |
|
| 1165 | + return; |
|
| 1166 | + } |
|
| 1151 | 1167 | |
| 1152 | 1168 | $defaults = array('width' => 250, 'height' => 200 ); |
| 1153 | 1169 | $options = wp_parse_args($options, $defaults); |
@@ -1234,7 +1250,9 @@ discard block |
||
| 1234 | 1250 | $did_one = false; |
| 1235 | 1251 | foreach ( (array) $sidebars_widgets[$index] as $id ) { |
| 1236 | 1252 | |
| 1237 | - if ( !isset($wp_registered_widgets[$id]) ) continue; |
|
| 1253 | + if ( !isset($wp_registered_widgets[$id]) ) { |
|
| 1254 | + continue; |
|
| 1255 | + } |
|
| 1238 | 1256 | |
| 1239 | 1257 | $params = array_merge( |
| 1240 | 1258 | array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
@@ -1244,10 +1262,11 @@ discard block |
||
| 1244 | 1262 | // Substitute HTML id and class attributes into before_widget |
| 1245 | 1263 | $classname_ = ''; |
| 1246 | 1264 | foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
| 1247 | - if ( is_string($cn) ) |
|
| 1248 | - $classname_ .= '_' . $cn; |
|
| 1249 | - elseif ( is_object($cn) ) |
|
| 1250 | - $classname_ .= '_' . get_class($cn); |
|
| 1265 | + if ( is_string($cn) ) { |
|
| 1266 | + $classname_ .= '_' . $cn; |
|
| 1267 | + } elseif ( is_object($cn) ) { |
|
| 1268 | + $classname_ .= '_' . get_class($cn); |
|
| 1269 | + } |
|
| 1251 | 1270 | } |
| 1252 | 1271 | $classname_ = ltrim($classname_, '_'); |
| 1253 | 1272 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
@@ -1387,8 +1406,9 @@ discard block |
||
| 1387 | 1406 | if ( is_array($widgets) ) { |
| 1388 | 1407 | foreach ( $widgets as $widget ) { |
| 1389 | 1408 | if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) { |
| 1390 | - if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) |
|
| 1391 | - return $sidebar; |
|
| 1409 | + if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) { |
|
| 1410 | + return $sidebar; |
|
| 1411 | + } |
|
| 1392 | 1412 | } |
| 1393 | 1413 | } |
| 1394 | 1414 | } |
@@ -1412,9 +1432,10 @@ discard block |
||
| 1412 | 1432 | $sidebars_widgets = get_option('sidebars_widgets'); |
| 1413 | 1433 | foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
| 1414 | 1434 | if ( count($sidebars_widgets[$index]) ) { |
| 1415 | - foreach ( (array) $sidebars_widgets[$index] as $widget ) |
|
| 1416 | - if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
| 1435 | + foreach ( (array) $sidebars_widgets[$index] as $widget ) { |
|
| 1436 | + if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
| 1417 | 1437 | return true; |
| 1438 | + } |
|
| 1418 | 1439 | } |
| 1419 | 1440 | } |
| 1420 | 1441 | return false; |
@@ -1463,24 +1484,27 @@ discard block |
||
| 1463 | 1484 | * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
| 1464 | 1485 | */ |
| 1465 | 1486 | function wp_get_sidebars_widgets( $deprecated = true ) { |
| 1466 | - if ( $deprecated !== true ) |
|
| 1467 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
| 1487 | + if ( $deprecated !== true ) { |
|
| 1488 | + _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
| 1489 | + } |
|
| 1468 | 1490 | |
| 1469 | 1491 | global $_wp_sidebars_widgets, $sidebars_widgets; |
| 1470 | 1492 | |
| 1471 | 1493 | // If loading from front page, consult $_wp_sidebars_widgets rather than options |
| 1472 | 1494 | // to see if wp_convert_widget_settings() has made manipulations in memory. |
| 1473 | 1495 | if ( !is_admin() ) { |
| 1474 | - if ( empty($_wp_sidebars_widgets) ) |
|
| 1475 | - $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
|
| 1496 | + if ( empty($_wp_sidebars_widgets) ) { |
|
| 1497 | + $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
|
| 1498 | + } |
|
| 1476 | 1499 | |
| 1477 | 1500 | $sidebars_widgets = $_wp_sidebars_widgets; |
| 1478 | 1501 | } else { |
| 1479 | 1502 | $sidebars_widgets = get_option('sidebars_widgets', array()); |
| 1480 | 1503 | } |
| 1481 | 1504 | |
| 1482 | - if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) |
|
| 1483 | - unset($sidebars_widgets['array_version']); |
|
| 1505 | + if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) { |
|
| 1506 | + unset($sidebars_widgets['array_version']); |
|
| 1507 | + } |
|
| 1484 | 1508 | |
| 1485 | 1509 | /** |
| 1486 | 1510 | * Filter the list of sidebars and their widgets. |
@@ -1501,8 +1525,9 @@ discard block |
||
| 1501 | 1525 | * @param array $sidebars_widgets Sidebar widgets and their settings. |
| 1502 | 1526 | */ |
| 1503 | 1527 | function wp_set_sidebars_widgets( $sidebars_widgets ) { |
| 1504 | - if ( !isset( $sidebars_widgets['array_version'] ) ) |
|
| 1505 | - $sidebars_widgets['array_version'] = 3; |
|
| 1528 | + if ( !isset( $sidebars_widgets['array_version'] ) ) { |
|
| 1529 | + $sidebars_widgets['array_version'] = 3; |
|
| 1530 | + } |
|
| 1506 | 1531 | update_option( 'sidebars_widgets', $sidebars_widgets ); |
| 1507 | 1532 | } |
| 1508 | 1533 | |
@@ -1521,8 +1546,9 @@ discard block |
||
| 1521 | 1546 | |
| 1522 | 1547 | $defaults = array(); |
| 1523 | 1548 | |
| 1524 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) |
|
| 1525 | - $defaults[$index] = array(); |
|
| 1549 | + foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
|
| 1550 | + $defaults[$index] = array(); |
|
| 1551 | + } |
|
| 1526 | 1552 | |
| 1527 | 1553 | return $defaults; |
| 1528 | 1554 | } |
@@ -1546,8 +1572,9 @@ discard block |
||
| 1546 | 1572 | $single = true; |
| 1547 | 1573 | } else { |
| 1548 | 1574 | foreach ( array_keys($settings) as $number ) { |
| 1549 | - if ( 'number' == $number ) |
|
| 1550 | - continue; |
|
| 1575 | + if ( 'number' == $number ) { |
|
| 1576 | + continue; |
|
| 1577 | + } |
|
| 1551 | 1578 | if ( !is_numeric($number) ) { |
| 1552 | 1579 | $single = true; |
| 1553 | 1580 | break; |
@@ -1562,8 +1589,9 @@ discard block |
||
| 1562 | 1589 | if ( is_admin() ) { |
| 1563 | 1590 | $sidebars_widgets = get_option('sidebars_widgets'); |
| 1564 | 1591 | } else { |
| 1565 | - if ( empty($GLOBALS['_wp_sidebars_widgets']) ) |
|
| 1566 | - $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
|
| 1592 | + if ( empty($GLOBALS['_wp_sidebars_widgets']) ) { |
|
| 1593 | + $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
|
| 1594 | + } |
|
| 1567 | 1595 | $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; |
| 1568 | 1596 | } |
| 1569 | 1597 | |
@@ -1579,13 +1607,15 @@ discard block |
||
| 1579 | 1607 | } |
| 1580 | 1608 | } |
| 1581 | 1609 | |
| 1582 | - if ( is_admin() && $changed ) |
|
| 1583 | - update_option('sidebars_widgets', $sidebars_widgets); |
|
| 1610 | + if ( is_admin() && $changed ) { |
|
| 1611 | + update_option('sidebars_widgets', $sidebars_widgets); |
|
| 1612 | + } |
|
| 1584 | 1613 | } |
| 1585 | 1614 | |
| 1586 | 1615 | $settings['_multiwidget'] = 1; |
| 1587 | - if ( is_admin() ) |
|
| 1588 | - update_option( $option_name, $settings ); |
|
| 1616 | + if ( is_admin() ) { |
|
| 1617 | + update_option( $option_name, $settings ); |
|
| 1618 | + } |
|
| 1589 | 1619 | |
| 1590 | 1620 | return $settings; |
| 1591 | 1621 | } |
@@ -1661,8 +1691,9 @@ discard block |
||
| 1661 | 1691 | function _wp_sidebars_changed() { |
| 1662 | 1692 | global $sidebars_widgets; |
| 1663 | 1693 | |
| 1664 | - if ( ! is_array( $sidebars_widgets ) ) |
|
| 1665 | - $sidebars_widgets = wp_get_sidebars_widgets(); |
|
| 1694 | + if ( ! is_array( $sidebars_widgets ) ) { |
|
| 1695 | + $sidebars_widgets = wp_get_sidebars_widgets(); |
|
| 1696 | + } |
|
| 1666 | 1697 | |
| 1667 | 1698 | retrieve_widgets(true); |
| 1668 | 1699 | } |
@@ -1706,8 +1737,9 @@ discard block |
||
| 1706 | 1737 | } |
| 1707 | 1738 | } |
| 1708 | 1739 | } else { |
| 1709 | - if ( empty( $sidebars_widgets ) ) |
|
| 1710 | - return; |
|
| 1740 | + if ( empty( $sidebars_widgets ) ) { |
|
| 1741 | + return; |
|
| 1742 | + } |
|
| 1711 | 1743 | |
| 1712 | 1744 | unset( $sidebars_widgets['array_version'] ); |
| 1713 | 1745 | |
@@ -1715,8 +1747,9 @@ discard block |
||
| 1715 | 1747 | sort($old); |
| 1716 | 1748 | sort($registered_sidebar_keys); |
| 1717 | 1749 | |
| 1718 | - if ( $old == $registered_sidebar_keys ) |
|
| 1719 | - return; |
|
| 1750 | + if ( $old == $registered_sidebar_keys ) { |
|
| 1751 | + return; |
|
| 1752 | + } |
|
| 1720 | 1753 | |
| 1721 | 1754 | $_sidebars_widgets = array( |
| 1722 | 1755 | 'wp_inactive_widgets' => !empty( $sidebars_widgets['wp_inactive_widgets'] ) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
@@ -1737,8 +1770,9 @@ discard block |
||
| 1737 | 1770 | } |
| 1738 | 1771 | |
| 1739 | 1772 | foreach ( $sidebars_widgets as $val ) { |
| 1740 | - if ( is_array($val) && ! empty( $val ) ) |
|
| 1741 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
| 1773 | + if ( is_array($val) && ! empty( $val ) ) { |
|
| 1774 | + $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
| 1775 | + } |
|
| 1742 | 1776 | } |
| 1743 | 1777 | } |
| 1744 | 1778 | |
@@ -1746,13 +1780,15 @@ discard block |
||
| 1746 | 1780 | $shown_widgets = array(); |
| 1747 | 1781 | |
| 1748 | 1782 | foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
| 1749 | - if ( !is_array($widgets) ) |
|
| 1750 | - continue; |
|
| 1783 | + if ( !is_array($widgets) ) { |
|
| 1784 | + continue; |
|
| 1785 | + } |
|
| 1751 | 1786 | |
| 1752 | 1787 | $_widgets = array(); |
| 1753 | 1788 | foreach ( $widgets as $widget ) { |
| 1754 | - if ( isset($wp_registered_widgets[$widget]) ) |
|
| 1755 | - $_widgets[] = $widget; |
|
| 1789 | + if ( isset($wp_registered_widgets[$widget]) ) { |
|
| 1790 | + $_widgets[] = $widget; |
|
| 1791 | + } |
|
| 1756 | 1792 | } |
| 1757 | 1793 | |
| 1758 | 1794 | $_sidebars_widgets[$sidebar] = $_widgets; |
@@ -1765,13 +1801,15 @@ discard block |
||
| 1765 | 1801 | // find hidden/lost multi-widget instances |
| 1766 | 1802 | $lost_widgets = array(); |
| 1767 | 1803 | foreach ( $wp_registered_widgets as $key => $val ) { |
| 1768 | - if ( in_array($key, $shown_widgets, true) ) |
|
| 1769 | - continue; |
|
| 1804 | + if ( in_array($key, $shown_widgets, true) ) { |
|
| 1805 | + continue; |
|
| 1806 | + } |
|
| 1770 | 1807 | |
| 1771 | 1808 | $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key); |
| 1772 | 1809 | |
| 1773 | - if ( 2 > (int) $number ) |
|
| 1774 | - continue; |
|
| 1810 | + if ( 2 > (int) $number ) { |
|
| 1811 | + continue; |
|
| 1812 | + } |
|
| 1775 | 1813 | |
| 1776 | 1814 | $lost_widgets[] = $key; |
| 1777 | 1815 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * |
| 655 | 655 | * @see wpdb::__construct() |
| 656 | 656 | * @since 2.0.8 |
| 657 | - * @return true |
|
| 657 | + * @return boolean |
|
| 658 | 658 | */ |
| 659 | 659 | public function __destruct() { |
| 660 | 660 | return true; |
@@ -1203,8 +1203,6 @@ discard block |
||
| 1203 | 1203 | * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like |
| 1204 | 1204 | * {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if |
| 1205 | 1205 | * being called like {@link http://php.net/sprintf sprintf()}. |
| 1206 | - * @param mixed $args,... further variables to substitute into the query's placeholders if being called like |
|
| 1207 | - * {@link http://php.net/sprintf sprintf()}. |
|
| 1208 | 1206 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1209 | 1207 | */ |
| 1210 | 1208 | public function prepare( $query, $args ) { |
@@ -1413,7 +1411,7 @@ discard block |
||
| 1413 | 1411 | * @since 3.9.0 $allow_bail parameter added. |
| 1414 | 1412 | * |
| 1415 | 1413 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1416 | - * @return bool True with a successful connection, false on failure. |
|
| 1414 | + * @return null|boolean True with a successful connection, false on failure. |
|
| 1417 | 1415 | */ |
| 1418 | 1416 | public function db_connect( $allow_bail = true ) { |
| 1419 | 1417 | $this->is_mysql = true; |
@@ -2960,7 +2958,7 @@ discard block |
||
| 2960 | 2958 | * |
| 2961 | 2959 | * @since 1.5.0 |
| 2962 | 2960 | * |
| 2963 | - * @return true |
|
| 2961 | + * @return boolean |
|
| 2964 | 2962 | */ |
| 2965 | 2963 | public function timer_start() { |
| 2966 | 2964 | $this->time_start = microtime( true ); |
@@ -3062,7 +3060,7 @@ discard block |
||
| 3062 | 3060 | * @param string $db_cap The feature to check for. Accepts 'collation', |
| 3063 | 3061 | * 'group_concat', 'subqueries', 'set_charset', |
| 3064 | 3062 | * or 'utf8mb4'. |
| 3065 | - * @return int|false Whether the database feature is supported, false otherwise. |
|
| 3063 | + * @return boolean Whether the database feature is supported, false otherwise. |
|
| 3066 | 3064 | */ |
| 3067 | 3065 | public function has_cap( $db_cap ) { |
| 3068 | 3066 | $version = $this->db_version(); |
@@ -3118,7 +3116,7 @@ discard block |
||
| 3118 | 3116 | * |
| 3119 | 3117 | * @since 2.7.0 |
| 3120 | 3118 | * |
| 3121 | - * @return null|string Null on failure, version number on success. |
|
| 3119 | + * @return string Null on failure, version number on success. |
|
| 3122 | 3120 | */ |
| 3123 | 3121 | public function db_version() { |
| 3124 | 3122 | if ( $this->use_mysqli ) { |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * WordPress DB Class |
|
| 4 | - * |
|
| 5 | - * Original code from {@link http://php.justinvincent.com Justin Vincent ([email protected])} |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Database |
|
| 9 | - * @since 0.71 |
|
| 10 | - */ |
|
| 3 | + * WordPress DB Class |
|
| 4 | + * |
|
| 5 | + * Original code from {@link http://php.justinvincent.com Justin Vincent ([email protected])} |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Database |
|
| 9 | + * @since 0.71 |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @since 0.71 |
@@ -12,28 +12,28 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @since 0.71 |
| 14 | 14 | */ |
| 15 | -define( 'EZSQL_VERSION', 'WP1.25' ); |
|
| 15 | +define('EZSQL_VERSION', 'WP1.25'); |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @since 0.71 |
| 19 | 19 | */ |
| 20 | -define( 'OBJECT', 'OBJECT' ); |
|
| 21 | -define( 'object', 'OBJECT' ); // Back compat. |
|
| 20 | +define('OBJECT', 'OBJECT'); |
|
| 21 | +define('object', 'OBJECT'); // Back compat. |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @since 2.5.0 |
| 25 | 25 | */ |
| 26 | -define( 'OBJECT_K', 'OBJECT_K' ); |
|
| 26 | +define('OBJECT_K', 'OBJECT_K'); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @since 0.71 |
| 30 | 30 | */ |
| 31 | -define( 'ARRAY_A', 'ARRAY_A' ); |
|
| 31 | +define('ARRAY_A', 'ARRAY_A'); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @since 0.71 |
| 35 | 35 | */ |
| 36 | -define( 'ARRAY_N', 'ARRAY_N' ); |
|
| 36 | +define('ARRAY_N', 'ARRAY_N'); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * WordPress Database Access Abstraction Object |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | * @see wpdb::tables() |
| 266 | 266 | * @var array |
| 267 | 267 | */ |
| 268 | - var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', |
|
| 269 | - 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); |
|
| 268 | + var $tables = array('posts', 'comments', 'links', 'options', 'postmeta', |
|
| 269 | + 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta'); |
|
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | 272 | * List of deprecated WordPress tables |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @see wpdb::tables() |
| 279 | 279 | * @var array |
| 280 | 280 | */ |
| 281 | - var $old_tables = array( 'categories', 'post2cat', 'link2cat' ); |
|
| 281 | + var $old_tables = array('categories', 'post2cat', 'link2cat'); |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * List of WordPress global tables |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @see wpdb::tables() |
| 289 | 289 | * @var array |
| 290 | 290 | */ |
| 291 | - var $global_tables = array( 'users', 'usermeta' ); |
|
| 291 | + var $global_tables = array('users', 'usermeta'); |
|
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * List of Multisite global tables |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @see wpdb::tables() |
| 299 | 299 | * @var array |
| 300 | 300 | */ |
| 301 | - var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', |
|
| 302 | - 'sitecategories', 'registration_log', 'blog_versions' ); |
|
| 301 | + var $ms_global_tables = array('blogs', 'signups', 'site', 'sitemeta', |
|
| 302 | + 'sitecategories', 'registration_log', 'blog_versions'); |
|
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * WordPress Comments table |
@@ -576,8 +576,8 @@ discard block |
||
| 576 | 576 | * @access protected |
| 577 | 577 | * @var array |
| 578 | 578 | */ |
| 579 | - protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', |
|
| 580 | - 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); |
|
| 579 | + protected $incompatible_modes = array('NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', |
|
| 580 | + 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL'); |
|
| 581 | 581 | |
| 582 | 582 | /** |
| 583 | 583 | * Whether to use mysqli over mysql. |
@@ -614,10 +614,10 @@ discard block |
||
| 614 | 614 | * @param string $dbname MySQL database name |
| 615 | 615 | * @param string $dbhost MySQL database host |
| 616 | 616 | */ |
| 617 | - public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { |
|
| 618 | - register_shutdown_function( array( $this, '__destruct' ) ); |
|
| 617 | + public function __construct($dbuser, $dbpassword, $dbname, $dbhost) { |
|
| 618 | + register_shutdown_function(array($this, '__destruct')); |
|
| 619 | 619 | |
| 620 | - if ( WP_DEBUG && WP_DEBUG_DISPLAY ) |
|
| 620 | + if (WP_DEBUG && WP_DEBUG_DISPLAY) |
|
| 621 | 621 | $this->show_errors(); |
| 622 | 622 | |
| 623 | 623 | /* Use ext/mysqli if it exists and: |
@@ -626,12 +626,12 @@ discard block |
||
| 626 | 626 | * - We are running PHP 5.5 or greater, or |
| 627 | 627 | * - ext/mysql is not loaded. |
| 628 | 628 | */ |
| 629 | - if ( function_exists( 'mysqli_connect' ) ) { |
|
| 630 | - if ( defined( 'WP_USE_EXT_MYSQL' ) ) { |
|
| 629 | + if (function_exists('mysqli_connect')) { |
|
| 630 | + if (defined('WP_USE_EXT_MYSQL')) { |
|
| 631 | 631 | $this->use_mysqli = ! WP_USE_EXT_MYSQL; |
| 632 | - } elseif ( version_compare( phpversion(), '5.5', '>=' ) || ! function_exists( 'mysql_connect' ) ) { |
|
| 632 | + } elseif (version_compare(phpversion(), '5.5', '>=') || ! function_exists('mysql_connect')) { |
|
| 633 | 633 | $this->use_mysqli = true; |
| 634 | - } elseif ( false !== strpos( $GLOBALS['wp_version'], '-' ) ) { |
|
| 634 | + } elseif (false !== strpos($GLOBALS['wp_version'], '-')) { |
|
| 635 | 635 | $this->use_mysqli = true; |
| 636 | 636 | } |
| 637 | 637 | } |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | $this->dbhost = $dbhost; |
| 643 | 643 | |
| 644 | 644 | // wp-config.php creation will manually connect when ready. |
| 645 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 645 | + if (defined('WP_SETUP_CONFIG')) { |
|
| 646 | 646 | return; |
| 647 | 647 | } |
| 648 | 648 | |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | * @param string $name The private member to get, and optionally process |
| 669 | 669 | * @return mixed The private member |
| 670 | 670 | */ |
| 671 | - public function __get( $name ) { |
|
| 672 | - if ( 'col_info' === $name ) |
|
| 671 | + public function __get($name) { |
|
| 672 | + if ('col_info' === $name) |
|
| 673 | 673 | $this->load_col_info(); |
| 674 | 674 | |
| 675 | 675 | return $this->$name; |
@@ -683,13 +683,13 @@ discard block |
||
| 683 | 683 | * @param string $name The private member to set |
| 684 | 684 | * @param mixed $value The value to set |
| 685 | 685 | */ |
| 686 | - public function __set( $name, $value ) { |
|
| 686 | + public function __set($name, $value) { |
|
| 687 | 687 | $protected_members = array( |
| 688 | 688 | 'col_meta', |
| 689 | 689 | 'table_charset', |
| 690 | 690 | 'check_current_query', |
| 691 | 691 | ); |
| 692 | - if ( in_array( $name, $protected_members, true ) ) { |
|
| 692 | + if (in_array($name, $protected_members, true)) { |
|
| 693 | 693 | return; |
| 694 | 694 | } |
| 695 | 695 | $this->$name = $value; |
@@ -704,8 +704,8 @@ discard block |
||
| 704 | 704 | * |
| 705 | 705 | * @return bool If the member is set or not |
| 706 | 706 | */ |
| 707 | - public function __isset( $name ) { |
|
| 708 | - return isset( $this->$name ); |
|
| 707 | + public function __isset($name) { |
|
| 708 | + return isset($this->$name); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | * |
| 716 | 716 | * @param string $name The private member to unset |
| 717 | 717 | */ |
| 718 | - public function __unset( $name ) { |
|
| 719 | - unset( $this->$name ); |
|
| 718 | + public function __unset($name) { |
|
| 719 | + unset($this->$name); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -725,30 +725,30 @@ discard block |
||
| 725 | 725 | * @since 3.1.0 |
| 726 | 726 | */ |
| 727 | 727 | public function init_charset() { |
| 728 | - if ( function_exists('is_multisite') && is_multisite() ) { |
|
| 728 | + if (function_exists('is_multisite') && is_multisite()) { |
|
| 729 | 729 | $this->charset = 'utf8'; |
| 730 | - if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) { |
|
| 730 | + if (defined('DB_COLLATE') && DB_COLLATE) { |
|
| 731 | 731 | $this->collate = DB_COLLATE; |
| 732 | 732 | } else { |
| 733 | 733 | $this->collate = 'utf8_general_ci'; |
| 734 | 734 | } |
| 735 | - } elseif ( defined( 'DB_COLLATE' ) ) { |
|
| 735 | + } elseif (defined('DB_COLLATE')) { |
|
| 736 | 736 | $this->collate = DB_COLLATE; |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - if ( defined( 'DB_CHARSET' ) ) { |
|
| 739 | + if (defined('DB_CHARSET')) { |
|
| 740 | 740 | $this->charset = DB_CHARSET; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) { |
|
| 743 | + if (($this->use_mysqli && ! ($this->dbh instanceof mysqli)) || empty($this->dbh)) { |
|
| 744 | 744 | return; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - if ( 'utf8' === $this->charset && $this->has_cap( 'utf8mb4' ) ) { |
|
| 747 | + if ('utf8' === $this->charset && $this->has_cap('utf8mb4')) { |
|
| 748 | 748 | $this->charset = 'utf8mb4'; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - if ( 'utf8mb4' === $this->charset && ( ! $this->collate || stripos( $this->collate, 'utf8_' ) === 0 ) ) { |
|
| 751 | + if ('utf8mb4' === $this->charset && ( ! $this->collate || stripos($this->collate, 'utf8_') === 0)) { |
|
| 752 | 752 | $this->collate = 'utf8mb4_unicode_ci'; |
| 753 | 753 | } |
| 754 | 754 | } |
@@ -762,29 +762,29 @@ discard block |
||
| 762 | 762 | * @param string $charset Optional. The character set. Default null. |
| 763 | 763 | * @param string $collate Optional. The collation. Default null. |
| 764 | 764 | */ |
| 765 | - public function set_charset( $dbh, $charset = null, $collate = null ) { |
|
| 766 | - if ( ! isset( $charset ) ) |
|
| 765 | + public function set_charset($dbh, $charset = null, $collate = null) { |
|
| 766 | + if ( ! isset($charset)) |
|
| 767 | 767 | $charset = $this->charset; |
| 768 | - if ( ! isset( $collate ) ) |
|
| 768 | + if ( ! isset($collate)) |
|
| 769 | 769 | $collate = $this->collate; |
| 770 | - if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { |
|
| 771 | - if ( $this->use_mysqli ) { |
|
| 772 | - if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
|
| 773 | - mysqli_set_charset( $dbh, $charset ); |
|
| 770 | + if ($this->has_cap('collation') && ! empty($charset)) { |
|
| 771 | + if ($this->use_mysqli) { |
|
| 772 | + if (function_exists('mysqli_set_charset') && $this->has_cap('set_charset')) { |
|
| 773 | + mysqli_set_charset($dbh, $charset); |
|
| 774 | 774 | } else { |
| 775 | - $query = $this->prepare( 'SET NAMES %s', $charset ); |
|
| 776 | - if ( ! empty( $collate ) ) |
|
| 777 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 778 | - mysqli_query( $dbh, $query ); |
|
| 775 | + $query = $this->prepare('SET NAMES %s', $charset); |
|
| 776 | + if ( ! empty($collate)) |
|
| 777 | + $query .= $this->prepare(' COLLATE %s', $collate); |
|
| 778 | + mysqli_query($dbh, $query); |
|
| 779 | 779 | } |
| 780 | 780 | } else { |
| 781 | - if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
|
| 782 | - mysql_set_charset( $charset, $dbh ); |
|
| 781 | + if (function_exists('mysql_set_charset') && $this->has_cap('set_charset')) { |
|
| 782 | + mysql_set_charset($charset, $dbh); |
|
| 783 | 783 | } else { |
| 784 | - $query = $this->prepare( 'SET NAMES %s', $charset ); |
|
| 785 | - if ( ! empty( $collate ) ) |
|
| 786 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 787 | - mysql_query( $query, $dbh ); |
|
| 784 | + $query = $this->prepare('SET NAMES %s', $charset); |
|
| 785 | + if ( ! empty($collate)) |
|
| 786 | + $query .= $this->prepare(' COLLATE %s', $collate); |
|
| 787 | + mysql_query($query, $dbh); |
|
| 788 | 788 | } |
| 789 | 789 | } |
| 790 | 790 | } |
@@ -800,36 +800,36 @@ discard block |
||
| 800 | 800 | * |
| 801 | 801 | * @param array $modes Optional. A list of SQL modes to set. |
| 802 | 802 | */ |
| 803 | - public function set_sql_mode( $modes = array() ) { |
|
| 804 | - if ( empty( $modes ) ) { |
|
| 805 | - if ( $this->use_mysqli ) { |
|
| 806 | - $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' ); |
|
| 803 | + public function set_sql_mode($modes = array()) { |
|
| 804 | + if (empty($modes)) { |
|
| 805 | + if ($this->use_mysqli) { |
|
| 806 | + $res = mysqli_query($this->dbh, 'SELECT @@SESSION.sql_mode'); |
|
| 807 | 807 | } else { |
| 808 | - $res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh ); |
|
| 808 | + $res = mysql_query('SELECT @@SESSION.sql_mode', $this->dbh); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - if ( empty( $res ) ) { |
|
| 811 | + if (empty($res)) { |
|
| 812 | 812 | return; |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | - if ( $this->use_mysqli ) { |
|
| 816 | - $modes_array = mysqli_fetch_array( $res ); |
|
| 817 | - if ( empty( $modes_array[0] ) ) { |
|
| 815 | + if ($this->use_mysqli) { |
|
| 816 | + $modes_array = mysqli_fetch_array($res); |
|
| 817 | + if (empty($modes_array[0])) { |
|
| 818 | 818 | return; |
| 819 | 819 | } |
| 820 | 820 | $modes_str = $modes_array[0]; |
| 821 | 821 | } else { |
| 822 | - $modes_str = mysql_result( $res, 0 ); |
|
| 822 | + $modes_str = mysql_result($res, 0); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - if ( empty( $modes_str ) ) { |
|
| 825 | + if (empty($modes_str)) { |
|
| 826 | 826 | return; |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - $modes = explode( ',', $modes_str ); |
|
| 829 | + $modes = explode(',', $modes_str); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | - $modes = array_change_key_case( $modes, CASE_UPPER ); |
|
| 832 | + $modes = array_change_key_case($modes, CASE_UPPER); |
|
| 833 | 833 | |
| 834 | 834 | /** |
| 835 | 835 | * Filter the list of incompatible SQL modes to exclude. |
@@ -838,20 +838,20 @@ discard block |
||
| 838 | 838 | * |
| 839 | 839 | * @param array $incompatible_modes An array of incompatible modes. |
| 840 | 840 | */ |
| 841 | - $incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes ); |
|
| 841 | + $incompatible_modes = (array) apply_filters('incompatible_sql_modes', $this->incompatible_modes); |
|
| 842 | 842 | |
| 843 | - foreach( $modes as $i => $mode ) { |
|
| 844 | - if ( in_array( $mode, $incompatible_modes ) ) { |
|
| 845 | - unset( $modes[ $i ] ); |
|
| 843 | + foreach ($modes as $i => $mode) { |
|
| 844 | + if (in_array($mode, $incompatible_modes)) { |
|
| 845 | + unset($modes[$i]); |
|
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - $modes_str = implode( ',', $modes ); |
|
| 849 | + $modes_str = implode(',', $modes); |
|
| 850 | 850 | |
| 851 | - if ( $this->use_mysqli ) { |
|
| 852 | - mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" ); |
|
| 851 | + if ($this->use_mysqli) { |
|
| 852 | + mysqli_query($this->dbh, "SET SESSION sql_mode='$modes_str'"); |
|
| 853 | 853 | } else { |
| 854 | - mysql_query( "SET SESSION sql_mode='$modes_str'", $this->dbh ); |
|
| 854 | + mysql_query("SET SESSION sql_mode='$modes_str'", $this->dbh); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | |
@@ -864,31 +864,31 @@ discard block |
||
| 864 | 864 | * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not. |
| 865 | 865 | * @return string|WP_Error Old prefix or WP_Error on error |
| 866 | 866 | */ |
| 867 | - public function set_prefix( $prefix, $set_table_names = true ) { |
|
| 867 | + public function set_prefix($prefix, $set_table_names = true) { |
|
| 868 | 868 | |
| 869 | - if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) |
|
| 870 | - return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 869 | + if (preg_match('|[^a-z0-9_]|i', $prefix)) |
|
| 870 | + return new WP_Error('invalid_db_prefix', 'Invalid database prefix'); |
|
| 871 | 871 | |
| 872 | 872 | $old_prefix = is_multisite() ? '' : $prefix; |
| 873 | 873 | |
| 874 | - if ( isset( $this->base_prefix ) ) |
|
| 874 | + if (isset($this->base_prefix)) |
|
| 875 | 875 | $old_prefix = $this->base_prefix; |
| 876 | 876 | |
| 877 | 877 | $this->base_prefix = $prefix; |
| 878 | 878 | |
| 879 | - if ( $set_table_names ) { |
|
| 880 | - foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) |
|
| 879 | + if ($set_table_names) { |
|
| 880 | + foreach ($this->tables('global') as $table => $prefixed_table) |
|
| 881 | 881 | $this->$table = $prefixed_table; |
| 882 | 882 | |
| 883 | - if ( is_multisite() && empty( $this->blogid ) ) |
|
| 883 | + if (is_multisite() && empty($this->blogid)) |
|
| 884 | 884 | return $old_prefix; |
| 885 | 885 | |
| 886 | 886 | $this->prefix = $this->get_blog_prefix(); |
| 887 | 887 | |
| 888 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 888 | + foreach ($this->tables('blog') as $table => $prefixed_table) |
|
| 889 | 889 | $this->$table = $prefixed_table; |
| 890 | 890 | |
| 891 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 891 | + foreach ($this->tables('old') as $table => $prefixed_table) |
|
| 892 | 892 | $this->$table = $prefixed_table; |
| 893 | 893 | } |
| 894 | 894 | return $old_prefix; |
@@ -904,8 +904,8 @@ discard block |
||
| 904 | 904 | * @param int $site_id Optional. |
| 905 | 905 | * @return int previous blog id |
| 906 | 906 | */ |
| 907 | - public function set_blog_id( $blog_id, $site_id = 0 ) { |
|
| 908 | - if ( ! empty( $site_id ) ) |
|
| 907 | + public function set_blog_id($blog_id, $site_id = 0) { |
|
| 908 | + if ( ! empty($site_id)) |
|
| 909 | 909 | $this->siteid = $site_id; |
| 910 | 910 | |
| 911 | 911 | $old_blog_id = $this->blogid; |
@@ -913,10 +913,10 @@ discard block |
||
| 913 | 913 | |
| 914 | 914 | $this->prefix = $this->get_blog_prefix(); |
| 915 | 915 | |
| 916 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 916 | + foreach ($this->tables('blog') as $table => $prefixed_table) |
|
| 917 | 917 | $this->$table = $prefixed_table; |
| 918 | 918 | |
| 919 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 919 | + foreach ($this->tables('old') as $table => $prefixed_table) |
|
| 920 | 920 | $this->$table = $prefixed_table; |
| 921 | 921 | |
| 922 | 922 | return $old_blog_id; |
@@ -929,15 +929,15 @@ discard block |
||
| 929 | 929 | * @param int $blog_id Optional. |
| 930 | 930 | * @return string Blog prefix. |
| 931 | 931 | */ |
| 932 | - public function get_blog_prefix( $blog_id = null ) { |
|
| 933 | - if ( is_multisite() ) { |
|
| 934 | - if ( null === $blog_id ) |
|
| 932 | + public function get_blog_prefix($blog_id = null) { |
|
| 933 | + if (is_multisite()) { |
|
| 934 | + if (null === $blog_id) |
|
| 935 | 935 | $blog_id = $this->blogid; |
| 936 | 936 | $blog_id = (int) $blog_id; |
| 937 | - if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) |
|
| 937 | + if (defined('MULTISITE') && (0 == $blog_id || 1 == $blog_id)) |
|
| 938 | 938 | return $this->base_prefix; |
| 939 | 939 | else |
| 940 | - return $this->base_prefix . $blog_id . '_'; |
|
| 940 | + return $this->base_prefix.$blog_id.'_'; |
|
| 941 | 941 | } else { |
| 942 | 942 | return $this->base_prefix; |
| 943 | 943 | } |
@@ -970,20 +970,20 @@ discard block |
||
| 970 | 970 | * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. |
| 971 | 971 | * @return array Table names. When a prefix is requested, the key is the unprefixed table name. |
| 972 | 972 | */ |
| 973 | - public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { |
|
| 974 | - switch ( $scope ) { |
|
| 973 | + public function tables($scope = 'all', $prefix = true, $blog_id = 0) { |
|
| 974 | + switch ($scope) { |
|
| 975 | 975 | case 'all' : |
| 976 | - $tables = array_merge( $this->global_tables, $this->tables ); |
|
| 977 | - if ( is_multisite() ) |
|
| 978 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 976 | + $tables = array_merge($this->global_tables, $this->tables); |
|
| 977 | + if (is_multisite()) |
|
| 978 | + $tables = array_merge($tables, $this->ms_global_tables); |
|
| 979 | 979 | break; |
| 980 | 980 | case 'blog' : |
| 981 | 981 | $tables = $this->tables; |
| 982 | 982 | break; |
| 983 | 983 | case 'global' : |
| 984 | 984 | $tables = $this->global_tables; |
| 985 | - if ( is_multisite() ) |
|
| 986 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 985 | + if (is_multisite()) |
|
| 986 | + $tables = array_merge($tables, $this->ms_global_tables); |
|
| 987 | 987 | break; |
| 988 | 988 | case 'ms_global' : |
| 989 | 989 | $tables = $this->ms_global_tables; |
@@ -995,24 +995,24 @@ discard block |
||
| 995 | 995 | return array(); |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | - if ( $prefix ) { |
|
| 999 | - if ( ! $blog_id ) |
|
| 998 | + if ($prefix) { |
|
| 999 | + if ( ! $blog_id) |
|
| 1000 | 1000 | $blog_id = $this->blogid; |
| 1001 | - $blog_prefix = $this->get_blog_prefix( $blog_id ); |
|
| 1001 | + $blog_prefix = $this->get_blog_prefix($blog_id); |
|
| 1002 | 1002 | $base_prefix = $this->base_prefix; |
| 1003 | - $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); |
|
| 1004 | - foreach ( $tables as $k => $table ) { |
|
| 1005 | - if ( in_array( $table, $global_tables ) ) |
|
| 1006 | - $tables[ $table ] = $base_prefix . $table; |
|
| 1003 | + $global_tables = array_merge($this->global_tables, $this->ms_global_tables); |
|
| 1004 | + foreach ($tables as $k => $table) { |
|
| 1005 | + if (in_array($table, $global_tables)) |
|
| 1006 | + $tables[$table] = $base_prefix.$table; |
|
| 1007 | 1007 | else |
| 1008 | - $tables[ $table ] = $blog_prefix . $table; |
|
| 1009 | - unset( $tables[ $k ] ); |
|
| 1008 | + $tables[$table] = $blog_prefix.$table; |
|
| 1009 | + unset($tables[$k]); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) |
|
| 1012 | + if (isset($tables['users']) && defined('CUSTOM_USER_TABLE')) |
|
| 1013 | 1013 | $tables['users'] = CUSTOM_USER_TABLE; |
| 1014 | 1014 | |
| 1015 | - if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) |
|
| 1015 | + if (isset($tables['usermeta']) && defined('CUSTOM_USER_META_TABLE')) |
|
| 1016 | 1016 | $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
| 1017 | 1017 | } |
| 1018 | 1018 | |
@@ -1030,27 +1030,27 @@ discard block |
||
| 1030 | 1030 | * @param string $db MySQL database name |
| 1031 | 1031 | * @param resource|null $dbh Optional link identifier. |
| 1032 | 1032 | */ |
| 1033 | - public function select( $db, $dbh = null ) { |
|
| 1034 | - if ( is_null($dbh) ) |
|
| 1033 | + public function select($db, $dbh = null) { |
|
| 1034 | + if (is_null($dbh)) |
|
| 1035 | 1035 | $dbh = $this->dbh; |
| 1036 | 1036 | |
| 1037 | - if ( $this->use_mysqli ) { |
|
| 1038 | - $success = @mysqli_select_db( $dbh, $db ); |
|
| 1037 | + if ($this->use_mysqli) { |
|
| 1038 | + $success = @mysqli_select_db($dbh, $db); |
|
| 1039 | 1039 | } else { |
| 1040 | - $success = @mysql_select_db( $db, $dbh ); |
|
| 1040 | + $success = @mysql_select_db($db, $dbh); |
|
| 1041 | 1041 | } |
| 1042 | - if ( ! $success ) { |
|
| 1042 | + if ( ! $success) { |
|
| 1043 | 1043 | $this->ready = false; |
| 1044 | - if ( ! did_action( 'template_redirect' ) ) { |
|
| 1044 | + if ( ! did_action('template_redirect')) { |
|
| 1045 | 1045 | wp_load_translations_early(); |
| 1046 | - $this->bail( sprintf( __( '<h1>Can’t select database</h1> |
|
| 1046 | + $this->bail(sprintf(__('<h1>Can’t select database</h1> |
|
| 1047 | 1047 | <p>We were able to connect to the database server (which means your username and password is okay) but not able to select the <code>%1$s</code> database.</p> |
| 1048 | 1048 | <ul> |
| 1049 | 1049 | <li>Are you sure it exists?</li> |
| 1050 | 1050 | <li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li> |
| 1051 | 1051 | <li>On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?</li> |
| 1052 | 1052 | </ul> |
| 1053 | -<p>If you don\'t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="https://wordpress.org/support/">WordPress Support Forums</a>.</p>' ), htmlspecialchars( $db, ENT_QUOTES ), htmlspecialchars( $this->dbuser, ENT_QUOTES ) ), 'db_select_fail' ); |
|
| 1053 | +<p>If you don\'t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="https://wordpress.org/support/">WordPress Support Forums</a>.</p>' ), htmlspecialchars($db, ENT_QUOTES), htmlspecialchars($this->dbuser, ENT_QUOTES)), 'db_select_fail'); |
|
| 1054 | 1054 | } |
| 1055 | 1055 | } |
| 1056 | 1056 | } |
@@ -1069,10 +1069,10 @@ discard block |
||
| 1069 | 1069 | * @param string $string |
| 1070 | 1070 | * @return string |
| 1071 | 1071 | */ |
| 1072 | - function _weak_escape( $string ) { |
|
| 1073 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1074 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1075 | - return addslashes( $string ); |
|
| 1072 | + function _weak_escape($string) { |
|
| 1073 | + if (func_num_args() === 1 && function_exists('_deprecated_function')) |
|
| 1074 | + _deprecated_function(__METHOD__, '3.6', 'wpdb::prepare() or esc_sql()'); |
|
| 1075 | + return addslashes($string); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1086,22 +1086,22 @@ discard block |
||
| 1086 | 1086 | * @param string $string to escape |
| 1087 | 1087 | * @return string escaped |
| 1088 | 1088 | */ |
| 1089 | - function _real_escape( $string ) { |
|
| 1090 | - if ( $this->dbh ) { |
|
| 1091 | - if ( $this->use_mysqli ) { |
|
| 1092 | - return mysqli_real_escape_string( $this->dbh, $string ); |
|
| 1089 | + function _real_escape($string) { |
|
| 1090 | + if ($this->dbh) { |
|
| 1091 | + if ($this->use_mysqli) { |
|
| 1092 | + return mysqli_real_escape_string($this->dbh, $string); |
|
| 1093 | 1093 | } else { |
| 1094 | - return mysql_real_escape_string( $string, $this->dbh ); |
|
| 1094 | + return mysql_real_escape_string($string, $this->dbh); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - $class = get_class( $this ); |
|
| 1099 | - if ( function_exists( '__' ) ) { |
|
| 1100 | - _doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), E_USER_NOTICE ); |
|
| 1098 | + $class = get_class($this); |
|
| 1099 | + if (function_exists('__')) { |
|
| 1100 | + _doing_it_wrong($class, sprintf(__('%s must set a database connection for use with escaping.'), $class), E_USER_NOTICE); |
|
| 1101 | 1101 | } else { |
| 1102 | - _doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), E_USER_NOTICE ); |
|
| 1102 | + _doing_it_wrong($class, sprintf('%s must set a database connection for use with escaping.', $class), E_USER_NOTICE); |
|
| 1103 | 1103 | } |
| 1104 | - return addslashes( $string ); |
|
| 1104 | + return addslashes($string); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | /** |
@@ -1114,16 +1114,16 @@ discard block |
||
| 1114 | 1114 | * @param string|array $data |
| 1115 | 1115 | * @return string|array escaped |
| 1116 | 1116 | */ |
| 1117 | - function _escape( $data ) { |
|
| 1118 | - if ( is_array( $data ) ) { |
|
| 1119 | - foreach ( $data as $k => $v ) { |
|
| 1120 | - if ( is_array($v) ) |
|
| 1121 | - $data[$k] = $this->_escape( $v ); |
|
| 1117 | + function _escape($data) { |
|
| 1118 | + if (is_array($data)) { |
|
| 1119 | + foreach ($data as $k => $v) { |
|
| 1120 | + if (is_array($v)) |
|
| 1121 | + $data[$k] = $this->_escape($v); |
|
| 1122 | 1122 | else |
| 1123 | - $data[$k] = $this->_real_escape( $v ); |
|
| 1123 | + $data[$k] = $this->_real_escape($v); |
|
| 1124 | 1124 | } |
| 1125 | 1125 | } else { |
| 1126 | - $data = $this->_real_escape( $data ); |
|
| 1126 | + $data = $this->_real_escape($data); |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | return $data; |
@@ -1142,18 +1142,18 @@ discard block |
||
| 1142 | 1142 | * @param mixed $data |
| 1143 | 1143 | * @return mixed |
| 1144 | 1144 | */ |
| 1145 | - public function escape( $data ) { |
|
| 1146 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1147 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1148 | - if ( is_array( $data ) ) { |
|
| 1149 | - foreach ( $data as $k => $v ) { |
|
| 1150 | - if ( is_array( $v ) ) |
|
| 1151 | - $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1145 | + public function escape($data) { |
|
| 1146 | + if (func_num_args() === 1 && function_exists('_deprecated_function')) |
|
| 1147 | + _deprecated_function(__METHOD__, '3.6', 'wpdb::prepare() or esc_sql()'); |
|
| 1148 | + if (is_array($data)) { |
|
| 1149 | + foreach ($data as $k => $v) { |
|
| 1150 | + if (is_array($v)) |
|
| 1151 | + $data[$k] = $this->escape($v, 'recursive'); |
|
| 1152 | 1152 | else |
| 1153 | - $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1153 | + $data[$k] = $this->_weak_escape($v, 'internal'); |
|
| 1154 | 1154 | } |
| 1155 | 1155 | } else { |
| 1156 | - $data = $this->_weak_escape( $data, 'internal' ); |
|
| 1156 | + $data = $this->_weak_escape($data, 'internal'); |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | return $data; |
@@ -1168,9 +1168,9 @@ discard block |
||
| 1168 | 1168 | * |
| 1169 | 1169 | * @param string $string to escape |
| 1170 | 1170 | */ |
| 1171 | - public function escape_by_ref( &$string ) { |
|
| 1172 | - if ( ! is_float( $string ) ) |
|
| 1173 | - $string = $this->_real_escape( $string ); |
|
| 1171 | + public function escape_by_ref(&$string) { |
|
| 1172 | + if ( ! is_float($string)) |
|
| 1173 | + $string = $this->_real_escape($string); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | /** |
@@ -1207,26 +1207,26 @@ discard block |
||
| 1207 | 1207 | * {@link http://php.net/sprintf sprintf()}. |
| 1208 | 1208 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1209 | 1209 | */ |
| 1210 | - public function prepare( $query, $args ) { |
|
| 1211 | - if ( is_null( $query ) ) |
|
| 1210 | + public function prepare($query, $args) { |
|
| 1211 | + if (is_null($query)) |
|
| 1212 | 1212 | return; |
| 1213 | 1213 | |
| 1214 | 1214 | // This is not meant to be foolproof -- but it will catch obviously incorrect usage. |
| 1215 | - if ( strpos( $query, '%' ) === false ) { |
|
| 1216 | - _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9' ); |
|
| 1215 | + if (strpos($query, '%') === false) { |
|
| 1216 | + _doing_it_wrong('wpdb::prepare', sprintf(__('The query argument of %s must have a placeholder.'), 'wpdb::prepare()'), '3.9'); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | $args = func_get_args(); |
| 1220 | - array_shift( $args ); |
|
| 1220 | + array_shift($args); |
|
| 1221 | 1221 | // If args were passed as an array (as in vsprintf), move them up |
| 1222 | - if ( isset( $args[0] ) && is_array($args[0]) ) |
|
| 1222 | + if (isset($args[0]) && is_array($args[0])) |
|
| 1223 | 1223 | $args = $args[0]; |
| 1224 | - $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it |
|
| 1225 | - $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting |
|
| 1226 | - $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware |
|
| 1227 | - $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s |
|
| 1228 | - array_walk( $args, array( $this, 'escape_by_ref' ) ); |
|
| 1229 | - return @vsprintf( $query, $args ); |
|
| 1224 | + $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it |
|
| 1225 | + $query = str_replace('"%s"', '%s', $query); // doublequote unquoting |
|
| 1226 | + $query = preg_replace('|(?<!%)%f|', '%F', $query); // Force floats to be locale unaware |
|
| 1227 | + $query = preg_replace('|(?<!%)%s|', "'%s'", $query); // quote the strings, avoiding escaped strings like %%s |
|
| 1228 | + array_walk($args, array($this, 'escape_by_ref')); |
|
| 1229 | + return @vsprintf($query, $args); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1251,8 +1251,8 @@ discard block |
||
| 1251 | 1251 | * @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare() |
| 1252 | 1252 | * or real_escape next. |
| 1253 | 1253 | */ |
| 1254 | - public function esc_like( $text ) { |
|
| 1255 | - return addcslashes( $text, '_%\\' ); |
|
| 1254 | + public function esc_like($text) { |
|
| 1255 | + return addcslashes($text, '_%\\'); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
@@ -1264,56 +1264,56 @@ discard block |
||
| 1264 | 1264 | * @param string $str The error to display |
| 1265 | 1265 | * @return false|void False if the showing of errors is disabled. |
| 1266 | 1266 | */ |
| 1267 | - public function print_error( $str = '' ) { |
|
| 1267 | + public function print_error($str = '') { |
|
| 1268 | 1268 | global $EZSQL_ERROR; |
| 1269 | 1269 | |
| 1270 | - if ( !$str ) { |
|
| 1271 | - if ( $this->use_mysqli ) { |
|
| 1272 | - $str = mysqli_error( $this->dbh ); |
|
| 1270 | + if ( ! $str) { |
|
| 1271 | + if ($this->use_mysqli) { |
|
| 1272 | + $str = mysqli_error($this->dbh); |
|
| 1273 | 1273 | } else { |
| 1274 | - $str = mysql_error( $this->dbh ); |
|
| 1274 | + $str = mysql_error($this->dbh); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | } |
| 1277 | - $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); |
|
| 1277 | + $EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str); |
|
| 1278 | 1278 | |
| 1279 | - if ( $this->suppress_errors ) |
|
| 1279 | + if ($this->suppress_errors) |
|
| 1280 | 1280 | return false; |
| 1281 | 1281 | |
| 1282 | 1282 | wp_load_translations_early(); |
| 1283 | 1283 | |
| 1284 | - if ( $caller = $this->get_caller() ) |
|
| 1285 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1284 | + if ($caller = $this->get_caller()) |
|
| 1285 | + $error_str = sprintf(__('WordPress database error %1$s for query %2$s made by %3$s'), $str, $this->last_query, $caller); |
|
| 1286 | 1286 | else |
| 1287 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1287 | + $error_str = sprintf(__('WordPress database error %1$s for query %2$s'), $str, $this->last_query); |
|
| 1288 | 1288 | |
| 1289 | - error_log( $error_str ); |
|
| 1289 | + error_log($error_str); |
|
| 1290 | 1290 | |
| 1291 | 1291 | // Are we showing errors? |
| 1292 | - if ( ! $this->show_errors ) |
|
| 1292 | + if ( ! $this->show_errors) |
|
| 1293 | 1293 | return false; |
| 1294 | 1294 | |
| 1295 | 1295 | // If there is an error then take note of it |
| 1296 | - if ( is_multisite() ) { |
|
| 1296 | + if (is_multisite()) { |
|
| 1297 | 1297 | $msg = sprintf( |
| 1298 | 1298 | "%s [%s]\n%s\n", |
| 1299 | - __( 'WordPress database error:' ), |
|
| 1299 | + __('WordPress database error:'), |
|
| 1300 | 1300 | $str, |
| 1301 | 1301 | $this->last_query |
| 1302 | 1302 | ); |
| 1303 | 1303 | |
| 1304 | - if ( defined( 'ERRORLOGFILE' ) ) { |
|
| 1305 | - error_log( $msg, 3, ERRORLOGFILE ); |
|
| 1304 | + if (defined('ERRORLOGFILE')) { |
|
| 1305 | + error_log($msg, 3, ERRORLOGFILE); |
|
| 1306 | 1306 | } |
| 1307 | - if ( defined( 'DIEONDBERROR' ) ) { |
|
| 1308 | - wp_die( $msg ); |
|
| 1307 | + if (defined('DIEONDBERROR')) { |
|
| 1308 | + wp_die($msg); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | } else { |
| 1311 | - $str = htmlspecialchars( $str, ENT_QUOTES ); |
|
| 1312 | - $query = htmlspecialchars( $this->last_query, ENT_QUOTES ); |
|
| 1311 | + $str = htmlspecialchars($str, ENT_QUOTES); |
|
| 1312 | + $query = htmlspecialchars($this->last_query, ENT_QUOTES); |
|
| 1313 | 1313 | |
| 1314 | 1314 | printf( |
| 1315 | 1315 | '<div id="error"><p class="wpdberror"><strong>%s</strong> [%s]<br /><code>%s</code></p></div>', |
| 1316 | - __( 'WordPress database error:' ), |
|
| 1316 | + __('WordPress database error:'), |
|
| 1317 | 1317 | $str, |
| 1318 | 1318 | $query |
| 1319 | 1319 | ); |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | * @param bool $show Whether to show or hide errors |
| 1335 | 1335 | * @return bool Old value for showing errors. |
| 1336 | 1336 | */ |
| 1337 | - public function show_errors( $show = true ) { |
|
| 1337 | + public function show_errors($show = true) { |
|
| 1338 | 1338 | $errors = $this->show_errors; |
| 1339 | 1339 | $this->show_errors = $show; |
| 1340 | 1340 | return $errors; |
@@ -1367,7 +1367,7 @@ discard block |
||
| 1367 | 1367 | * @param bool $suppress Optional. New value. Defaults to true. |
| 1368 | 1368 | * @return bool Old value |
| 1369 | 1369 | */ |
| 1370 | - public function suppress_errors( $suppress = true ) { |
|
| 1370 | + public function suppress_errors($suppress = true) { |
|
| 1371 | 1371 | $errors = $this->suppress_errors; |
| 1372 | 1372 | $this->suppress_errors = (bool) $suppress; |
| 1373 | 1373 | return $errors; |
@@ -1385,21 +1385,21 @@ discard block |
||
| 1385 | 1385 | $this->rows_affected = $this->num_rows = 0; |
| 1386 | 1386 | $this->last_error = ''; |
| 1387 | 1387 | |
| 1388 | - if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { |
|
| 1389 | - mysqli_free_result( $this->result ); |
|
| 1388 | + if ($this->use_mysqli && $this->result instanceof mysqli_result) { |
|
| 1389 | + mysqli_free_result($this->result); |
|
| 1390 | 1390 | $this->result = null; |
| 1391 | 1391 | |
| 1392 | 1392 | // Sanity check before using the handle |
| 1393 | - if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) ) { |
|
| 1393 | + if (empty($this->dbh) || ! ($this->dbh instanceof mysqli)) { |
|
| 1394 | 1394 | return; |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | // Clear out any results from a multi-query |
| 1398 | - while ( mysqli_more_results( $this->dbh ) ) { |
|
| 1399 | - mysqli_next_result( $this->dbh ); |
|
| 1398 | + while (mysqli_more_results($this->dbh)) { |
|
| 1399 | + mysqli_next_result($this->dbh); |
|
| 1400 | 1400 | } |
| 1401 | - } elseif ( is_resource( $this->result ) ) { |
|
| 1402 | - mysql_free_result( $this->result ); |
|
| 1401 | + } elseif (is_resource($this->result)) { |
|
| 1402 | + mysql_free_result($this->result); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | } |
| 1405 | 1405 | |
@@ -1415,17 +1415,17 @@ discard block |
||
| 1415 | 1415 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1416 | 1416 | * @return bool True with a successful connection, false on failure. |
| 1417 | 1417 | */ |
| 1418 | - public function db_connect( $allow_bail = true ) { |
|
| 1418 | + public function db_connect($allow_bail = true) { |
|
| 1419 | 1419 | $this->is_mysql = true; |
| 1420 | 1420 | |
| 1421 | 1421 | /* |
| 1422 | 1422 | * Deprecated in 3.9+ when using MySQLi. No equivalent |
| 1423 | 1423 | * $new_link parameter exists for mysqli_* functions. |
| 1424 | 1424 | */ |
| 1425 | - $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; |
|
| 1426 | - $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; |
|
| 1425 | + $new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true; |
|
| 1426 | + $client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0; |
|
| 1427 | 1427 | |
| 1428 | - if ( $this->use_mysqli ) { |
|
| 1428 | + if ($this->use_mysqli) { |
|
| 1429 | 1429 | $this->dbh = mysqli_init(); |
| 1430 | 1430 | |
| 1431 | 1431 | // mysqli_real_connect doesn't support the host param including a port or socket |
@@ -1433,28 +1433,28 @@ discard block |
||
| 1433 | 1433 | $port = null; |
| 1434 | 1434 | $socket = null; |
| 1435 | 1435 | $host = $this->dbhost; |
| 1436 | - $port_or_socket = strstr( $host, ':' ); |
|
| 1437 | - if ( ! empty( $port_or_socket ) ) { |
|
| 1438 | - $host = substr( $host, 0, strpos( $host, ':' ) ); |
|
| 1439 | - $port_or_socket = substr( $port_or_socket, 1 ); |
|
| 1440 | - if ( 0 !== strpos( $port_or_socket, '/' ) ) { |
|
| 1441 | - $port = intval( $port_or_socket ); |
|
| 1442 | - $maybe_socket = strstr( $port_or_socket, ':' ); |
|
| 1443 | - if ( ! empty( $maybe_socket ) ) { |
|
| 1444 | - $socket = substr( $maybe_socket, 1 ); |
|
| 1436 | + $port_or_socket = strstr($host, ':'); |
|
| 1437 | + if ( ! empty($port_or_socket)) { |
|
| 1438 | + $host = substr($host, 0, strpos($host, ':')); |
|
| 1439 | + $port_or_socket = substr($port_or_socket, 1); |
|
| 1440 | + if (0 !== strpos($port_or_socket, '/')) { |
|
| 1441 | + $port = intval($port_or_socket); |
|
| 1442 | + $maybe_socket = strstr($port_or_socket, ':'); |
|
| 1443 | + if ( ! empty($maybe_socket)) { |
|
| 1444 | + $socket = substr($maybe_socket, 1); |
|
| 1445 | 1445 | } |
| 1446 | 1446 | } else { |
| 1447 | 1447 | $socket = $port_or_socket; |
| 1448 | 1448 | } |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - if ( WP_DEBUG ) { |
|
| 1452 | - mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); |
|
| 1451 | + if (WP_DEBUG) { |
|
| 1452 | + mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags); |
|
| 1453 | 1453 | } else { |
| 1454 | - @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); |
|
| 1454 | + @mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | - if ( $this->dbh->connect_errno ) { |
|
| 1457 | + if ($this->dbh->connect_errno) { |
|
| 1458 | 1458 | $this->dbh = null; |
| 1459 | 1459 | |
| 1460 | 1460 | /* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if: |
@@ -1464,37 +1464,37 @@ discard block |
||
| 1464 | 1464 | */ |
| 1465 | 1465 | $attempt_fallback = true; |
| 1466 | 1466 | |
| 1467 | - if ( $this->has_connected ) { |
|
| 1467 | + if ($this->has_connected) { |
|
| 1468 | 1468 | $attempt_fallback = false; |
| 1469 | - } elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) { |
|
| 1469 | + } elseif (defined('WP_USE_EXT_MYSQL') && ! WP_USE_EXT_MYSQL) { |
|
| 1470 | 1470 | $attempt_fallback = false; |
| 1471 | - } elseif ( ! function_exists( 'mysql_connect' ) ) { |
|
| 1471 | + } elseif ( ! function_exists('mysql_connect')) { |
|
| 1472 | 1472 | $attempt_fallback = false; |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | - if ( $attempt_fallback ) { |
|
| 1475 | + if ($attempt_fallback) { |
|
| 1476 | 1476 | $this->use_mysqli = false; |
| 1477 | 1477 | $this->db_connect(); |
| 1478 | 1478 | } |
| 1479 | 1479 | } |
| 1480 | 1480 | } else { |
| 1481 | - if ( WP_DEBUG ) { |
|
| 1482 | - $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); |
|
| 1481 | + if (WP_DEBUG) { |
|
| 1482 | + $this->dbh = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags); |
|
| 1483 | 1483 | } else { |
| 1484 | - $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); |
|
| 1484 | + $this->dbh = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | - if ( ! $this->dbh && $allow_bail ) { |
|
| 1488 | + if ( ! $this->dbh && $allow_bail) { |
|
| 1489 | 1489 | wp_load_translations_early(); |
| 1490 | 1490 | |
| 1491 | 1491 | // Load custom DB error template, if present. |
| 1492 | - if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { |
|
| 1493 | - require_once( WP_CONTENT_DIR . '/db-error.php' ); |
|
| 1492 | + if (file_exists(WP_CONTENT_DIR.'/db-error.php')) { |
|
| 1493 | + require_once(WP_CONTENT_DIR.'/db-error.php'); |
|
| 1494 | 1494 | die(); |
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | - $this->bail( sprintf( __( " |
|
| 1497 | + $this->bail(sprintf(__(" |
|
| 1498 | 1498 | <h1>Error establishing a database connection</h1> |
| 1499 | 1499 | <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p> |
| 1500 | 1500 | <ul> |
@@ -1503,21 +1503,21 @@ discard block |
||
| 1503 | 1503 | <li>Are you sure that the database server is running?</li> |
| 1504 | 1504 | </ul> |
| 1505 | 1505 | <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p> |
| 1506 | -" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' ); |
|
| 1506 | +" ), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail'); |
|
| 1507 | 1507 | |
| 1508 | 1508 | return false; |
| 1509 | - } elseif ( $this->dbh ) { |
|
| 1510 | - if ( ! $this->has_connected ) { |
|
| 1509 | + } elseif ($this->dbh) { |
|
| 1510 | + if ( ! $this->has_connected) { |
|
| 1511 | 1511 | $this->init_charset(); |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | $this->has_connected = true; |
| 1515 | 1515 | |
| 1516 | - $this->set_charset( $this->dbh ); |
|
| 1516 | + $this->set_charset($this->dbh); |
|
| 1517 | 1517 | |
| 1518 | 1518 | $this->ready = true; |
| 1519 | 1519 | $this->set_sql_mode(); |
| 1520 | - $this->select( $this->dbname, $this->dbh ); |
|
| 1520 | + $this->select($this->dbname, $this->dbh); |
|
| 1521 | 1521 | |
| 1522 | 1522 | return true; |
| 1523 | 1523 | } |
@@ -1539,13 +1539,13 @@ discard block |
||
| 1539 | 1539 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1540 | 1540 | * @return bool|void True if the connection is up. |
| 1541 | 1541 | */ |
| 1542 | - public function check_connection( $allow_bail = true ) { |
|
| 1543 | - if ( $this->use_mysqli ) { |
|
| 1544 | - if ( @mysqli_ping( $this->dbh ) ) { |
|
| 1542 | + public function check_connection($allow_bail = true) { |
|
| 1543 | + if ($this->use_mysqli) { |
|
| 1544 | + if (@mysqli_ping($this->dbh)) { |
|
| 1545 | 1545 | return true; |
| 1546 | 1546 | } |
| 1547 | 1547 | } else { |
| 1548 | - if ( @mysql_ping( $this->dbh ) ) { |
|
| 1548 | + if (@mysql_ping($this->dbh)) { |
|
| 1549 | 1549 | return true; |
| 1550 | 1550 | } |
| 1551 | 1551 | } |
@@ -1553,41 +1553,41 @@ discard block |
||
| 1553 | 1553 | $error_reporting = false; |
| 1554 | 1554 | |
| 1555 | 1555 | // Disable warnings, as we don't want to see a multitude of "unable to connect" messages |
| 1556 | - if ( WP_DEBUG ) { |
|
| 1556 | + if (WP_DEBUG) { |
|
| 1557 | 1557 | $error_reporting = error_reporting(); |
| 1558 | - error_reporting( $error_reporting & ~E_WARNING ); |
|
| 1558 | + error_reporting($error_reporting & ~E_WARNING); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | - for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) { |
|
| 1561 | + for ($tries = 1; $tries <= $this->reconnect_retries; $tries++) { |
|
| 1562 | 1562 | // On the last try, re-enable warnings. We want to see a single instance of the |
| 1563 | 1563 | // "unable to connect" message on the bail() screen, if it appears. |
| 1564 | - if ( $this->reconnect_retries === $tries && WP_DEBUG ) { |
|
| 1565 | - error_reporting( $error_reporting ); |
|
| 1564 | + if ($this->reconnect_retries === $tries && WP_DEBUG) { |
|
| 1565 | + error_reporting($error_reporting); |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | - if ( $this->db_connect( false ) ) { |
|
| 1569 | - if ( $error_reporting ) { |
|
| 1570 | - error_reporting( $error_reporting ); |
|
| 1568 | + if ($this->db_connect(false)) { |
|
| 1569 | + if ($error_reporting) { |
|
| 1570 | + error_reporting($error_reporting); |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | return true; |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | - sleep( 1 ); |
|
| 1576 | + sleep(1); |
|
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | // If template_redirect has already happened, it's too late for wp_die()/dead_db(). |
| 1580 | 1580 | // Let's just return and hope for the best. |
| 1581 | - if ( did_action( 'template_redirect' ) ) { |
|
| 1581 | + if (did_action('template_redirect')) { |
|
| 1582 | 1582 | return false; |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | - if ( ! $allow_bail ) { |
|
| 1585 | + if ( ! $allow_bail) { |
|
| 1586 | 1586 | return false; |
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | // We weren't able to reconnect, so we better bail. |
| 1590 | - $this->bail( sprintf( ( " |
|
| 1590 | + $this->bail(sprintf((" |
|
| 1591 | 1591 | <h1>Error reconnecting to the database</h1> |
| 1592 | 1592 | <p>This means that we lost contact with the database server at <code>%s</code>. This could mean your host's database server is down.</p> |
| 1593 | 1593 | <ul> |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | <li>Are you sure that the database server is not under particularly heavy load?</li> |
| 1596 | 1596 | </ul> |
| 1597 | 1597 | <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p> |
| 1598 | -" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' ); |
|
| 1598 | +" ), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail'); |
|
| 1599 | 1599 | |
| 1600 | 1600 | // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily). |
| 1601 | 1601 | dead_db(); |
@@ -1611,8 +1611,8 @@ discard block |
||
| 1611 | 1611 | * @param string $query Database query |
| 1612 | 1612 | * @return int|false Number of rows affected/selected or false on error |
| 1613 | 1613 | */ |
| 1614 | - public function query( $query ) { |
|
| 1615 | - if ( ! $this->ready ) { |
|
| 1614 | + public function query($query) { |
|
| 1615 | + if ( ! $this->ready) { |
|
| 1616 | 1616 | $this->check_current_query = true; |
| 1617 | 1617 | return false; |
| 1618 | 1618 | } |
@@ -1627,7 +1627,7 @@ discard block |
||
| 1627 | 1627 | * |
| 1628 | 1628 | * @param string $query Database query. |
| 1629 | 1629 | */ |
| 1630 | - $query = apply_filters( 'query', $query ); |
|
| 1630 | + $query = apply_filters('query', $query); |
|
| 1631 | 1631 | |
| 1632 | 1632 | $this->flush(); |
| 1633 | 1633 | |
@@ -1635,12 +1635,12 @@ discard block |
||
| 1635 | 1635 | $this->func_call = "\$db->query(\"$query\")"; |
| 1636 | 1636 | |
| 1637 | 1637 | // If we're writing to the database, make sure the query will write safely. |
| 1638 | - if ( $this->check_current_query && ! $this->check_ascii( $query ) ) { |
|
| 1639 | - $stripped_query = $this->strip_invalid_text_from_query( $query ); |
|
| 1638 | + if ($this->check_current_query && ! $this->check_ascii($query)) { |
|
| 1639 | + $stripped_query = $this->strip_invalid_text_from_query($query); |
|
| 1640 | 1640 | // strip_invalid_text_from_query() can perform queries, so we need |
| 1641 | 1641 | // to flush again, just to make sure everything is clear. |
| 1642 | 1642 | $this->flush(); |
| 1643 | - if ( $stripped_query !== $query ) { |
|
| 1643 | + if ($stripped_query !== $query) { |
|
| 1644 | 1644 | $this->insert_id = 0; |
| 1645 | 1645 | return false; |
| 1646 | 1646 | } |
@@ -1651,21 +1651,21 @@ discard block |
||
| 1651 | 1651 | // Keep track of the last query for debug.. |
| 1652 | 1652 | $this->last_query = $query; |
| 1653 | 1653 | |
| 1654 | - $this->_do_query( $query ); |
|
| 1654 | + $this->_do_query($query); |
|
| 1655 | 1655 | |
| 1656 | 1656 | // MySQL server has gone away, try to reconnect |
| 1657 | 1657 | $mysql_errno = 0; |
| 1658 | - if ( ! empty( $this->dbh ) ) { |
|
| 1659 | - if ( $this->use_mysqli ) { |
|
| 1660 | - $mysql_errno = mysqli_errno( $this->dbh ); |
|
| 1658 | + if ( ! empty($this->dbh)) { |
|
| 1659 | + if ($this->use_mysqli) { |
|
| 1660 | + $mysql_errno = mysqli_errno($this->dbh); |
|
| 1661 | 1661 | } else { |
| 1662 | - $mysql_errno = mysql_errno( $this->dbh ); |
|
| 1662 | + $mysql_errno = mysql_errno($this->dbh); |
|
| 1663 | 1663 | } |
| 1664 | 1664 | } |
| 1665 | 1665 | |
| 1666 | - if ( empty( $this->dbh ) || 2006 == $mysql_errno ) { |
|
| 1667 | - if ( $this->check_connection() ) { |
|
| 1668 | - $this->_do_query( $query ); |
|
| 1666 | + if (empty($this->dbh) || 2006 == $mysql_errno) { |
|
| 1667 | + if ($this->check_connection()) { |
|
| 1668 | + $this->_do_query($query); |
|
| 1669 | 1669 | } else { |
| 1670 | 1670 | $this->insert_id = 0; |
| 1671 | 1671 | return false; |
@@ -1673,48 +1673,48 @@ discard block |
||
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | // If there is an error then take note of it.. |
| 1676 | - if ( $this->use_mysqli ) { |
|
| 1677 | - $this->last_error = mysqli_error( $this->dbh ); |
|
| 1676 | + if ($this->use_mysqli) { |
|
| 1677 | + $this->last_error = mysqli_error($this->dbh); |
|
| 1678 | 1678 | } else { |
| 1679 | - $this->last_error = mysql_error( $this->dbh ); |
|
| 1679 | + $this->last_error = mysql_error($this->dbh); |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | - if ( $this->last_error ) { |
|
| 1682 | + if ($this->last_error) { |
|
| 1683 | 1683 | // Clear insert_id on a subsequent failed insert. |
| 1684 | - if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) |
|
| 1684 | + if ($this->insert_id && preg_match('/^\s*(insert|replace)\s/i', $query)) |
|
| 1685 | 1685 | $this->insert_id = 0; |
| 1686 | 1686 | |
| 1687 | 1687 | $this->print_error(); |
| 1688 | 1688 | return false; |
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | - if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { |
|
| 1691 | + if (preg_match('/^\s*(create|alter|truncate|drop)\s/i', $query)) { |
|
| 1692 | 1692 | $return_val = $this->result; |
| 1693 | - } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { |
|
| 1694 | - if ( $this->use_mysqli ) { |
|
| 1695 | - $this->rows_affected = mysqli_affected_rows( $this->dbh ); |
|
| 1693 | + } elseif (preg_match('/^\s*(insert|delete|update|replace)\s/i', $query)) { |
|
| 1694 | + if ($this->use_mysqli) { |
|
| 1695 | + $this->rows_affected = mysqli_affected_rows($this->dbh); |
|
| 1696 | 1696 | } else { |
| 1697 | - $this->rows_affected = mysql_affected_rows( $this->dbh ); |
|
| 1697 | + $this->rows_affected = mysql_affected_rows($this->dbh); |
|
| 1698 | 1698 | } |
| 1699 | 1699 | // Take note of the insert_id |
| 1700 | - if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { |
|
| 1701 | - if ( $this->use_mysqli ) { |
|
| 1702 | - $this->insert_id = mysqli_insert_id( $this->dbh ); |
|
| 1700 | + if (preg_match('/^\s*(insert|replace)\s/i', $query)) { |
|
| 1701 | + if ($this->use_mysqli) { |
|
| 1702 | + $this->insert_id = mysqli_insert_id($this->dbh); |
|
| 1703 | 1703 | } else { |
| 1704 | - $this->insert_id = mysql_insert_id( $this->dbh ); |
|
| 1704 | + $this->insert_id = mysql_insert_id($this->dbh); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | } |
| 1707 | 1707 | // Return number of rows affected |
| 1708 | 1708 | $return_val = $this->rows_affected; |
| 1709 | 1709 | } else { |
| 1710 | 1710 | $num_rows = 0; |
| 1711 | - if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { |
|
| 1712 | - while ( $row = @mysqli_fetch_object( $this->result ) ) { |
|
| 1711 | + if ($this->use_mysqli && $this->result instanceof mysqli_result) { |
|
| 1712 | + while ($row = @mysqli_fetch_object($this->result)) { |
|
| 1713 | 1713 | $this->last_result[$num_rows] = $row; |
| 1714 | 1714 | $num_rows++; |
| 1715 | 1715 | } |
| 1716 | - } elseif ( is_resource( $this->result ) ) { |
|
| 1717 | - while ( $row = @mysql_fetch_object( $this->result ) ) { |
|
| 1716 | + } elseif (is_resource($this->result)) { |
|
| 1717 | + while ($row = @mysql_fetch_object($this->result)) { |
|
| 1718 | 1718 | $this->last_result[$num_rows] = $row; |
| 1719 | 1719 | $num_rows++; |
| 1720 | 1720 | } |
@@ -1739,20 +1739,20 @@ discard block |
||
| 1739 | 1739 | * |
| 1740 | 1740 | * @param string $query The query to run. |
| 1741 | 1741 | */ |
| 1742 | - private function _do_query( $query ) { |
|
| 1743 | - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
|
| 1742 | + private function _do_query($query) { |
|
| 1743 | + if (defined('SAVEQUERIES') && SAVEQUERIES) { |
|
| 1744 | 1744 | $this->timer_start(); |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | - if ( $this->use_mysqli ) { |
|
| 1748 | - $this->result = @mysqli_query( $this->dbh, $query ); |
|
| 1747 | + if ($this->use_mysqli) { |
|
| 1748 | + $this->result = @mysqli_query($this->dbh, $query); |
|
| 1749 | 1749 | } else { |
| 1750 | - $this->result = @mysql_query( $query, $this->dbh ); |
|
| 1750 | + $this->result = @mysql_query($query, $this->dbh); |
|
| 1751 | 1751 | } |
| 1752 | 1752 | $this->num_queries++; |
| 1753 | 1753 | |
| 1754 | - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
|
| 1755 | - $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); |
|
| 1754 | + if (defined('SAVEQUERIES') && SAVEQUERIES) { |
|
| 1755 | + $this->queries[] = array($query, $this->timer_stop(), $this->get_caller()); |
|
| 1756 | 1756 | } |
| 1757 | 1757 | } |
| 1758 | 1758 | |
@@ -1776,8 +1776,8 @@ discard block |
||
| 1776 | 1776 | * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1777 | 1777 | * @return int|false The number of rows inserted, or false on error. |
| 1778 | 1778 | */ |
| 1779 | - public function insert( $table, $data, $format = null ) { |
|
| 1780 | - return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); |
|
| 1779 | + public function insert($table, $data, $format = null) { |
|
| 1780 | + return $this->_insert_replace_helper($table, $data, $format, 'INSERT'); |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | /** |
@@ -1800,8 +1800,8 @@ discard block |
||
| 1800 | 1800 | * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1801 | 1801 | * @return int|false The number of rows affected, or false on error. |
| 1802 | 1802 | */ |
| 1803 | - public function replace( $table, $data, $format = null ) { |
|
| 1804 | - return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); |
|
| 1803 | + public function replace($table, $data, $format = null) { |
|
| 1804 | + return $this->_insert_replace_helper($table, $data, $format, 'REPLACE'); |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | /** |
@@ -1825,31 +1825,31 @@ discard block |
||
| 1825 | 1825 | * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT. |
| 1826 | 1826 | * @return int|false The number of rows affected, or false on error. |
| 1827 | 1827 | */ |
| 1828 | - function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { |
|
| 1828 | + function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') { |
|
| 1829 | 1829 | $this->insert_id = 0; |
| 1830 | 1830 | |
| 1831 | - if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) { |
|
| 1831 | + if ( ! in_array(strtoupper($type), array('REPLACE', 'INSERT'))) { |
|
| 1832 | 1832 | return false; |
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | - $data = $this->process_fields( $table, $data, $format ); |
|
| 1836 | - if ( false === $data ) { |
|
| 1835 | + $data = $this->process_fields($table, $data, $format); |
|
| 1836 | + if (false === $data) { |
|
| 1837 | 1837 | return false; |
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | 1840 | $formats = $values = array(); |
| 1841 | - foreach ( $data as $value ) { |
|
| 1841 | + foreach ($data as $value) { |
|
| 1842 | 1842 | $formats[] = $value['format']; |
| 1843 | 1843 | $values[] = $value['value']; |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - $fields = '`' . implode( '`, `', array_keys( $data ) ) . '`'; |
|
| 1847 | - $formats = implode( ', ', $formats ); |
|
| 1846 | + $fields = '`'.implode('`, `', array_keys($data)).'`'; |
|
| 1847 | + $formats = implode(', ', $formats); |
|
| 1848 | 1848 | |
| 1849 | 1849 | $sql = "$type INTO `$table` ($fields) VALUES ($formats)"; |
| 1850 | 1850 | |
| 1851 | 1851 | $this->check_current_query = false; |
| 1852 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 1852 | + return $this->query($this->prepare($sql, $values)); |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | /** |
@@ -1879,37 +1879,37 @@ discard block |
||
| 1879 | 1879 | * If omitted, all values in $where will be treated as strings. |
| 1880 | 1880 | * @return int|false The number of rows updated, or false on error. |
| 1881 | 1881 | */ |
| 1882 | - public function update( $table, $data, $where, $format = null, $where_format = null ) { |
|
| 1883 | - if ( ! is_array( $data ) || ! is_array( $where ) ) { |
|
| 1882 | + public function update($table, $data, $where, $format = null, $where_format = null) { |
|
| 1883 | + if ( ! is_array($data) || ! is_array($where)) { |
|
| 1884 | 1884 | return false; |
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | - $data = $this->process_fields( $table, $data, $format ); |
|
| 1888 | - if ( false === $data ) { |
|
| 1887 | + $data = $this->process_fields($table, $data, $format); |
|
| 1888 | + if (false === $data) { |
|
| 1889 | 1889 | return false; |
| 1890 | 1890 | } |
| 1891 | - $where = $this->process_fields( $table, $where, $where_format ); |
|
| 1892 | - if ( false === $where ) { |
|
| 1891 | + $where = $this->process_fields($table, $where, $where_format); |
|
| 1892 | + if (false === $where) { |
|
| 1893 | 1893 | return false; |
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | $fields = $conditions = $values = array(); |
| 1897 | - foreach ( $data as $field => $value ) { |
|
| 1898 | - $fields[] = "`$field` = " . $value['format']; |
|
| 1897 | + foreach ($data as $field => $value) { |
|
| 1898 | + $fields[] = "`$field` = ".$value['format']; |
|
| 1899 | 1899 | $values[] = $value['value']; |
| 1900 | 1900 | } |
| 1901 | - foreach ( $where as $field => $value ) { |
|
| 1902 | - $conditions[] = "`$field` = " . $value['format']; |
|
| 1901 | + foreach ($where as $field => $value) { |
|
| 1902 | + $conditions[] = "`$field` = ".$value['format']; |
|
| 1903 | 1903 | $values[] = $value['value']; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | - $fields = implode( ', ', $fields ); |
|
| 1907 | - $conditions = implode( ' AND ', $conditions ); |
|
| 1906 | + $fields = implode(', ', $fields); |
|
| 1907 | + $conditions = implode(' AND ', $conditions); |
|
| 1908 | 1908 | |
| 1909 | 1909 | $sql = "UPDATE `$table` SET $fields WHERE $conditions"; |
| 1910 | 1910 | |
| 1911 | 1911 | $this->check_current_query = false; |
| 1912 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 1912 | + return $this->query($this->prepare($sql, $values)); |
|
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | /** |
@@ -1933,28 +1933,28 @@ discard block |
||
| 1933 | 1933 | * If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1934 | 1934 | * @return int|false The number of rows updated, or false on error. |
| 1935 | 1935 | */ |
| 1936 | - public function delete( $table, $where, $where_format = null ) { |
|
| 1937 | - if ( ! is_array( $where ) ) { |
|
| 1936 | + public function delete($table, $where, $where_format = null) { |
|
| 1937 | + if ( ! is_array($where)) { |
|
| 1938 | 1938 | return false; |
| 1939 | 1939 | } |
| 1940 | 1940 | |
| 1941 | - $where = $this->process_fields( $table, $where, $where_format ); |
|
| 1942 | - if ( false === $where ) { |
|
| 1941 | + $where = $this->process_fields($table, $where, $where_format); |
|
| 1942 | + if (false === $where) { |
|
| 1943 | 1943 | return false; |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | 1946 | $conditions = $values = array(); |
| 1947 | - foreach ( $where as $field => $value ) { |
|
| 1948 | - $conditions[] = "`$field` = " . $value['format']; |
|
| 1947 | + foreach ($where as $field => $value) { |
|
| 1948 | + $conditions[] = "`$field` = ".$value['format']; |
|
| 1949 | 1949 | $values[] = $value['value']; |
| 1950 | 1950 | } |
| 1951 | 1951 | |
| 1952 | - $conditions = implode( ' AND ', $conditions ); |
|
| 1952 | + $conditions = implode(' AND ', $conditions); |
|
| 1953 | 1953 | |
| 1954 | 1954 | $sql = "DELETE FROM `$table` WHERE $conditions"; |
| 1955 | 1955 | |
| 1956 | 1956 | $this->check_current_query = false; |
| 1957 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 1957 | + return $this->query($this->prepare($sql, $values)); |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | /** |
@@ -1975,25 +1975,25 @@ discard block |
||
| 1975 | 1975 | * @return array|false Returns an array of fields that contain paired values |
| 1976 | 1976 | * and formats. Returns false for invalid values. |
| 1977 | 1977 | */ |
| 1978 | - protected function process_fields( $table, $data, $format ) { |
|
| 1979 | - $data = $this->process_field_formats( $data, $format ); |
|
| 1980 | - if ( false === $data ) { |
|
| 1978 | + protected function process_fields($table, $data, $format) { |
|
| 1979 | + $data = $this->process_field_formats($data, $format); |
|
| 1980 | + if (false === $data) { |
|
| 1981 | 1981 | return false; |
| 1982 | 1982 | } |
| 1983 | 1983 | |
| 1984 | - $data = $this->process_field_charsets( $data, $table ); |
|
| 1985 | - if ( false === $data ) { |
|
| 1984 | + $data = $this->process_field_charsets($data, $table); |
|
| 1985 | + if (false === $data) { |
|
| 1986 | 1986 | return false; |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | - $data = $this->process_field_lengths( $data, $table ); |
|
| 1990 | - if ( false === $data ) { |
|
| 1989 | + $data = $this->process_field_lengths($data, $table); |
|
| 1990 | + if (false === $data) { |
|
| 1991 | 1991 | return false; |
| 1992 | 1992 | } |
| 1993 | 1993 | |
| 1994 | - $converted_data = $this->strip_invalid_text( $data ); |
|
| 1994 | + $converted_data = $this->strip_invalid_text($data); |
|
| 1995 | 1995 | |
| 1996 | - if ( $data !== $converted_data ) { |
|
| 1996 | + if ($data !== $converted_data) { |
|
| 1997 | 1997 | return false; |
| 1998 | 1998 | } |
| 1999 | 1999 | |
@@ -2011,25 +2011,25 @@ discard block |
||
| 2011 | 2011 | * @return array Array, keyed by field names with values being an array |
| 2012 | 2012 | * of 'value' and 'format' keys. |
| 2013 | 2013 | */ |
| 2014 | - protected function process_field_formats( $data, $format ) { |
|
| 2014 | + protected function process_field_formats($data, $format) { |
|
| 2015 | 2015 | $formats = $original_formats = (array) $format; |
| 2016 | 2016 | |
| 2017 | - foreach ( $data as $field => $value ) { |
|
| 2017 | + foreach ($data as $field => $value) { |
|
| 2018 | 2018 | $value = array( |
| 2019 | 2019 | 'value' => $value, |
| 2020 | 2020 | 'format' => '%s', |
| 2021 | 2021 | ); |
| 2022 | 2022 | |
| 2023 | - if ( ! empty( $format ) ) { |
|
| 2024 | - $value['format'] = array_shift( $formats ); |
|
| 2025 | - if ( ! $value['format'] ) { |
|
| 2026 | - $value['format'] = reset( $original_formats ); |
|
| 2023 | + if ( ! empty($format)) { |
|
| 2024 | + $value['format'] = array_shift($formats); |
|
| 2025 | + if ( ! $value['format']) { |
|
| 2026 | + $value['format'] = reset($original_formats); |
|
| 2027 | 2027 | } |
| 2028 | - } elseif ( isset( $this->field_types[ $field ] ) ) { |
|
| 2029 | - $value['format'] = $this->field_types[ $field ]; |
|
| 2028 | + } elseif (isset($this->field_types[$field])) { |
|
| 2029 | + $value['format'] = $this->field_types[$field]; |
|
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 2032 | - $data[ $field ] = $value; |
|
| 2032 | + $data[$field] = $value; |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | return $data; |
@@ -2046,20 +2046,20 @@ discard block |
||
| 2046 | 2046 | * @param string $table Table name. |
| 2047 | 2047 | * @return array|false The same array as $data with additional 'charset' keys. |
| 2048 | 2048 | */ |
| 2049 | - protected function process_field_charsets( $data, $table ) { |
|
| 2050 | - foreach ( $data as $field => $value ) { |
|
| 2051 | - if ( '%d' === $value['format'] || '%f' === $value['format'] ) { |
|
| 2049 | + protected function process_field_charsets($data, $table) { |
|
| 2050 | + foreach ($data as $field => $value) { |
|
| 2051 | + if ('%d' === $value['format'] || '%f' === $value['format']) { |
|
| 2052 | 2052 | // We can skip this field if we know it isn't a string. |
| 2053 | 2053 | // This checks %d/%f versus ! %s because it's sprintf() could take more. |
| 2054 | 2054 | $value['charset'] = false; |
| 2055 | 2055 | } else { |
| 2056 | - $value['charset'] = $this->get_col_charset( $table, $field ); |
|
| 2057 | - if ( is_wp_error( $value['charset'] ) ) { |
|
| 2056 | + $value['charset'] = $this->get_col_charset($table, $field); |
|
| 2057 | + if (is_wp_error($value['charset'])) { |
|
| 2058 | 2058 | return false; |
| 2059 | 2059 | } |
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | - $data[ $field ] = $value; |
|
| 2062 | + $data[$field] = $value; |
|
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | 2065 | return $data; |
@@ -2076,20 +2076,20 @@ discard block |
||
| 2076 | 2076 | * @return array|false The same array as $data with additional 'length' keys, or false if |
| 2077 | 2077 | * any of the values were too long for their corresponding field. |
| 2078 | 2078 | */ |
| 2079 | - protected function process_field_lengths( $data, $table ) { |
|
| 2080 | - foreach ( $data as $field => $value ) { |
|
| 2081 | - if ( '%d' === $value['format'] || '%f' === $value['format'] ) { |
|
| 2079 | + protected function process_field_lengths($data, $table) { |
|
| 2080 | + foreach ($data as $field => $value) { |
|
| 2081 | + if ('%d' === $value['format'] || '%f' === $value['format']) { |
|
| 2082 | 2082 | // We can skip this field if we know it isn't a string. |
| 2083 | 2083 | // This checks %d/%f versus ! %s because it's sprintf() could take more. |
| 2084 | 2084 | $value['length'] = false; |
| 2085 | 2085 | } else { |
| 2086 | - $value['length'] = $this->get_col_length( $table, $field ); |
|
| 2087 | - if ( is_wp_error( $value['length'] ) ) { |
|
| 2086 | + $value['length'] = $this->get_col_length($table, $field); |
|
| 2087 | + if (is_wp_error($value['length'])) { |
|
| 2088 | 2088 | return false; |
| 2089 | 2089 | } |
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | - $data[ $field ] = $value; |
|
| 2092 | + $data[$field] = $value; |
|
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | return $data; |
@@ -2109,24 +2109,24 @@ discard block |
||
| 2109 | 2109 | * @param int $y Optional. Row of value to return. Indexed from 0. |
| 2110 | 2110 | * @return string|null Database query result (as string), or null on failure |
| 2111 | 2111 | */ |
| 2112 | - public function get_var( $query = null, $x = 0, $y = 0 ) { |
|
| 2112 | + public function get_var($query = null, $x = 0, $y = 0) { |
|
| 2113 | 2113 | $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; |
| 2114 | 2114 | |
| 2115 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2115 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2116 | 2116 | $this->check_current_query = false; |
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | - if ( $query ) { |
|
| 2120 | - $this->query( $query ); |
|
| 2119 | + if ($query) { |
|
| 2120 | + $this->query($query); |
|
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | 2123 | // Extract var out of cached results based x,y vals |
| 2124 | - if ( !empty( $this->last_result[$y] ) ) { |
|
| 2125 | - $values = array_values( get_object_vars( $this->last_result[$y] ) ); |
|
| 2124 | + if ( ! empty($this->last_result[$y])) { |
|
| 2125 | + $values = array_values(get_object_vars($this->last_result[$y])); |
|
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 2128 | 2128 | // If there is a value return it else return null |
| 2129 | - return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null; |
|
| 2129 | + return (isset($values[$x]) && $values[$x] !== '') ? $values[$x] : null; |
|
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | /** |
@@ -2144,33 +2144,33 @@ discard block |
||
| 2144 | 2144 | * @param int $y Optional. Row to return. Indexed from 0. |
| 2145 | 2145 | * @return array|object|null|void Database query result in format specified by $output or null on failure |
| 2146 | 2146 | */ |
| 2147 | - public function get_row( $query = null, $output = OBJECT, $y = 0 ) { |
|
| 2147 | + public function get_row($query = null, $output = OBJECT, $y = 0) { |
|
| 2148 | 2148 | $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; |
| 2149 | 2149 | |
| 2150 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2150 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2151 | 2151 | $this->check_current_query = false; |
| 2152 | 2152 | } |
| 2153 | 2153 | |
| 2154 | - if ( $query ) { |
|
| 2155 | - $this->query( $query ); |
|
| 2154 | + if ($query) { |
|
| 2155 | + $this->query($query); |
|
| 2156 | 2156 | } else { |
| 2157 | 2157 | return null; |
| 2158 | 2158 | } |
| 2159 | 2159 | |
| 2160 | - if ( !isset( $this->last_result[$y] ) ) |
|
| 2160 | + if ( ! isset($this->last_result[$y])) |
|
| 2161 | 2161 | return null; |
| 2162 | 2162 | |
| 2163 | - if ( $output == OBJECT ) { |
|
| 2163 | + if ($output == OBJECT) { |
|
| 2164 | 2164 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| 2165 | - } elseif ( $output == ARRAY_A ) { |
|
| 2166 | - return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; |
|
| 2167 | - } elseif ( $output == ARRAY_N ) { |
|
| 2168 | - return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; |
|
| 2169 | - } elseif ( strtoupper( $output ) === OBJECT ) { |
|
| 2165 | + } elseif ($output == ARRAY_A) { |
|
| 2166 | + return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null; |
|
| 2167 | + } elseif ($output == ARRAY_N) { |
|
| 2168 | + return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null; |
|
| 2169 | + } elseif (strtoupper($output) === OBJECT) { |
|
| 2170 | 2170 | // Back compat for OBJECT being previously case insensitive. |
| 2171 | 2171 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| 2172 | 2172 | } else { |
| 2173 | - $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" ); |
|
| 2173 | + $this->print_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"); |
|
| 2174 | 2174 | } |
| 2175 | 2175 | } |
| 2176 | 2176 | |
@@ -2187,19 +2187,19 @@ discard block |
||
| 2187 | 2187 | * @param int $x Optional. Column to return. Indexed from 0. |
| 2188 | 2188 | * @return array Database query result. Array indexed from 0 by SQL result row number. |
| 2189 | 2189 | */ |
| 2190 | - public function get_col( $query = null , $x = 0 ) { |
|
| 2191 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2190 | + public function get_col($query = null, $x = 0) { |
|
| 2191 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2192 | 2192 | $this->check_current_query = false; |
| 2193 | 2193 | } |
| 2194 | 2194 | |
| 2195 | - if ( $query ) { |
|
| 2196 | - $this->query( $query ); |
|
| 2195 | + if ($query) { |
|
| 2196 | + $this->query($query); |
|
| 2197 | 2197 | } |
| 2198 | 2198 | |
| 2199 | 2199 | $new_array = array(); |
| 2200 | 2200 | // Extract the column values |
| 2201 | - for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { |
|
| 2202 | - $new_array[$i] = $this->get_var( null, $x, $i ); |
|
| 2201 | + for ($i = 0, $j = count($this->last_result); $i < $j; $i++) { |
|
| 2202 | + $new_array[$i] = $this->get_var(null, $x, $i); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | return $new_array; |
| 2205 | 2205 | } |
@@ -2219,48 +2219,48 @@ discard block |
||
| 2219 | 2219 | * Duplicate keys are discarded. |
| 2220 | 2220 | * @return array|object|null Database query results |
| 2221 | 2221 | */ |
| 2222 | - public function get_results( $query = null, $output = OBJECT ) { |
|
| 2222 | + public function get_results($query = null, $output = OBJECT) { |
|
| 2223 | 2223 | $this->func_call = "\$db->get_results(\"$query\", $output)"; |
| 2224 | 2224 | |
| 2225 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2225 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2226 | 2226 | $this->check_current_query = false; |
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | - if ( $query ) { |
|
| 2230 | - $this->query( $query ); |
|
| 2229 | + if ($query) { |
|
| 2230 | + $this->query($query); |
|
| 2231 | 2231 | } else { |
| 2232 | 2232 | return null; |
| 2233 | 2233 | } |
| 2234 | 2234 | |
| 2235 | 2235 | $new_array = array(); |
| 2236 | - if ( $output == OBJECT ) { |
|
| 2236 | + if ($output == OBJECT) { |
|
| 2237 | 2237 | // Return an integer-keyed array of row objects |
| 2238 | 2238 | return $this->last_result; |
| 2239 | - } elseif ( $output == OBJECT_K ) { |
|
| 2239 | + } elseif ($output == OBJECT_K) { |
|
| 2240 | 2240 | // Return an array of row objects with keys from column 1 |
| 2241 | 2241 | // (Duplicates are discarded) |
| 2242 | - foreach ( $this->last_result as $row ) { |
|
| 2243 | - $var_by_ref = get_object_vars( $row ); |
|
| 2244 | - $key = array_shift( $var_by_ref ); |
|
| 2245 | - if ( ! isset( $new_array[ $key ] ) ) |
|
| 2246 | - $new_array[ $key ] = $row; |
|
| 2242 | + foreach ($this->last_result as $row) { |
|
| 2243 | + $var_by_ref = get_object_vars($row); |
|
| 2244 | + $key = array_shift($var_by_ref); |
|
| 2245 | + if ( ! isset($new_array[$key])) |
|
| 2246 | + $new_array[$key] = $row; |
|
| 2247 | 2247 | } |
| 2248 | 2248 | return $new_array; |
| 2249 | - } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { |
|
| 2249 | + } elseif ($output == ARRAY_A || $output == ARRAY_N) { |
|
| 2250 | 2250 | // Return an integer-keyed array of... |
| 2251 | - if ( $this->last_result ) { |
|
| 2252 | - foreach( (array) $this->last_result as $row ) { |
|
| 2253 | - if ( $output == ARRAY_N ) { |
|
| 2251 | + if ($this->last_result) { |
|
| 2252 | + foreach ((array) $this->last_result as $row) { |
|
| 2253 | + if ($output == ARRAY_N) { |
|
| 2254 | 2254 | // ...integer-keyed row arrays |
| 2255 | - $new_array[] = array_values( get_object_vars( $row ) ); |
|
| 2255 | + $new_array[] = array_values(get_object_vars($row)); |
|
| 2256 | 2256 | } else { |
| 2257 | 2257 | // ...column name-keyed row arrays |
| 2258 | - $new_array[] = get_object_vars( $row ); |
|
| 2258 | + $new_array[] = get_object_vars($row); |
|
| 2259 | 2259 | } |
| 2260 | 2260 | } |
| 2261 | 2261 | } |
| 2262 | 2262 | return $new_array; |
| 2263 | - } elseif ( strtoupper( $output ) === OBJECT ) { |
|
| 2263 | + } elseif (strtoupper($output) === OBJECT) { |
|
| 2264 | 2264 | // Back compat for OBJECT being previously case insensitive. |
| 2265 | 2265 | return $this->last_result; |
| 2266 | 2266 | } |
@@ -2276,8 +2276,8 @@ discard block |
||
| 2276 | 2276 | * @param string $table Table name. |
| 2277 | 2277 | * @return string|WP_Error Table character set, WP_Error object if it couldn't be found. |
| 2278 | 2278 | */ |
| 2279 | - protected function get_table_charset( $table ) { |
|
| 2280 | - $tablekey = strtolower( $table ); |
|
| 2279 | + protected function get_table_charset($table) { |
|
| 2280 | + $tablekey = strtolower($table); |
|
| 2281 | 2281 | |
| 2282 | 2282 | /** |
| 2283 | 2283 | * Filter the table charset value before the DB is checked. |
@@ -2290,72 +2290,72 @@ discard block |
||
| 2290 | 2290 | * @param string $charset The character set to use. Default null. |
| 2291 | 2291 | * @param string $table The name of the table being checked. |
| 2292 | 2292 | */ |
| 2293 | - $charset = apply_filters( 'pre_get_table_charset', null, $table ); |
|
| 2294 | - if ( null !== $charset ) { |
|
| 2293 | + $charset = apply_filters('pre_get_table_charset', null, $table); |
|
| 2294 | + if (null !== $charset) { |
|
| 2295 | 2295 | return $charset; |
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | - if ( isset( $this->table_charset[ $tablekey ] ) ) { |
|
| 2299 | - return $this->table_charset[ $tablekey ]; |
|
| 2298 | + if (isset($this->table_charset[$tablekey])) { |
|
| 2299 | + return $this->table_charset[$tablekey]; |
|
| 2300 | 2300 | } |
| 2301 | 2301 | |
| 2302 | 2302 | $charsets = $columns = array(); |
| 2303 | 2303 | |
| 2304 | - $table_parts = explode( '.', $table ); |
|
| 2305 | - $table = '`' . implode( '`.`', $table_parts ) . '`'; |
|
| 2306 | - $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" ); |
|
| 2307 | - if ( ! $results ) { |
|
| 2308 | - return new WP_Error( 'wpdb_get_table_charset_failure' ); |
|
| 2304 | + $table_parts = explode('.', $table); |
|
| 2305 | + $table = '`'.implode('`.`', $table_parts).'`'; |
|
| 2306 | + $results = $this->get_results("SHOW FULL COLUMNS FROM $table"); |
|
| 2307 | + if ( ! $results) { |
|
| 2308 | + return new WP_Error('wpdb_get_table_charset_failure'); |
|
| 2309 | 2309 | } |
| 2310 | 2310 | |
| 2311 | - foreach ( $results as $column ) { |
|
| 2312 | - $columns[ strtolower( $column->Field ) ] = $column; |
|
| 2311 | + foreach ($results as $column) { |
|
| 2312 | + $columns[strtolower($column->Field)] = $column; |
|
| 2313 | 2313 | } |
| 2314 | 2314 | |
| 2315 | - $this->col_meta[ $tablekey ] = $columns; |
|
| 2315 | + $this->col_meta[$tablekey] = $columns; |
|
| 2316 | 2316 | |
| 2317 | - foreach ( $columns as $column ) { |
|
| 2318 | - if ( ! empty( $column->Collation ) ) { |
|
| 2319 | - list( $charset ) = explode( '_', $column->Collation ); |
|
| 2317 | + foreach ($columns as $column) { |
|
| 2318 | + if ( ! empty($column->Collation)) { |
|
| 2319 | + list($charset) = explode('_', $column->Collation); |
|
| 2320 | 2320 | |
| 2321 | 2321 | // If the current connection can't support utf8mb4 characters, let's only send 3-byte utf8 characters. |
| 2322 | - if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) { |
|
| 2322 | + if ('utf8mb4' === $charset && ! $this->has_cap('utf8mb4')) { |
|
| 2323 | 2323 | $charset = 'utf8'; |
| 2324 | 2324 | } |
| 2325 | 2325 | |
| 2326 | - $charsets[ strtolower( $charset ) ] = true; |
|
| 2326 | + $charsets[strtolower($charset)] = true; |
|
| 2327 | 2327 | } |
| 2328 | 2328 | |
| 2329 | - list( $type ) = explode( '(', $column->Type ); |
|
| 2329 | + list($type) = explode('(', $column->Type); |
|
| 2330 | 2330 | |
| 2331 | 2331 | // A binary/blob means the whole query gets treated like this. |
| 2332 | - if ( in_array( strtoupper( $type ), array( 'BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB' ) ) ) { |
|
| 2333 | - $this->table_charset[ $tablekey ] = 'binary'; |
|
| 2332 | + if (in_array(strtoupper($type), array('BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB'))) { |
|
| 2333 | + $this->table_charset[$tablekey] = 'binary'; |
|
| 2334 | 2334 | return 'binary'; |
| 2335 | 2335 | } |
| 2336 | 2336 | } |
| 2337 | 2337 | |
| 2338 | 2338 | // utf8mb3 is an alias for utf8. |
| 2339 | - if ( isset( $charsets['utf8mb3'] ) ) { |
|
| 2339 | + if (isset($charsets['utf8mb3'])) { |
|
| 2340 | 2340 | $charsets['utf8'] = true; |
| 2341 | - unset( $charsets['utf8mb3'] ); |
|
| 2341 | + unset($charsets['utf8mb3']); |
|
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | // Check if we have more than one charset in play. |
| 2345 | - $count = count( $charsets ); |
|
| 2346 | - if ( 1 === $count ) { |
|
| 2347 | - $charset = key( $charsets ); |
|
| 2348 | - } elseif ( 0 === $count ) { |
|
| 2345 | + $count = count($charsets); |
|
| 2346 | + if (1 === $count) { |
|
| 2347 | + $charset = key($charsets); |
|
| 2348 | + } elseif (0 === $count) { |
|
| 2349 | 2349 | // No charsets, assume this table can store whatever. |
| 2350 | 2350 | $charset = false; |
| 2351 | 2351 | } else { |
| 2352 | 2352 | // More than one charset. Remove latin1 if present and recalculate. |
| 2353 | - unset( $charsets['latin1'] ); |
|
| 2354 | - $count = count( $charsets ); |
|
| 2355 | - if ( 1 === $count ) { |
|
| 2353 | + unset($charsets['latin1']); |
|
| 2354 | + $count = count($charsets); |
|
| 2355 | + if (1 === $count) { |
|
| 2356 | 2356 | // Only one charset (besides latin1). |
| 2357 | - $charset = key( $charsets ); |
|
| 2358 | - } elseif ( 2 === $count && isset( $charsets['utf8'], $charsets['utf8mb4'] ) ) { |
|
| 2357 | + $charset = key($charsets); |
|
| 2358 | + } elseif (2 === $count && isset($charsets['utf8'], $charsets['utf8mb4'])) { |
|
| 2359 | 2359 | // Two charsets, but they're utf8 and utf8mb4, use utf8. |
| 2360 | 2360 | $charset = 'utf8'; |
| 2361 | 2361 | } else { |
@@ -2364,7 +2364,7 @@ discard block |
||
| 2364 | 2364 | } |
| 2365 | 2365 | } |
| 2366 | 2366 | |
| 2367 | - $this->table_charset[ $tablekey ] = $charset; |
|
| 2367 | + $this->table_charset[$tablekey] = $charset; |
|
| 2368 | 2368 | return $charset; |
| 2369 | 2369 | } |
| 2370 | 2370 | |
@@ -2379,9 +2379,9 @@ discard block |
||
| 2379 | 2379 | * @return string|false|WP_Error Column character set as a string. False if the column has no |
| 2380 | 2380 | * character set. WP_Error object if there was an error. |
| 2381 | 2381 | */ |
| 2382 | - public function get_col_charset( $table, $column ) { |
|
| 2383 | - $tablekey = strtolower( $table ); |
|
| 2384 | - $columnkey = strtolower( $column ); |
|
| 2382 | + public function get_col_charset($table, $column) { |
|
| 2383 | + $tablekey = strtolower($table); |
|
| 2384 | + $columnkey = strtolower($column); |
|
| 2385 | 2385 | |
| 2386 | 2386 | /** |
| 2387 | 2387 | * Filter the column charset value before the DB is checked. |
@@ -2395,40 +2395,40 @@ discard block |
||
| 2395 | 2395 | * @param string $table The name of the table being checked. |
| 2396 | 2396 | * @param string $column The name of the column being checked. |
| 2397 | 2397 | */ |
| 2398 | - $charset = apply_filters( 'pre_get_col_charset', null, $table, $column ); |
|
| 2399 | - if ( null !== $charset ) { |
|
| 2398 | + $charset = apply_filters('pre_get_col_charset', null, $table, $column); |
|
| 2399 | + if (null !== $charset) { |
|
| 2400 | 2400 | return $charset; |
| 2401 | 2401 | } |
| 2402 | 2402 | |
| 2403 | 2403 | // Skip this entirely if this isn't a MySQL database. |
| 2404 | - if ( false === $this->is_mysql ) { |
|
| 2404 | + if (false === $this->is_mysql) { |
|
| 2405 | 2405 | return false; |
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | - if ( empty( $this->table_charset[ $tablekey ] ) ) { |
|
| 2408 | + if (empty($this->table_charset[$tablekey])) { |
|
| 2409 | 2409 | // This primes column information for us. |
| 2410 | - $table_charset = $this->get_table_charset( $table ); |
|
| 2411 | - if ( is_wp_error( $table_charset ) ) { |
|
| 2410 | + $table_charset = $this->get_table_charset($table); |
|
| 2411 | + if (is_wp_error($table_charset)) { |
|
| 2412 | 2412 | return $table_charset; |
| 2413 | 2413 | } |
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | // If still no column information, return the table charset. |
| 2417 | - if ( empty( $this->col_meta[ $tablekey ] ) ) { |
|
| 2418 | - return $this->table_charset[ $tablekey ]; |
|
| 2417 | + if (empty($this->col_meta[$tablekey])) { |
|
| 2418 | + return $this->table_charset[$tablekey]; |
|
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | // If this column doesn't exist, return the table charset. |
| 2422 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { |
|
| 2423 | - return $this->table_charset[ $tablekey ]; |
|
| 2422 | + if (empty($this->col_meta[$tablekey][$columnkey])) { |
|
| 2423 | + return $this->table_charset[$tablekey]; |
|
| 2424 | 2424 | } |
| 2425 | 2425 | |
| 2426 | 2426 | // Return false when it's not a string column. |
| 2427 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ]->Collation ) ) { |
|
| 2427 | + if (empty($this->col_meta[$tablekey][$columnkey]->Collation)) { |
|
| 2428 | 2428 | return false; |
| 2429 | 2429 | } |
| 2430 | 2430 | |
| 2431 | - list( $charset ) = explode( '_', $this->col_meta[ $tablekey ][ $columnkey ]->Collation ); |
|
| 2431 | + list($charset) = explode('_', $this->col_meta[$tablekey][$columnkey]->Collation); |
|
| 2432 | 2432 | return $charset; |
| 2433 | 2433 | } |
| 2434 | 2434 | |
@@ -2445,37 +2445,37 @@ discard block |
||
| 2445 | 2445 | * false if the column has no length (for example, numeric column) |
| 2446 | 2446 | * WP_Error object if there was an error. |
| 2447 | 2447 | */ |
| 2448 | - public function get_col_length( $table, $column ) { |
|
| 2449 | - $tablekey = strtolower( $table ); |
|
| 2450 | - $columnkey = strtolower( $column ); |
|
| 2448 | + public function get_col_length($table, $column) { |
|
| 2449 | + $tablekey = strtolower($table); |
|
| 2450 | + $columnkey = strtolower($column); |
|
| 2451 | 2451 | |
| 2452 | 2452 | // Skip this entirely if this isn't a MySQL database. |
| 2453 | - if ( false === $this->is_mysql ) { |
|
| 2453 | + if (false === $this->is_mysql) { |
|
| 2454 | 2454 | return false; |
| 2455 | 2455 | } |
| 2456 | 2456 | |
| 2457 | - if ( empty( $this->col_meta[ $tablekey ] ) ) { |
|
| 2457 | + if (empty($this->col_meta[$tablekey])) { |
|
| 2458 | 2458 | // This primes column information for us. |
| 2459 | - $table_charset = $this->get_table_charset( $table ); |
|
| 2460 | - if ( is_wp_error( $table_charset ) ) { |
|
| 2459 | + $table_charset = $this->get_table_charset($table); |
|
| 2460 | + if (is_wp_error($table_charset)) { |
|
| 2461 | 2461 | return $table_charset; |
| 2462 | 2462 | } |
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { |
|
| 2465 | + if (empty($this->col_meta[$tablekey][$columnkey])) { |
|
| 2466 | 2466 | return false; |
| 2467 | 2467 | } |
| 2468 | 2468 | |
| 2469 | - $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type ); |
|
| 2469 | + $typeinfo = explode('(', $this->col_meta[$tablekey][$columnkey]->Type); |
|
| 2470 | 2470 | |
| 2471 | - $type = strtolower( $typeinfo[0] ); |
|
| 2472 | - if ( ! empty( $typeinfo[1] ) ) { |
|
| 2473 | - $length = trim( $typeinfo[1], ')' ); |
|
| 2471 | + $type = strtolower($typeinfo[0]); |
|
| 2472 | + if ( ! empty($typeinfo[1])) { |
|
| 2473 | + $length = trim($typeinfo[1], ')'); |
|
| 2474 | 2474 | } else { |
| 2475 | 2475 | $length = false; |
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | - switch( $type ) { |
|
| 2478 | + switch ($type) { |
|
| 2479 | 2479 | case 'char': |
| 2480 | 2480 | case 'varchar': |
| 2481 | 2481 | return array( |
@@ -2494,21 +2494,21 @@ discard block |
||
| 2494 | 2494 | case 'tinytext': |
| 2495 | 2495 | return array( |
| 2496 | 2496 | 'type' => 'byte', |
| 2497 | - 'length' => 255, // 2^8 - 1 |
|
| 2497 | + 'length' => 255, // 2^8 - 1 |
|
| 2498 | 2498 | ); |
| 2499 | 2499 | break; |
| 2500 | 2500 | case 'blob': |
| 2501 | 2501 | case 'text': |
| 2502 | 2502 | return array( |
| 2503 | 2503 | 'type' => 'byte', |
| 2504 | - 'length' => 65535, // 2^16 - 1 |
|
| 2504 | + 'length' => 65535, // 2^16 - 1 |
|
| 2505 | 2505 | ); |
| 2506 | 2506 | break; |
| 2507 | 2507 | case 'mediumblob': |
| 2508 | 2508 | case 'mediumtext': |
| 2509 | 2509 | return array( |
| 2510 | 2510 | 'type' => 'byte', |
| 2511 | - 'length' => 16777215, // 2^24 - 1 |
|
| 2511 | + 'length' => 16777215, // 2^24 - 1 |
|
| 2512 | 2512 | ); |
| 2513 | 2513 | break; |
| 2514 | 2514 | case 'longblob': |
@@ -2537,12 +2537,12 @@ discard block |
||
| 2537 | 2537 | * @param string $string String to check. |
| 2538 | 2538 | * @return bool True if ASCII, false if not. |
| 2539 | 2539 | */ |
| 2540 | - protected function check_ascii( $string ) { |
|
| 2541 | - if ( function_exists( 'mb_check_encoding' ) ) { |
|
| 2542 | - if ( mb_check_encoding( $string, 'ASCII' ) ) { |
|
| 2540 | + protected function check_ascii($string) { |
|
| 2541 | + if (function_exists('mb_check_encoding')) { |
|
| 2542 | + if (mb_check_encoding($string, 'ASCII')) { |
|
| 2543 | 2543 | return true; |
| 2544 | 2544 | } |
| 2545 | - } elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) { |
|
| 2545 | + } elseif ( ! preg_match('/[^\x00-\x7F]/', $string)) { |
|
| 2546 | 2546 | return true; |
| 2547 | 2547 | } |
| 2548 | 2548 | |
@@ -2558,48 +2558,48 @@ discard block |
||
| 2558 | 2558 | * @param string $query The query to check. |
| 2559 | 2559 | * @return bool True if the collation is safe, false if it isn't. |
| 2560 | 2560 | */ |
| 2561 | - protected function check_safe_collation( $query ) { |
|
| 2562 | - if ( $this->checking_collation ) { |
|
| 2561 | + protected function check_safe_collation($query) { |
|
| 2562 | + if ($this->checking_collation) { |
|
| 2563 | 2563 | return true; |
| 2564 | 2564 | } |
| 2565 | 2565 | |
| 2566 | 2566 | // We don't need to check the collation for queries that don't read data. |
| 2567 | - $query = ltrim( $query, "\r\n\t (" ); |
|
| 2568 | - if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query ) ) { |
|
| 2567 | + $query = ltrim($query, "\r\n\t ("); |
|
| 2568 | + if (preg_match('/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query)) { |
|
| 2569 | 2569 | return true; |
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | // All-ASCII queries don't need extra checking. |
| 2573 | - if ( $this->check_ascii( $query ) ) { |
|
| 2573 | + if ($this->check_ascii($query)) { |
|
| 2574 | 2574 | return true; |
| 2575 | 2575 | } |
| 2576 | 2576 | |
| 2577 | - $table = $this->get_table_from_query( $query ); |
|
| 2578 | - if ( ! $table ) { |
|
| 2577 | + $table = $this->get_table_from_query($query); |
|
| 2578 | + if ( ! $table) { |
|
| 2579 | 2579 | return false; |
| 2580 | 2580 | } |
| 2581 | 2581 | |
| 2582 | 2582 | $this->checking_collation = true; |
| 2583 | - $collation = $this->get_table_charset( $table ); |
|
| 2583 | + $collation = $this->get_table_charset($table); |
|
| 2584 | 2584 | $this->checking_collation = false; |
| 2585 | 2585 | |
| 2586 | 2586 | // Tables with no collation, or latin1 only, don't need extra checking. |
| 2587 | - if ( false === $collation || 'latin1' === $collation ) { |
|
| 2587 | + if (false === $collation || 'latin1' === $collation) { |
|
| 2588 | 2588 | return true; |
| 2589 | 2589 | } |
| 2590 | 2590 | |
| 2591 | - $table = strtolower( $table ); |
|
| 2592 | - if ( empty( $this->col_meta[ $table ] ) ) { |
|
| 2591 | + $table = strtolower($table); |
|
| 2592 | + if (empty($this->col_meta[$table])) { |
|
| 2593 | 2593 | return false; |
| 2594 | 2594 | } |
| 2595 | 2595 | |
| 2596 | 2596 | // If any of the columns don't have one of these collations, it needs more sanity checking. |
| 2597 | - foreach( $this->col_meta[ $table ] as $col ) { |
|
| 2598 | - if ( empty( $col->Collation ) ) { |
|
| 2597 | + foreach ($this->col_meta[$table] as $col) { |
|
| 2598 | + if (empty($col->Collation)) { |
|
| 2599 | 2599 | continue; |
| 2600 | 2600 | } |
| 2601 | 2601 | |
| 2602 | - if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) { |
|
| 2602 | + if ( ! in_array($col->Collation, array('utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin'), true)) { |
|
| 2603 | 2603 | return false; |
| 2604 | 2604 | } |
| 2605 | 2605 | } |
@@ -2621,13 +2621,13 @@ discard block |
||
| 2621 | 2621 | * such as 'field' are retained in each value array. If we cannot |
| 2622 | 2622 | * remove invalid characters, a WP_Error object is returned. |
| 2623 | 2623 | */ |
| 2624 | - protected function strip_invalid_text( $data ) { |
|
| 2624 | + protected function strip_invalid_text($data) { |
|
| 2625 | 2625 | $db_check_string = false; |
| 2626 | 2626 | |
| 2627 | - foreach ( $data as &$value ) { |
|
| 2627 | + foreach ($data as &$value) { |
|
| 2628 | 2628 | $charset = $value['charset']; |
| 2629 | 2629 | |
| 2630 | - if ( is_array( $value['length'] ) ) { |
|
| 2630 | + if (is_array($value['length'])) { |
|
| 2631 | 2631 | $length = $value['length']['length']; |
| 2632 | 2632 | $truncate_by_byte_length = 'byte' === $value['length']['type']; |
| 2633 | 2633 | } else { |
@@ -2639,12 +2639,12 @@ discard block |
||
| 2639 | 2639 | } |
| 2640 | 2640 | |
| 2641 | 2641 | // There's no charset to work with. |
| 2642 | - if ( false === $charset ) { |
|
| 2642 | + if (false === $charset) { |
|
| 2643 | 2643 | continue; |
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | // Column isn't a string. |
| 2647 | - if ( ! is_string( $value['value'] ) ) { |
|
| 2647 | + if ( ! is_string($value['value'])) { |
|
| 2648 | 2648 | continue; |
| 2649 | 2649 | } |
| 2650 | 2650 | |
@@ -2654,26 +2654,26 @@ discard block |
||
| 2654 | 2654 | 'latin1' === $charset |
| 2655 | 2655 | || |
| 2656 | 2656 | // ASCII is always OK. |
| 2657 | - ( ! isset( $value['ascii'] ) && $this->check_ascii( $value['value'] ) ) |
|
| 2657 | + ( ! isset($value['ascii']) && $this->check_ascii($value['value'])) |
|
| 2658 | 2658 | ) { |
| 2659 | 2659 | $truncate_by_byte_length = true; |
| 2660 | 2660 | $needs_validation = false; |
| 2661 | 2661 | } |
| 2662 | 2662 | |
| 2663 | - if ( $truncate_by_byte_length ) { |
|
| 2663 | + if ($truncate_by_byte_length) { |
|
| 2664 | 2664 | mbstring_binary_safe_encoding(); |
| 2665 | - if ( false !== $length && strlen( $value['value'] ) > $length ) { |
|
| 2666 | - $value['value'] = substr( $value['value'], 0, $length ); |
|
| 2665 | + if (false !== $length && strlen($value['value']) > $length) { |
|
| 2666 | + $value['value'] = substr($value['value'], 0, $length); |
|
| 2667 | 2667 | } |
| 2668 | 2668 | reset_mbstring_encoding(); |
| 2669 | 2669 | |
| 2670 | - if ( ! $needs_validation ) { |
|
| 2670 | + if ( ! $needs_validation) { |
|
| 2671 | 2671 | continue; |
| 2672 | 2672 | } |
| 2673 | 2673 | } |
| 2674 | 2674 | |
| 2675 | 2675 | // utf8 can be handled by regex, which is a bunch faster than a DB lookup. |
| 2676 | - if ( ( 'utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset ) && function_exists( 'mb_strlen' ) ) { |
|
| 2676 | + if (('utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset) && function_exists('mb_strlen')) { |
|
| 2677 | 2677 | $regex = '/ |
| 2678 | 2678 | ( |
| 2679 | 2679 | (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx |
@@ -2683,7 +2683,7 @@ discard block |
||
| 2683 | 2683 | | \xED[\x80-\x9F][\x80-\xBF] |
| 2684 | 2684 | | [\xEE-\xEF][\x80-\xBF]{2}'; |
| 2685 | 2685 | |
| 2686 | - if ( 'utf8mb4' === $charset ) { |
|
| 2686 | + if ('utf8mb4' === $charset) { |
|
| 2687 | 2687 | $regex .= ' |
| 2688 | 2688 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 |
| 2689 | 2689 | | [\xF1-\xF3][\x80-\xBF]{3} |
@@ -2695,11 +2695,11 @@ discard block |
||
| 2695 | 2695 | ) |
| 2696 | 2696 | | . # anything else |
| 2697 | 2697 | /x'; |
| 2698 | - $value['value'] = preg_replace( $regex, '$1', $value['value'] ); |
|
| 2698 | + $value['value'] = preg_replace($regex, '$1', $value['value']); |
|
| 2699 | 2699 | |
| 2700 | 2700 | |
| 2701 | - if ( false !== $length && mb_strlen( $value['value'], 'UTF-8' ) > $length ) { |
|
| 2702 | - $value['value'] = mb_substr( $value['value'], 0, $length, 'UTF-8' ); |
|
| 2701 | + if (false !== $length && mb_strlen($value['value'], 'UTF-8') > $length) { |
|
| 2702 | + $value['value'] = mb_substr($value['value'], 0, $length, 'UTF-8'); |
|
| 2703 | 2703 | } |
| 2704 | 2704 | continue; |
| 2705 | 2705 | } |
@@ -2707,49 +2707,49 @@ discard block |
||
| 2707 | 2707 | // We couldn't use any local conversions, send it to the DB. |
| 2708 | 2708 | $value['db'] = $db_check_string = true; |
| 2709 | 2709 | } |
| 2710 | - unset( $value ); // Remove by reference. |
|
| 2710 | + unset($value); // Remove by reference. |
|
| 2711 | 2711 | |
| 2712 | - if ( $db_check_string ) { |
|
| 2712 | + if ($db_check_string) { |
|
| 2713 | 2713 | $queries = array(); |
| 2714 | - foreach ( $data as $col => $value ) { |
|
| 2715 | - if ( ! empty( $value['db'] ) ) { |
|
| 2714 | + foreach ($data as $col => $value) { |
|
| 2715 | + if ( ! empty($value['db'])) { |
|
| 2716 | 2716 | // We're going to need to truncate by characters or bytes, depending on the length value we have. |
| 2717 | - if ( 'byte' === $value['length']['type'] ) { |
|
| 2717 | + if ('byte' === $value['length']['type']) { |
|
| 2718 | 2718 | // Using binary causes LEFT() to truncate by bytes. |
| 2719 | 2719 | $charset = 'binary'; |
| 2720 | 2720 | } else { |
| 2721 | 2721 | $charset = $value['charset']; |
| 2722 | 2722 | } |
| 2723 | 2723 | |
| 2724 | - if ( is_array( $value['length'] ) ) { |
|
| 2725 | - $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] ); |
|
| 2726 | - } else if ( 'binary' !== $charset ) { |
|
| 2724 | + if (is_array($value['length'])) { |
|
| 2725 | + $queries[$col] = $this->prepare("CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length']); |
|
| 2726 | + } else if ('binary' !== $charset) { |
|
| 2727 | 2727 | // If we don't have a length, there's no need to convert binary - it will always return the same result. |
| 2728 | - $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING {$this->charset} )", $value['value'] ); |
|
| 2728 | + $queries[$col] = $this->prepare("CONVERT( CONVERT( %s USING $charset ) USING {$this->charset} )", $value['value']); |
|
| 2729 | 2729 | } |
| 2730 | 2730 | |
| 2731 | - unset( $data[ $col ]['db'] ); |
|
| 2731 | + unset($data[$col]['db']); |
|
| 2732 | 2732 | } |
| 2733 | 2733 | } |
| 2734 | 2734 | |
| 2735 | 2735 | $sql = array(); |
| 2736 | - foreach ( $queries as $column => $query ) { |
|
| 2737 | - if ( ! $query ) { |
|
| 2736 | + foreach ($queries as $column => $query) { |
|
| 2737 | + if ( ! $query) { |
|
| 2738 | 2738 | continue; |
| 2739 | 2739 | } |
| 2740 | 2740 | |
| 2741 | - $sql[] = $query . " AS x_$column"; |
|
| 2741 | + $sql[] = $query." AS x_$column"; |
|
| 2742 | 2742 | } |
| 2743 | 2743 | |
| 2744 | 2744 | $this->check_current_query = false; |
| 2745 | - $row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A ); |
|
| 2746 | - if ( ! $row ) { |
|
| 2747 | - return new WP_Error( 'wpdb_strip_invalid_text_failure' ); |
|
| 2745 | + $row = $this->get_row("SELECT ".implode(', ', $sql), ARRAY_A); |
|
| 2746 | + if ( ! $row) { |
|
| 2747 | + return new WP_Error('wpdb_strip_invalid_text_failure'); |
|
| 2748 | 2748 | } |
| 2749 | 2749 | |
| 2750 | - foreach ( array_keys( $data ) as $column ) { |
|
| 2751 | - if ( isset( $row["x_$column"] ) ) { |
|
| 2752 | - $data[ $column ]['value'] = $row["x_$column"]; |
|
| 2750 | + foreach (array_keys($data) as $column) { |
|
| 2751 | + if (isset($row["x_$column"])) { |
|
| 2752 | + $data[$column]['value'] = $row["x_$column"]; |
|
| 2753 | 2753 | } |
| 2754 | 2754 | } |
| 2755 | 2755 | } |
@@ -2766,22 +2766,22 @@ discard block |
||
| 2766 | 2766 | * @param string $query Query to convert. |
| 2767 | 2767 | * @return string|WP_Error The converted query, or a WP_Error object if the conversion fails. |
| 2768 | 2768 | */ |
| 2769 | - protected function strip_invalid_text_from_query( $query ) { |
|
| 2769 | + protected function strip_invalid_text_from_query($query) { |
|
| 2770 | 2770 | // We don't need to check the collation for queries that don't read data. |
| 2771 | - $trimmed_query = ltrim( $query, "\r\n\t (" ); |
|
| 2772 | - if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query ) ) { |
|
| 2771 | + $trimmed_query = ltrim($query, "\r\n\t ("); |
|
| 2772 | + if (preg_match('/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query)) { |
|
| 2773 | 2773 | return $query; |
| 2774 | 2774 | } |
| 2775 | 2775 | |
| 2776 | - $table = $this->get_table_from_query( $query ); |
|
| 2777 | - if ( $table ) { |
|
| 2778 | - $charset = $this->get_table_charset( $table ); |
|
| 2779 | - if ( is_wp_error( $charset ) ) { |
|
| 2776 | + $table = $this->get_table_from_query($query); |
|
| 2777 | + if ($table) { |
|
| 2778 | + $charset = $this->get_table_charset($table); |
|
| 2779 | + if (is_wp_error($charset)) { |
|
| 2780 | 2780 | return $charset; |
| 2781 | 2781 | } |
| 2782 | 2782 | |
| 2783 | 2783 | // We can't reliably strip text from tables containing binary/blob columns |
| 2784 | - if ( 'binary' === $charset ) { |
|
| 2784 | + if ('binary' === $charset) { |
|
| 2785 | 2785 | return $query; |
| 2786 | 2786 | } |
| 2787 | 2787 | } else { |
@@ -2795,8 +2795,8 @@ discard block |
||
| 2795 | 2795 | 'length' => false, |
| 2796 | 2796 | ); |
| 2797 | 2797 | |
| 2798 | - $data = $this->strip_invalid_text( array( $data ) ); |
|
| 2799 | - if ( is_wp_error( $data ) ) { |
|
| 2798 | + $data = $this->strip_invalid_text(array($data)); |
|
| 2799 | + if (is_wp_error($data)) { |
|
| 2800 | 2800 | return $data; |
| 2801 | 2801 | } |
| 2802 | 2802 | |
@@ -2814,16 +2814,16 @@ discard block |
||
| 2814 | 2814 | * @param string $value The text to check. |
| 2815 | 2815 | * @return string|WP_Error The converted string, or a WP_Error object if the conversion fails. |
| 2816 | 2816 | */ |
| 2817 | - public function strip_invalid_text_for_column( $table, $column, $value ) { |
|
| 2818 | - if ( ! is_string( $value ) ) { |
|
| 2817 | + public function strip_invalid_text_for_column($table, $column, $value) { |
|
| 2818 | + if ( ! is_string($value)) { |
|
| 2819 | 2819 | return $value; |
| 2820 | 2820 | } |
| 2821 | 2821 | |
| 2822 | - $charset = $this->get_col_charset( $table, $column ); |
|
| 2823 | - if ( ! $charset ) { |
|
| 2822 | + $charset = $this->get_col_charset($table, $column); |
|
| 2823 | + if ( ! $charset) { |
|
| 2824 | 2824 | // Not a string column. |
| 2825 | 2825 | return $value; |
| 2826 | - } elseif ( is_wp_error( $charset ) ) { |
|
| 2826 | + } elseif (is_wp_error($charset)) { |
|
| 2827 | 2827 | // Bail on real errors. |
| 2828 | 2828 | return $charset; |
| 2829 | 2829 | } |
@@ -2832,16 +2832,16 @@ discard block |
||
| 2832 | 2832 | $column => array( |
| 2833 | 2833 | 'value' => $value, |
| 2834 | 2834 | 'charset' => $charset, |
| 2835 | - 'length' => $this->get_col_length( $table, $column ), |
|
| 2835 | + 'length' => $this->get_col_length($table, $column), |
|
| 2836 | 2836 | ) |
| 2837 | 2837 | ); |
| 2838 | 2838 | |
| 2839 | - $data = $this->strip_invalid_text( $data ); |
|
| 2840 | - if ( is_wp_error( $data ) ) { |
|
| 2839 | + $data = $this->strip_invalid_text($data); |
|
| 2840 | + if (is_wp_error($data)) { |
|
| 2841 | 2841 | return $data; |
| 2842 | 2842 | } |
| 2843 | 2843 | |
| 2844 | - return $data[ $column ]['value']; |
|
| 2844 | + return $data[$column]['value']; |
|
| 2845 | 2845 | } |
| 2846 | 2846 | |
| 2847 | 2847 | /** |
@@ -2853,37 +2853,37 @@ discard block |
||
| 2853 | 2853 | * @param string $query The query to search. |
| 2854 | 2854 | * @return string|false $table The table name found, or false if a table couldn't be found. |
| 2855 | 2855 | */ |
| 2856 | - protected function get_table_from_query( $query ) { |
|
| 2856 | + protected function get_table_from_query($query) { |
|
| 2857 | 2857 | // Remove characters that can legally trail the table name. |
| 2858 | - $query = rtrim( $query, ';/-#' ); |
|
| 2858 | + $query = rtrim($query, ';/-#'); |
|
| 2859 | 2859 | |
| 2860 | 2860 | // Allow (select...) union [...] style queries. Use the first query's table name. |
| 2861 | - $query = ltrim( $query, "\r\n\t (" ); |
|
| 2861 | + $query = ltrim($query, "\r\n\t ("); |
|
| 2862 | 2862 | |
| 2863 | 2863 | // Strip everything between parentheses except nested selects. |
| 2864 | - $query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', $query ); |
|
| 2864 | + $query = preg_replace('/\((?!\s*select)[^(]*?\)/is', '()', $query); |
|
| 2865 | 2865 | |
| 2866 | 2866 | // Quickly match most common queries. |
| 2867 | - if ( preg_match( '/^\s*(?:' |
|
| 2867 | + if (preg_match('/^\s*(?:' |
|
| 2868 | 2868 | . 'SELECT.*?\s+FROM' |
| 2869 | 2869 | . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' |
| 2870 | 2870 | . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' |
| 2871 | 2871 | . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' |
| 2872 | 2872 | . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' |
| 2873 | - . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) { |
|
| 2874 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2873 | + . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe)) { |
|
| 2874 | + return str_replace('`', '', $maybe[1]); |
|
| 2875 | 2875 | } |
| 2876 | 2876 | |
| 2877 | 2877 | // SHOW TABLE STATUS and SHOW TABLES |
| 2878 | - if ( preg_match( '/^\s*(?:' |
|
| 2878 | + if (preg_match('/^\s*(?:' |
|
| 2879 | 2879 | . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' |
| 2880 | 2880 | . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' |
| 2881 | - . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) { |
|
| 2882 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2881 | + . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe)) { |
|
| 2882 | + return str_replace('`', '', $maybe[1]); |
|
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | 2885 | // Big pattern for the rest of the table-related queries. |
| 2886 | - if ( preg_match( '/^\s*(?:' |
|
| 2886 | + if (preg_match('/^\s*(?:' |
|
| 2887 | 2887 | . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' |
| 2888 | 2888 | . '|DESCRIBE|DESC|EXPLAIN|HANDLER' |
| 2889 | 2889 | . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?' |
@@ -2897,8 +2897,8 @@ discard block |
||
| 2897 | 2897 | . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE' |
| 2898 | 2898 | . '|(?:GRANT|REVOKE).*ON\s+TABLE' |
| 2899 | 2899 | . '|SHOW\s+(?:.*FROM|.*TABLE)' |
| 2900 | - . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) { |
|
| 2901 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2900 | + . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe)) { |
|
| 2901 | + return str_replace('`', '', $maybe[1]); |
|
| 2902 | 2902 | } |
| 2903 | 2903 | |
| 2904 | 2904 | return false; |
@@ -2912,18 +2912,18 @@ discard block |
||
| 2912 | 2912 | * @access protected |
| 2913 | 2913 | */ |
| 2914 | 2914 | protected function load_col_info() { |
| 2915 | - if ( $this->col_info ) |
|
| 2915 | + if ($this->col_info) |
|
| 2916 | 2916 | return; |
| 2917 | 2917 | |
| 2918 | - if ( $this->use_mysqli ) { |
|
| 2919 | - $num_fields = @mysqli_num_fields( $this->result ); |
|
| 2920 | - for ( $i = 0; $i < $num_fields; $i++ ) { |
|
| 2921 | - $this->col_info[ $i ] = @mysqli_fetch_field( $this->result ); |
|
| 2918 | + if ($this->use_mysqli) { |
|
| 2919 | + $num_fields = @mysqli_num_fields($this->result); |
|
| 2920 | + for ($i = 0; $i < $num_fields; $i++) { |
|
| 2921 | + $this->col_info[$i] = @mysqli_fetch_field($this->result); |
|
| 2922 | 2922 | } |
| 2923 | 2923 | } else { |
| 2924 | - $num_fields = @mysql_num_fields( $this->result ); |
|
| 2925 | - for ( $i = 0; $i < $num_fields; $i++ ) { |
|
| 2926 | - $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); |
|
| 2924 | + $num_fields = @mysql_num_fields($this->result); |
|
| 2925 | + for ($i = 0; $i < $num_fields; $i++) { |
|
| 2926 | + $this->col_info[$i] = @mysql_fetch_field($this->result, $i); |
|
| 2927 | 2927 | } |
| 2928 | 2928 | } |
| 2929 | 2929 | } |
@@ -2937,14 +2937,14 @@ discard block |
||
| 2937 | 2937 | * @param int $col_offset Optional. 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type |
| 2938 | 2938 | * @return mixed Column Results |
| 2939 | 2939 | */ |
| 2940 | - public function get_col_info( $info_type = 'name', $col_offset = -1 ) { |
|
| 2940 | + public function get_col_info($info_type = 'name', $col_offset = -1) { |
|
| 2941 | 2941 | $this->load_col_info(); |
| 2942 | 2942 | |
| 2943 | - if ( $this->col_info ) { |
|
| 2944 | - if ( $col_offset == -1 ) { |
|
| 2943 | + if ($this->col_info) { |
|
| 2944 | + if ($col_offset == -1) { |
|
| 2945 | 2945 | $i = 0; |
| 2946 | 2946 | $new_array = array(); |
| 2947 | - foreach( (array) $this->col_info as $col ) { |
|
| 2947 | + foreach ((array) $this->col_info as $col) { |
|
| 2948 | 2948 | $new_array[$i] = $col->{$info_type}; |
| 2949 | 2949 | $i++; |
| 2950 | 2950 | } |
@@ -2963,7 +2963,7 @@ discard block |
||
| 2963 | 2963 | * @return true |
| 2964 | 2964 | */ |
| 2965 | 2965 | public function timer_start() { |
| 2966 | - $this->time_start = microtime( true ); |
|
| 2966 | + $this->time_start = microtime(true); |
|
| 2967 | 2967 | return true; |
| 2968 | 2968 | } |
| 2969 | 2969 | |
@@ -2975,7 +2975,7 @@ discard block |
||
| 2975 | 2975 | * @return float Total time spent on the query, in seconds |
| 2976 | 2976 | */ |
| 2977 | 2977 | public function timer_stop() { |
| 2978 | - return ( microtime( true ) - $this->time_start ); |
|
| 2978 | + return (microtime(true) - $this->time_start); |
|
| 2979 | 2979 | } |
| 2980 | 2980 | |
| 2981 | 2981 | /** |
@@ -2989,9 +2989,9 @@ discard block |
||
| 2989 | 2989 | * @param string $error_code Optional. A Computer readable string to identify the error. |
| 2990 | 2990 | * @return false|void |
| 2991 | 2991 | */ |
| 2992 | - public function bail( $message, $error_code = '500' ) { |
|
| 2993 | - if ( !$this->show_errors ) { |
|
| 2994 | - if ( class_exists( 'WP_Error' ) ) |
|
| 2992 | + public function bail($message, $error_code = '500') { |
|
| 2993 | + if ( ! $this->show_errors) { |
|
| 2994 | + if (class_exists('WP_Error')) |
|
| 2995 | 2995 | $this->error = new WP_Error($error_code, $message); |
| 2996 | 2996 | else |
| 2997 | 2997 | $this->error = $message; |
@@ -3013,8 +3013,8 @@ discard block |
||
| 3013 | 3013 | public function check_database_version() { |
| 3014 | 3014 | global $wp_version, $required_mysql_version; |
| 3015 | 3015 | // Make sure the server has the required MySQL version |
| 3016 | - if ( version_compare($this->db_version(), $required_mysql_version, '<') ) |
|
| 3017 | - return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3016 | + if (version_compare($this->db_version(), $required_mysql_version, '<')) |
|
| 3017 | + return new WP_Error('database_version', sprintf(__('<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher'), $wp_version, $required_mysql_version)); |
|
| 3018 | 3018 | } |
| 3019 | 3019 | |
| 3020 | 3020 | /** |
@@ -3029,8 +3029,8 @@ discard block |
||
| 3029 | 3029 | * @return bool True if collation is supported, false if version does not |
| 3030 | 3030 | */ |
| 3031 | 3031 | public function supports_collation() { |
| 3032 | - _deprecated_function( __FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )' ); |
|
| 3033 | - return $this->has_cap( 'collation' ); |
|
| 3032 | + _deprecated_function(__FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )'); |
|
| 3033 | + return $this->has_cap('collation'); |
|
| 3034 | 3034 | } |
| 3035 | 3035 | |
| 3036 | 3036 | /** |
@@ -3043,9 +3043,9 @@ discard block |
||
| 3043 | 3043 | public function get_charset_collate() { |
| 3044 | 3044 | $charset_collate = ''; |
| 3045 | 3045 | |
| 3046 | - if ( ! empty( $this->charset ) ) |
|
| 3046 | + if ( ! empty($this->charset)) |
|
| 3047 | 3047 | $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
| 3048 | - if ( ! empty( $this->collate ) ) |
|
| 3048 | + if ( ! empty($this->collate)) |
|
| 3049 | 3049 | $charset_collate .= " COLLATE $this->collate"; |
| 3050 | 3050 | |
| 3051 | 3051 | return $charset_collate; |
@@ -3064,21 +3064,21 @@ discard block |
||
| 3064 | 3064 | * or 'utf8mb4'. |
| 3065 | 3065 | * @return int|false Whether the database feature is supported, false otherwise. |
| 3066 | 3066 | */ |
| 3067 | - public function has_cap( $db_cap ) { |
|
| 3067 | + public function has_cap($db_cap) { |
|
| 3068 | 3068 | $version = $this->db_version(); |
| 3069 | 3069 | |
| 3070 | - switch ( strtolower( $db_cap ) ) { |
|
| 3070 | + switch (strtolower($db_cap)) { |
|
| 3071 | 3071 | case 'collation' : // @since 2.5.0 |
| 3072 | 3072 | case 'group_concat' : // @since 2.7.0 |
| 3073 | 3073 | case 'subqueries' : // @since 2.7.0 |
| 3074 | - return version_compare( $version, '4.1', '>=' ); |
|
| 3074 | + return version_compare($version, '4.1', '>='); |
|
| 3075 | 3075 | case 'set_charset' : |
| 3076 | - return version_compare( $version, '5.0.7', '>=' ); |
|
| 3076 | + return version_compare($version, '5.0.7', '>='); |
|
| 3077 | 3077 | case 'utf8mb4' : // @since 4.1.0 |
| 3078 | - if ( version_compare( $version, '5.5.3', '<' ) ) { |
|
| 3078 | + if (version_compare($version, '5.5.3', '<')) { |
|
| 3079 | 3079 | return false; |
| 3080 | 3080 | } |
| 3081 | - if ( $this->use_mysqli ) { |
|
| 3081 | + if ($this->use_mysqli) { |
|
| 3082 | 3082 | $client_version = mysqli_get_client_info(); |
| 3083 | 3083 | } else { |
| 3084 | 3084 | $client_version = mysql_get_client_info(); |
@@ -3088,11 +3088,11 @@ discard block |
||
| 3088 | 3088 | * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server. |
| 3089 | 3089 | * mysqlnd has supported utf8mb4 since 5.0.9. |
| 3090 | 3090 | */ |
| 3091 | - if ( false !== strpos( $client_version, 'mysqlnd' ) ) { |
|
| 3092 | - $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version ); |
|
| 3093 | - return version_compare( $client_version, '5.0.9', '>=' ); |
|
| 3091 | + if (false !== strpos($client_version, 'mysqlnd')) { |
|
| 3092 | + $client_version = preg_replace('/^\D+([\d.]+).*/', '$1', $client_version); |
|
| 3093 | + return version_compare($client_version, '5.0.9', '>='); |
|
| 3094 | 3094 | } else { |
| 3095 | - return version_compare( $client_version, '5.5.3', '>=' ); |
|
| 3095 | + return version_compare($client_version, '5.5.3', '>='); |
|
| 3096 | 3096 | } |
| 3097 | 3097 | } |
| 3098 | 3098 | |
@@ -3110,7 +3110,7 @@ discard block |
||
| 3110 | 3110 | * @return string|array The name of the calling function |
| 3111 | 3111 | */ |
| 3112 | 3112 | public function get_caller() { |
| 3113 | - return wp_debug_backtrace_summary( __CLASS__ ); |
|
| 3113 | + return wp_debug_backtrace_summary(__CLASS__); |
|
| 3114 | 3114 | } |
| 3115 | 3115 | |
| 3116 | 3116 | /** |
@@ -3121,11 +3121,11 @@ discard block |
||
| 3121 | 3121 | * @return null|string Null on failure, version number on success. |
| 3122 | 3122 | */ |
| 3123 | 3123 | public function db_version() { |
| 3124 | - if ( $this->use_mysqli ) { |
|
| 3125 | - $server_info = mysqli_get_server_info( $this->dbh ); |
|
| 3124 | + if ($this->use_mysqli) { |
|
| 3125 | + $server_info = mysqli_get_server_info($this->dbh); |
|
| 3126 | 3126 | } else { |
| 3127 | - $server_info = mysql_get_server_info( $this->dbh ); |
|
| 3127 | + $server_info = mysql_get_server_info($this->dbh); |
|
| 3128 | 3128 | } |
| 3129 | - return preg_replace( '/[^0-9.].*/', '', $server_info ); |
|
| 3129 | + return preg_replace('/[^0-9.].*/', '', $server_info); |
|
| 3130 | 3130 | } |
| 3131 | 3131 | } |
@@ -617,8 +617,9 @@ discard block |
||
| 617 | 617 | public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { |
| 618 | 618 | register_shutdown_function( array( $this, '__destruct' ) ); |
| 619 | 619 | |
| 620 | - if ( WP_DEBUG && WP_DEBUG_DISPLAY ) |
|
| 621 | - $this->show_errors(); |
|
| 620 | + if ( WP_DEBUG && WP_DEBUG_DISPLAY ) { |
|
| 621 | + $this->show_errors(); |
|
| 622 | + } |
|
| 622 | 623 | |
| 623 | 624 | /* Use ext/mysqli if it exists and: |
| 624 | 625 | * - WP_USE_EXT_MYSQL is defined as false, or |
@@ -669,8 +670,9 @@ discard block |
||
| 669 | 670 | * @return mixed The private member |
| 670 | 671 | */ |
| 671 | 672 | public function __get( $name ) { |
| 672 | - if ( 'col_info' === $name ) |
|
| 673 | - $this->load_col_info(); |
|
| 673 | + if ( 'col_info' === $name ) { |
|
| 674 | + $this->load_col_info(); |
|
| 675 | + } |
|
| 674 | 676 | |
| 675 | 677 | return $this->$name; |
| 676 | 678 | } |
@@ -763,18 +765,21 @@ discard block |
||
| 763 | 765 | * @param string $collate Optional. The collation. Default null. |
| 764 | 766 | */ |
| 765 | 767 | public function set_charset( $dbh, $charset = null, $collate = null ) { |
| 766 | - if ( ! isset( $charset ) ) |
|
| 767 | - $charset = $this->charset; |
|
| 768 | - if ( ! isset( $collate ) ) |
|
| 769 | - $collate = $this->collate; |
|
| 768 | + if ( ! isset( $charset ) ) { |
|
| 769 | + $charset = $this->charset; |
|
| 770 | + } |
|
| 771 | + if ( ! isset( $collate ) ) { |
|
| 772 | + $collate = $this->collate; |
|
| 773 | + } |
|
| 770 | 774 | if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { |
| 771 | 775 | if ( $this->use_mysqli ) { |
| 772 | 776 | if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
| 773 | 777 | mysqli_set_charset( $dbh, $charset ); |
| 774 | 778 | } else { |
| 775 | 779 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 776 | - if ( ! empty( $collate ) ) |
|
| 777 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 780 | + if ( ! empty( $collate ) ) { |
|
| 781 | + $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 782 | + } |
|
| 778 | 783 | mysqli_query( $dbh, $query ); |
| 779 | 784 | } |
| 780 | 785 | } else { |
@@ -782,8 +787,9 @@ discard block |
||
| 782 | 787 | mysql_set_charset( $charset, $dbh ); |
| 783 | 788 | } else { |
| 784 | 789 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 785 | - if ( ! empty( $collate ) ) |
|
| 786 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 790 | + if ( ! empty( $collate ) ) { |
|
| 791 | + $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 792 | + } |
|
| 787 | 793 | mysql_query( $query, $dbh ); |
| 788 | 794 | } |
| 789 | 795 | } |
@@ -866,30 +872,36 @@ discard block |
||
| 866 | 872 | */ |
| 867 | 873 | public function set_prefix( $prefix, $set_table_names = true ) { |
| 868 | 874 | |
| 869 | - if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) |
|
| 870 | - return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 875 | + if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { |
|
| 876 | + return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 877 | + } |
|
| 871 | 878 | |
| 872 | 879 | $old_prefix = is_multisite() ? '' : $prefix; |
| 873 | 880 | |
| 874 | - if ( isset( $this->base_prefix ) ) |
|
| 875 | - $old_prefix = $this->base_prefix; |
|
| 881 | + if ( isset( $this->base_prefix ) ) { |
|
| 882 | + $old_prefix = $this->base_prefix; |
|
| 883 | + } |
|
| 876 | 884 | |
| 877 | 885 | $this->base_prefix = $prefix; |
| 878 | 886 | |
| 879 | 887 | if ( $set_table_names ) { |
| 880 | - foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) |
|
| 881 | - $this->$table = $prefixed_table; |
|
| 888 | + foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) { |
|
| 889 | + $this->$table = $prefixed_table; |
|
| 890 | + } |
|
| 882 | 891 | |
| 883 | - if ( is_multisite() && empty( $this->blogid ) ) |
|
| 884 | - return $old_prefix; |
|
| 892 | + if ( is_multisite() && empty( $this->blogid ) ) { |
|
| 893 | + return $old_prefix; |
|
| 894 | + } |
|
| 885 | 895 | |
| 886 | 896 | $this->prefix = $this->get_blog_prefix(); |
| 887 | 897 | |
| 888 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 889 | - $this->$table = $prefixed_table; |
|
| 898 | + foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { |
|
| 899 | + $this->$table = $prefixed_table; |
|
| 900 | + } |
|
| 890 | 901 | |
| 891 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 892 | - $this->$table = $prefixed_table; |
|
| 902 | + foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { |
|
| 903 | + $this->$table = $prefixed_table; |
|
| 904 | + } |
|
| 893 | 905 | } |
| 894 | 906 | return $old_prefix; |
| 895 | 907 | } |
@@ -905,19 +917,22 @@ discard block |
||
| 905 | 917 | * @return int previous blog id |
| 906 | 918 | */ |
| 907 | 919 | public function set_blog_id( $blog_id, $site_id = 0 ) { |
| 908 | - if ( ! empty( $site_id ) ) |
|
| 909 | - $this->siteid = $site_id; |
|
| 920 | + if ( ! empty( $site_id ) ) { |
|
| 921 | + $this->siteid = $site_id; |
|
| 922 | + } |
|
| 910 | 923 | |
| 911 | 924 | $old_blog_id = $this->blogid; |
| 912 | 925 | $this->blogid = $blog_id; |
| 913 | 926 | |
| 914 | 927 | $this->prefix = $this->get_blog_prefix(); |
| 915 | 928 | |
| 916 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 917 | - $this->$table = $prefixed_table; |
|
| 929 | + foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { |
|
| 930 | + $this->$table = $prefixed_table; |
|
| 931 | + } |
|
| 918 | 932 | |
| 919 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 920 | - $this->$table = $prefixed_table; |
|
| 933 | + foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { |
|
| 934 | + $this->$table = $prefixed_table; |
|
| 935 | + } |
|
| 921 | 936 | |
| 922 | 937 | return $old_blog_id; |
| 923 | 938 | } |
@@ -931,13 +946,15 @@ discard block |
||
| 931 | 946 | */ |
| 932 | 947 | public function get_blog_prefix( $blog_id = null ) { |
| 933 | 948 | if ( is_multisite() ) { |
| 934 | - if ( null === $blog_id ) |
|
| 935 | - $blog_id = $this->blogid; |
|
| 949 | + if ( null === $blog_id ) { |
|
| 950 | + $blog_id = $this->blogid; |
|
| 951 | + } |
|
| 936 | 952 | $blog_id = (int) $blog_id; |
| 937 | - if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) |
|
| 938 | - return $this->base_prefix; |
|
| 939 | - else |
|
| 940 | - return $this->base_prefix . $blog_id . '_'; |
|
| 953 | + if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) { |
|
| 954 | + return $this->base_prefix; |
|
| 955 | + } else { |
|
| 956 | + return $this->base_prefix . $blog_id . '_'; |
|
| 957 | + } |
|
| 941 | 958 | } else { |
| 942 | 959 | return $this->base_prefix; |
| 943 | 960 | } |
@@ -974,16 +991,18 @@ discard block |
||
| 974 | 991 | switch ( $scope ) { |
| 975 | 992 | case 'all' : |
| 976 | 993 | $tables = array_merge( $this->global_tables, $this->tables ); |
| 977 | - if ( is_multisite() ) |
|
| 978 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 994 | + if ( is_multisite() ) { |
|
| 995 | + $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 996 | + } |
|
| 979 | 997 | break; |
| 980 | 998 | case 'blog' : |
| 981 | 999 | $tables = $this->tables; |
| 982 | 1000 | break; |
| 983 | 1001 | case 'global' : |
| 984 | 1002 | $tables = $this->global_tables; |
| 985 | - if ( is_multisite() ) |
|
| 986 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1003 | + if ( is_multisite() ) { |
|
| 1004 | + $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1005 | + } |
|
| 987 | 1006 | break; |
| 988 | 1007 | case 'ms_global' : |
| 989 | 1008 | $tables = $this->ms_global_tables; |
@@ -996,24 +1015,28 @@ discard block |
||
| 996 | 1015 | } |
| 997 | 1016 | |
| 998 | 1017 | if ( $prefix ) { |
| 999 | - if ( ! $blog_id ) |
|
| 1000 | - $blog_id = $this->blogid; |
|
| 1018 | + if ( ! $blog_id ) { |
|
| 1019 | + $blog_id = $this->blogid; |
|
| 1020 | + } |
|
| 1001 | 1021 | $blog_prefix = $this->get_blog_prefix( $blog_id ); |
| 1002 | 1022 | $base_prefix = $this->base_prefix; |
| 1003 | 1023 | $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); |
| 1004 | 1024 | foreach ( $tables as $k => $table ) { |
| 1005 | - if ( in_array( $table, $global_tables ) ) |
|
| 1006 | - $tables[ $table ] = $base_prefix . $table; |
|
| 1007 | - else |
|
| 1008 | - $tables[ $table ] = $blog_prefix . $table; |
|
| 1025 | + if ( in_array( $table, $global_tables ) ) { |
|
| 1026 | + $tables[ $table ] = $base_prefix . $table; |
|
| 1027 | + } else { |
|
| 1028 | + $tables[ $table ] = $blog_prefix . $table; |
|
| 1029 | + } |
|
| 1009 | 1030 | unset( $tables[ $k ] ); |
| 1010 | 1031 | } |
| 1011 | 1032 | |
| 1012 | - if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) |
|
| 1013 | - $tables['users'] = CUSTOM_USER_TABLE; |
|
| 1033 | + if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) { |
|
| 1034 | + $tables['users'] = CUSTOM_USER_TABLE; |
|
| 1035 | + } |
|
| 1014 | 1036 | |
| 1015 | - if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) |
|
| 1016 | - $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
|
| 1037 | + if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) { |
|
| 1038 | + $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
|
| 1039 | + } |
|
| 1017 | 1040 | } |
| 1018 | 1041 | |
| 1019 | 1042 | return $tables; |
@@ -1031,8 +1054,9 @@ discard block |
||
| 1031 | 1054 | * @param resource|null $dbh Optional link identifier. |
| 1032 | 1055 | */ |
| 1033 | 1056 | public function select( $db, $dbh = null ) { |
| 1034 | - if ( is_null($dbh) ) |
|
| 1035 | - $dbh = $this->dbh; |
|
| 1057 | + if ( is_null($dbh) ) { |
|
| 1058 | + $dbh = $this->dbh; |
|
| 1059 | + } |
|
| 1036 | 1060 | |
| 1037 | 1061 | if ( $this->use_mysqli ) { |
| 1038 | 1062 | $success = @mysqli_select_db( $dbh, $db ); |
@@ -1070,8 +1094,9 @@ discard block |
||
| 1070 | 1094 | * @return string |
| 1071 | 1095 | */ |
| 1072 | 1096 | function _weak_escape( $string ) { |
| 1073 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1074 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1097 | + if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { |
|
| 1098 | + _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1099 | + } |
|
| 1075 | 1100 | return addslashes( $string ); |
| 1076 | 1101 | } |
| 1077 | 1102 | |
@@ -1117,10 +1142,11 @@ discard block |
||
| 1117 | 1142 | function _escape( $data ) { |
| 1118 | 1143 | if ( is_array( $data ) ) { |
| 1119 | 1144 | foreach ( $data as $k => $v ) { |
| 1120 | - if ( is_array($v) ) |
|
| 1121 | - $data[$k] = $this->_escape( $v ); |
|
| 1122 | - else |
|
| 1123 | - $data[$k] = $this->_real_escape( $v ); |
|
| 1145 | + if ( is_array($v) ) { |
|
| 1146 | + $data[$k] = $this->_escape( $v ); |
|
| 1147 | + } else { |
|
| 1148 | + $data[$k] = $this->_real_escape( $v ); |
|
| 1149 | + } |
|
| 1124 | 1150 | } |
| 1125 | 1151 | } else { |
| 1126 | 1152 | $data = $this->_real_escape( $data ); |
@@ -1143,14 +1169,16 @@ discard block |
||
| 1143 | 1169 | * @return mixed |
| 1144 | 1170 | */ |
| 1145 | 1171 | public function escape( $data ) { |
| 1146 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1147 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1172 | + if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { |
|
| 1173 | + _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1174 | + } |
|
| 1148 | 1175 | if ( is_array( $data ) ) { |
| 1149 | 1176 | foreach ( $data as $k => $v ) { |
| 1150 | - if ( is_array( $v ) ) |
|
| 1151 | - $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1152 | - else |
|
| 1153 | - $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1177 | + if ( is_array( $v ) ) { |
|
| 1178 | + $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1179 | + } else { |
|
| 1180 | + $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1181 | + } |
|
| 1154 | 1182 | } |
| 1155 | 1183 | } else { |
| 1156 | 1184 | $data = $this->_weak_escape( $data, 'internal' ); |
@@ -1169,8 +1197,9 @@ discard block |
||
| 1169 | 1197 | * @param string $string to escape |
| 1170 | 1198 | */ |
| 1171 | 1199 | public function escape_by_ref( &$string ) { |
| 1172 | - if ( ! is_float( $string ) ) |
|
| 1173 | - $string = $this->_real_escape( $string ); |
|
| 1200 | + if ( ! is_float( $string ) ) { |
|
| 1201 | + $string = $this->_real_escape( $string ); |
|
| 1202 | + } |
|
| 1174 | 1203 | } |
| 1175 | 1204 | |
| 1176 | 1205 | /** |
@@ -1208,8 +1237,9 @@ discard block |
||
| 1208 | 1237 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1209 | 1238 | */ |
| 1210 | 1239 | public function prepare( $query, $args ) { |
| 1211 | - if ( is_null( $query ) ) |
|
| 1212 | - return; |
|
| 1240 | + if ( is_null( $query ) ) { |
|
| 1241 | + return; |
|
| 1242 | + } |
|
| 1213 | 1243 | |
| 1214 | 1244 | // This is not meant to be foolproof -- but it will catch obviously incorrect usage. |
| 1215 | 1245 | if ( strpos( $query, '%' ) === false ) { |
@@ -1219,8 +1249,9 @@ discard block |
||
| 1219 | 1249 | $args = func_get_args(); |
| 1220 | 1250 | array_shift( $args ); |
| 1221 | 1251 | // If args were passed as an array (as in vsprintf), move them up |
| 1222 | - if ( isset( $args[0] ) && is_array($args[0]) ) |
|
| 1223 | - $args = $args[0]; |
|
| 1252 | + if ( isset( $args[0] ) && is_array($args[0]) ) { |
|
| 1253 | + $args = $args[0]; |
|
| 1254 | + } |
|
| 1224 | 1255 | $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it |
| 1225 | 1256 | $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting |
| 1226 | 1257 | $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware |
@@ -1276,21 +1307,24 @@ discard block |
||
| 1276 | 1307 | } |
| 1277 | 1308 | $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); |
| 1278 | 1309 | |
| 1279 | - if ( $this->suppress_errors ) |
|
| 1280 | - return false; |
|
| 1310 | + if ( $this->suppress_errors ) { |
|
| 1311 | + return false; |
|
| 1312 | + } |
|
| 1281 | 1313 | |
| 1282 | 1314 | wp_load_translations_early(); |
| 1283 | 1315 | |
| 1284 | - if ( $caller = $this->get_caller() ) |
|
| 1285 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1286 | - else |
|
| 1287 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1316 | + if ( $caller = $this->get_caller() ) { |
|
| 1317 | + $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1318 | + } else { |
|
| 1319 | + $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1320 | + } |
|
| 1288 | 1321 | |
| 1289 | 1322 | error_log( $error_str ); |
| 1290 | 1323 | |
| 1291 | 1324 | // Are we showing errors? |
| 1292 | - if ( ! $this->show_errors ) |
|
| 1293 | - return false; |
|
| 1325 | + if ( ! $this->show_errors ) { |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1294 | 1328 | |
| 1295 | 1329 | // If there is an error then take note of it |
| 1296 | 1330 | if ( is_multisite() ) { |
@@ -1681,8 +1715,9 @@ discard block |
||
| 1681 | 1715 | |
| 1682 | 1716 | if ( $this->last_error ) { |
| 1683 | 1717 | // Clear insert_id on a subsequent failed insert. |
| 1684 | - if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) |
|
| 1685 | - $this->insert_id = 0; |
|
| 1718 | + if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { |
|
| 1719 | + $this->insert_id = 0; |
|
| 1720 | + } |
|
| 1686 | 1721 | |
| 1687 | 1722 | $this->print_error(); |
| 1688 | 1723 | return false; |
@@ -2157,8 +2192,9 @@ discard block |
||
| 2157 | 2192 | return null; |
| 2158 | 2193 | } |
| 2159 | 2194 | |
| 2160 | - if ( !isset( $this->last_result[$y] ) ) |
|
| 2161 | - return null; |
|
| 2195 | + if ( !isset( $this->last_result[$y] ) ) { |
|
| 2196 | + return null; |
|
| 2197 | + } |
|
| 2162 | 2198 | |
| 2163 | 2199 | if ( $output == OBJECT ) { |
| 2164 | 2200 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
@@ -2242,8 +2278,9 @@ discard block |
||
| 2242 | 2278 | foreach ( $this->last_result as $row ) { |
| 2243 | 2279 | $var_by_ref = get_object_vars( $row ); |
| 2244 | 2280 | $key = array_shift( $var_by_ref ); |
| 2245 | - if ( ! isset( $new_array[ $key ] ) ) |
|
| 2246 | - $new_array[ $key ] = $row; |
|
| 2281 | + if ( ! isset( $new_array[ $key ] ) ) { |
|
| 2282 | + $new_array[ $key ] = $row; |
|
| 2283 | + } |
|
| 2247 | 2284 | } |
| 2248 | 2285 | return $new_array; |
| 2249 | 2286 | } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { |
@@ -2912,8 +2949,9 @@ discard block |
||
| 2912 | 2949 | * @access protected |
| 2913 | 2950 | */ |
| 2914 | 2951 | protected function load_col_info() { |
| 2915 | - if ( $this->col_info ) |
|
| 2916 | - return; |
|
| 2952 | + if ( $this->col_info ) { |
|
| 2953 | + return; |
|
| 2954 | + } |
|
| 2917 | 2955 | |
| 2918 | 2956 | if ( $this->use_mysqli ) { |
| 2919 | 2957 | $num_fields = @mysqli_num_fields( $this->result ); |
@@ -2991,10 +3029,11 @@ discard block |
||
| 2991 | 3029 | */ |
| 2992 | 3030 | public function bail( $message, $error_code = '500' ) { |
| 2993 | 3031 | if ( !$this->show_errors ) { |
| 2994 | - if ( class_exists( 'WP_Error' ) ) |
|
| 2995 | - $this->error = new WP_Error($error_code, $message); |
|
| 2996 | - else |
|
| 2997 | - $this->error = $message; |
|
| 3032 | + if ( class_exists( 'WP_Error' ) ) { |
|
| 3033 | + $this->error = new WP_Error($error_code, $message); |
|
| 3034 | + } else { |
|
| 3035 | + $this->error = $message; |
|
| 3036 | + } |
|
| 2998 | 3037 | return false; |
| 2999 | 3038 | } |
| 3000 | 3039 | wp_die($message); |
@@ -3013,8 +3052,9 @@ discard block |
||
| 3013 | 3052 | public function check_database_version() { |
| 3014 | 3053 | global $wp_version, $required_mysql_version; |
| 3015 | 3054 | // Make sure the server has the required MySQL version |
| 3016 | - if ( version_compare($this->db_version(), $required_mysql_version, '<') ) |
|
| 3017 | - return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3055 | + if ( version_compare($this->db_version(), $required_mysql_version, '<') ) { |
|
| 3056 | + return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3057 | + } |
|
| 3018 | 3058 | } |
| 3019 | 3059 | |
| 3020 | 3060 | /** |
@@ -3043,10 +3083,12 @@ discard block |
||
| 3043 | 3083 | public function get_charset_collate() { |
| 3044 | 3084 | $charset_collate = ''; |
| 3045 | 3085 | |
| 3046 | - if ( ! empty( $this->charset ) ) |
|
| 3047 | - $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
|
| 3048 | - if ( ! empty( $this->collate ) ) |
|
| 3049 | - $charset_collate .= " COLLATE $this->collate"; |
|
| 3086 | + if ( ! empty( $this->charset ) ) { |
|
| 3087 | + $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
|
| 3088 | + } |
|
| 3089 | + if ( ! empty( $this->collate ) ) { |
|
| 3090 | + $charset_collate .= " COLLATE $this->collate"; |
|
| 3091 | + } |
|
| 3050 | 3092 | |
| 3051 | 3093 | return $charset_collate; |
| 3052 | 3094 | } |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * @access public |
| 496 | 496 | * |
| 497 | 497 | * @param string $name Property to check if set. |
| 498 | - * @return bool Whether the property is set. |
|
| 498 | + * @return boolean|null Whether the property is set. |
|
| 499 | 499 | */ |
| 500 | 500 | public function __isset( $name ) { |
| 501 | 501 | if ( in_array( $name, $this->compat_fields ) ) { |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @param string $string |
| 534 | 534 | * @param string $newlineEscape |
| 535 | - * @return string |
|
| 535 | + * @return string[] |
|
| 536 | 536 | */ |
| 537 | 537 | public function _splitOnWords($string, $newlineEscape = "\n") { |
| 538 | 538 | $string = str_replace("\0", '', $string); |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * WordPress Diff bastard child of old MediaWiki Diff Formatter. |
|
| 4 | - * |
|
| 5 | - * Basically all that remains is the table structure and some method names. |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Diff |
|
| 9 | - */ |
|
| 3 | + * WordPress Diff bastard child of old MediaWiki Diff Formatter. |
|
| 4 | + * |
|
| 5 | + * Basically all that remains is the table structure and some method names. |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Diff |
|
| 9 | + */ |
|
| 10 | 10 | |
| 11 | 11 | if ( !class_exists( 'Text_Diff' ) ) { |
| 12 | 12 | /** Text_Diff class */ |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @param String $processed_line The processed diffed line. |
| 171 | 171 | * @param String $line The unprocessed diffed line. |
| 172 | - * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
|
| 172 | + * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
|
| 173 | 173 | */ |
| 174 | 174 | $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' ); |
| 175 | 175 | } |
@@ -8,13 +8,13 @@ discard block |
||
| 8 | 8 | * @subpackage Diff |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( !class_exists( 'Text_Diff' ) ) { |
|
| 11 | +if ( ! class_exists('Text_Diff')) { |
|
| 12 | 12 | /** Text_Diff class */ |
| 13 | - require( dirname(__FILE__).'/Text/Diff.php' ); |
|
| 13 | + require(dirname(__FILE__).'/Text/Diff.php'); |
|
| 14 | 14 | /** Text_Diff_Renderer class */ |
| 15 | - require( dirname(__FILE__).'/Text/Diff/Renderer.php' ); |
|
| 15 | + require(dirname(__FILE__).'/Text/Diff/Renderer.php'); |
|
| 16 | 16 | /** Text_Diff_Renderer_inline class */ |
| 17 | - require( dirname(__FILE__).'/Text/Diff/Renderer/inline.php' ); |
|
| 17 | + require(dirname(__FILE__).'/Text/Diff/Renderer/inline.php'); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @access public |
| 32 | 32 | * @since 2.6.0 |
| 33 | 33 | */ |
| 34 | - public $_leading_context_lines = 10000; |
|
| 34 | + public $_leading_context_lines = 10000; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @see Text_Diff_Renderer::_trailing_context_lines |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | protected $_show_split_view = true; |
| 70 | 70 | |
| 71 | - protected $compat_fields = array( '_show_split_view', 'inline_diff_renderer', '_diff_threshold' ); |
|
| 71 | + protected $compat_fields = array('_show_split_view', 'inline_diff_renderer', '_diff_threshold'); |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Constructor - Call parent constructor with params array. |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @param array $params |
| 81 | 81 | */ |
| 82 | - public function __construct( $params = array() ) { |
|
| 83 | - parent::__construct( $params ); |
|
| 84 | - if ( isset( $params[ 'show_split_view' ] ) ) |
|
| 85 | - $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 82 | + public function __construct($params = array()) { |
|
| 83 | + parent::__construct($params); |
|
| 84 | + if (isset($params['show_split_view'])) |
|
| 85 | + $this->_show_split_view = $params['show_split_view']; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param string $header |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function _startBlock( $header ) { |
|
| 94 | + public function _startBlock($header) { |
|
| 95 | 95 | return ''; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param array $lines |
| 102 | 102 | * @param string $prefix |
| 103 | 103 | */ |
| 104 | - public function _lines( $lines, $prefix=' ' ) { |
|
| 104 | + public function _lines($lines, $prefix = ' ') { |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $line HTML-escape the value. |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function addedLine( $line ) { |
|
| 113 | + public function addedLine($line) { |
|
| 114 | 114 | return "<td class='diff-addedline'>{$line}</td>"; |
| 115 | 115 | |
| 116 | 116 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string $line HTML-escape the value. |
| 122 | 122 | * @return string |
| 123 | 123 | */ |
| 124 | - public function deletedLine( $line ) { |
|
| 124 | + public function deletedLine($line) { |
|
| 125 | 125 | return "<td class='diff-deletedline'>{$line}</td>"; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @param string $line HTML-escape the value. |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function contextLine( $line ) { |
|
| 134 | + public function contextLine($line) { |
|
| 135 | 135 | return "<td class='diff-context'>{$line}</td>"; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | * @param bool $encode |
| 153 | 153 | * @return string |
| 154 | 154 | */ |
| 155 | - public function _added( $lines, $encode = true ) { |
|
| 155 | + public function _added($lines, $encode = true) { |
|
| 156 | 156 | $r = ''; |
| 157 | 157 | foreach ($lines as $line) { |
| 158 | - if ( $encode ) { |
|
| 159 | - $processed_line = htmlspecialchars( $line ); |
|
| 158 | + if ($encode) { |
|
| 159 | + $processed_line = htmlspecialchars($line); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Contextually filter a diffed line. |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | * @param String $line The unprocessed diffed line. |
| 172 | 172 | * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
| 173 | 173 | */ |
| 174 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' ); |
|
| 174 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'added'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if ( $this->_show_split_view ) { |
|
| 178 | - $r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n"; |
|
| 177 | + if ($this->_show_split_view) { |
|
| 178 | + $r .= '<tr>'.$this->emptyLine().$this->emptyLine().$this->addedLine($line)."</tr>\n"; |
|
| 179 | 179 | } else { |
| 180 | - $r .= '<tr>' . $this->addedLine( $line ) . "</tr>\n"; |
|
| 180 | + $r .= '<tr>'.$this->addedLine($line)."</tr>\n"; |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | return $r; |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | * @param bool $encode |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - public function _deleted( $lines, $encode = true ) { |
|
| 194 | + public function _deleted($lines, $encode = true) { |
|
| 195 | 195 | $r = ''; |
| 196 | 196 | foreach ($lines as $line) { |
| 197 | - if ( $encode ) { |
|
| 198 | - $processed_line = htmlspecialchars( $line ); |
|
| 197 | + if ($encode) { |
|
| 198 | + $processed_line = htmlspecialchars($line); |
|
| 199 | 199 | |
| 200 | 200 | /** This filter is documented in wp-includes/wp-diff.php */ |
| 201 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' ); |
|
| 201 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'deleted'); |
|
| 202 | 202 | } |
| 203 | - if ( $this->_show_split_view ) { |
|
| 204 | - $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n"; |
|
| 203 | + if ($this->_show_split_view) { |
|
| 204 | + $r .= '<tr>'.$this->deletedLine($line).$this->emptyLine().$this->emptyLine()."</tr>\n"; |
|
| 205 | 205 | } else { |
| 206 | - $r .= '<tr>' . $this->deletedLine( $line ) . "</tr>\n"; |
|
| 206 | + $r .= '<tr>'.$this->deletedLine($line)."</tr>\n"; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | } |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | * @param bool $encode |
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | - public function _context( $lines, $encode = true ) { |
|
| 221 | + public function _context($lines, $encode = true) { |
|
| 222 | 222 | $r = ''; |
| 223 | 223 | foreach ($lines as $line) { |
| 224 | - if ( $encode ) { |
|
| 225 | - $processed_line = htmlspecialchars( $line ); |
|
| 224 | + if ($encode) { |
|
| 225 | + $processed_line = htmlspecialchars($line); |
|
| 226 | 226 | |
| 227 | 227 | /** This filter is documented in wp-includes/wp-diff.php */ |
| 228 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' ); |
|
| 228 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'unchanged'); |
|
| 229 | 229 | } |
| 230 | - if ( $this->_show_split_view ) { |
|
| 231 | - $r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line ) . "</tr>\n"; |
|
| 230 | + if ($this->_show_split_view) { |
|
| 231 | + $r .= '<tr>'.$this->contextLine($line).$this->emptyLine().$this->contextLine($line)."</tr>\n"; |
|
| 232 | 232 | } else { |
| 233 | - $r .= '<tr>' . $this->contextLine( $line ) . "</tr>\n"; |
|
| 233 | + $r .= '<tr>'.$this->contextLine($line)."</tr>\n"; |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | return $r; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @param array $final |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function _changed( $orig, $final ) { |
|
| 252 | + public function _changed($orig, $final) { |
|
| 253 | 253 | $r = ''; |
| 254 | 254 | |
| 255 | 255 | // Does the aforementioned additional processing |
@@ -259,66 +259,66 @@ discard block |
||
| 259 | 259 | // *_rows are column vectors for the orig column and the final column. |
| 260 | 260 | // row >= 0: an indix of the $orig or $final array |
| 261 | 261 | // row < 0: a blank row for that column |
| 262 | - list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final ); |
|
| 262 | + list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines($orig, $final); |
|
| 263 | 263 | |
| 264 | 264 | // These will hold the word changes as determined by an inline diff |
| 265 | 265 | $orig_diffs = array(); |
| 266 | 266 | $final_diffs = array(); |
| 267 | 267 | |
| 268 | 268 | // Compute word diffs for each matched pair using the inline diff |
| 269 | - foreach ( $orig_matches as $o => $f ) { |
|
| 270 | - if ( is_numeric($o) && is_numeric($f) ) { |
|
| 271 | - $text_diff = new Text_Diff( 'auto', array( array($orig[$o]), array($final[$f]) ) ); |
|
| 269 | + foreach ($orig_matches as $o => $f) { |
|
| 270 | + if (is_numeric($o) && is_numeric($f)) { |
|
| 271 | + $text_diff = new Text_Diff('auto', array(array($orig[$o]), array($final[$f]))); |
|
| 272 | 272 | $renderer = new $this->inline_diff_renderer; |
| 273 | - $diff = $renderer->render( $text_diff ); |
|
| 273 | + $diff = $renderer->render($text_diff); |
|
| 274 | 274 | |
| 275 | 275 | // If they're too different, don't include any <ins> or <dels> |
| 276 | - if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) { |
|
| 276 | + if (preg_match_all('!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches)) { |
|
| 277 | 277 | // length of all text between <ins> or <del> |
| 278 | - $stripped_matches = strlen(strip_tags( join(' ', $diff_matches[0]) )); |
|
| 278 | + $stripped_matches = strlen(strip_tags(join(' ', $diff_matches[0]))); |
|
| 279 | 279 | // since we count lengith of text between <ins> or <del> (instead of picking just one), |
| 280 | 280 | // we double the length of chars not in those tags. |
| 281 | - $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches; |
|
| 281 | + $stripped_diff = strlen(strip_tags($diff)) * 2 - $stripped_matches; |
|
| 282 | 282 | $diff_ratio = $stripped_matches / $stripped_diff; |
| 283 | - if ( $diff_ratio > $this->_diff_threshold ) |
|
| 283 | + if ($diff_ratio > $this->_diff_threshold) |
|
| 284 | 284 | continue; // Too different. Don't save diffs. |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Un-inline the diffs by removing del or ins |
| 288 | - $orig_diffs[$o] = preg_replace( '|<ins>.*?</ins>|', '', $diff ); |
|
| 289 | - $final_diffs[$f] = preg_replace( '|<del>.*?</del>|', '', $diff ); |
|
| 288 | + $orig_diffs[$o] = preg_replace('|<ins>.*?</ins>|', '', $diff); |
|
| 289 | + $final_diffs[$f] = preg_replace('|<del>.*?</del>|', '', $diff); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - foreach ( array_keys($orig_rows) as $row ) { |
|
| 293 | + foreach (array_keys($orig_rows) as $row) { |
|
| 294 | 294 | // Both columns have blanks. Ignore them. |
| 295 | - if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) |
|
| 295 | + if ($orig_rows[$row] < 0 && $final_rows[$row] < 0) |
|
| 296 | 296 | continue; |
| 297 | 297 | |
| 298 | 298 | // If we have a word based diff, use it. Otherwise, use the normal line. |
| 299 | - if ( isset( $orig_diffs[$orig_rows[$row]] ) ) |
|
| 299 | + if (isset($orig_diffs[$orig_rows[$row]])) |
|
| 300 | 300 | $orig_line = $orig_diffs[$orig_rows[$row]]; |
| 301 | - elseif ( isset( $orig[$orig_rows[$row]] ) ) |
|
| 301 | + elseif (isset($orig[$orig_rows[$row]])) |
|
| 302 | 302 | $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
| 303 | 303 | else |
| 304 | 304 | $orig_line = ''; |
| 305 | 305 | |
| 306 | - if ( isset( $final_diffs[$final_rows[$row]] ) ) |
|
| 306 | + if (isset($final_diffs[$final_rows[$row]])) |
|
| 307 | 307 | $final_line = $final_diffs[$final_rows[$row]]; |
| 308 | - elseif ( isset( $final[$final_rows[$row]] ) ) |
|
| 308 | + elseif (isset($final[$final_rows[$row]])) |
|
| 309 | 309 | $final_line = htmlspecialchars($final[$final_rows[$row]]); |
| 310 | 310 | else |
| 311 | 311 | $final_line = ''; |
| 312 | 312 | |
| 313 | - if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row. |
|
| 314 | - $r .= $this->_added( array($final_line), false ); |
|
| 315 | - } elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row. |
|
| 316 | - $r .= $this->_deleted( array($orig_line), false ); |
|
| 313 | + if ($orig_rows[$row] < 0) { // Orig is blank. This is really an added row. |
|
| 314 | + $r .= $this->_added(array($final_line), false); |
|
| 315 | + } elseif ($final_rows[$row] < 0) { // Final is blank. This is really a deleted row. |
|
| 316 | + $r .= $this->_deleted(array($orig_line), false); |
|
| 317 | 317 | } else { // A true changed row. |
| 318 | - if ( $this->_show_split_view ) { |
|
| 319 | - $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n"; |
|
| 318 | + if ($this->_show_split_view) { |
|
| 319 | + $r .= '<tr>'.$this->deletedLine($orig_line).$this->emptyLine().$this->addedLine($final_line)."</tr>\n"; |
|
| 320 | 320 | } else { |
| 321 | - $r .= '<tr>' . $this->deletedLine( $orig_line ) . "</tr><tr>" . $this->addedLine( $final_line ) . "</tr>\n"; |
|
| 321 | + $r .= '<tr>'.$this->deletedLine($orig_line)."</tr><tr>".$this->addedLine($final_line)."</tr>\n"; |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | } |
@@ -340,13 +340,13 @@ discard block |
||
| 340 | 340 | * @param array $final |
| 341 | 341 | * @return array |
| 342 | 342 | */ |
| 343 | - public function interleave_changed_lines( $orig, $final ) { |
|
| 343 | + public function interleave_changed_lines($orig, $final) { |
|
| 344 | 344 | |
| 345 | 345 | // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array. |
| 346 | 346 | $matches = array(); |
| 347 | - foreach ( array_keys($orig) as $o ) { |
|
| 348 | - foreach ( array_keys($final) as $f ) { |
|
| 349 | - $matches["$o,$f"] = $this->compute_string_distance( $orig[$o], $final[$f] ); |
|
| 347 | + foreach (array_keys($orig) as $o) { |
|
| 348 | + foreach (array_keys($final) as $f) { |
|
| 349 | + $matches["$o,$f"] = $this->compute_string_distance($orig[$o], $final[$f]); |
|
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | asort($matches); // Order by string distance. |
@@ -354,28 +354,28 @@ discard block |
||
| 354 | 354 | $orig_matches = array(); |
| 355 | 355 | $final_matches = array(); |
| 356 | 356 | |
| 357 | - foreach ( $matches as $keys => $difference ) { |
|
| 357 | + foreach ($matches as $keys => $difference) { |
|
| 358 | 358 | list($o, $f) = explode(',', $keys); |
| 359 | 359 | $o = (int) $o; |
| 360 | 360 | $f = (int) $f; |
| 361 | 361 | |
| 362 | 362 | // Already have better matches for these guys |
| 363 | - if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) |
|
| 363 | + if (isset($orig_matches[$o]) && isset($final_matches[$f])) |
|
| 364 | 364 | continue; |
| 365 | 365 | |
| 366 | 366 | // First match for these guys. Must be best match |
| 367 | - if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) { |
|
| 367 | + if ( ! isset($orig_matches[$o]) && ! isset($final_matches[$f])) { |
|
| 368 | 368 | $orig_matches[$o] = $f; |
| 369 | 369 | $final_matches[$f] = $o; |
| 370 | 370 | continue; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // Best match of this final is already taken? Must mean this final is a new row. |
| 374 | - if ( isset($orig_matches[$o]) ) |
|
| 374 | + if (isset($orig_matches[$o])) |
|
| 375 | 375 | $final_matches[$f] = 'x'; |
| 376 | 376 | |
| 377 | 377 | // Best match of this orig is already taken? Must mean this orig is a deleted row. |
| 378 | - elseif ( isset($final_matches[$f]) ) |
|
| 378 | + elseif (isset($final_matches[$f])) |
|
| 379 | 379 | $orig_matches[$o] = 'x'; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -389,31 +389,31 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | // Interleaves rows with blanks to keep matches aligned. |
| 391 | 391 | // We may end up with some extraneous blank rows, but we'll just ignore them later. |
| 392 | - foreach ( $orig_rows_copy as $orig_row ) { |
|
| 392 | + foreach ($orig_rows_copy as $orig_row) { |
|
| 393 | 393 | $final_pos = array_search($orig_matches[$orig_row], $final_rows, true); |
| 394 | 394 | $orig_pos = (int) array_search($orig_row, $orig_rows, true); |
| 395 | 395 | |
| 396 | - if ( false === $final_pos ) { // This orig is paired with a blank final. |
|
| 397 | - array_splice( $final_rows, $orig_pos, 0, -1 ); |
|
| 398 | - } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. |
|
| 396 | + if (false === $final_pos) { // This orig is paired with a blank final. |
|
| 397 | + array_splice($final_rows, $orig_pos, 0, -1); |
|
| 398 | + } elseif ($final_pos < $orig_pos) { // This orig's match is up a ways. Pad final with blank rows. |
|
| 399 | 399 | $diff_pos = $final_pos - $orig_pos; |
| 400 | - while ( $diff_pos < 0 ) |
|
| 401 | - array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 402 | - } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. |
|
| 400 | + while ($diff_pos < 0) |
|
| 401 | + array_splice($final_rows, $orig_pos, 0, $diff_pos++); |
|
| 402 | + } elseif ($final_pos > $orig_pos) { // This orig's match is down a ways. Pad orig with blank rows. |
|
| 403 | 403 | $diff_pos = $orig_pos - $final_pos; |
| 404 | - while ( $diff_pos < 0 ) |
|
| 405 | - array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 404 | + while ($diff_pos < 0) |
|
| 405 | + array_splice($orig_rows, $orig_pos, 0, $diff_pos++); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | // Pad the ends with blank rows if the columns aren't the same length |
| 410 | 410 | $diff_count = count($orig_rows) - count($final_rows); |
| 411 | - if ( $diff_count < 0 ) { |
|
| 412 | - while ( $diff_count < 0 ) |
|
| 411 | + if ($diff_count < 0) { |
|
| 412 | + while ($diff_count < 0) |
|
| 413 | 413 | array_push($orig_rows, $diff_count++); |
| 414 | - } elseif ( $diff_count > 0 ) { |
|
| 414 | + } elseif ($diff_count > 0) { |
|
| 415 | 415 | $diff_count = -1 * $diff_count; |
| 416 | - while ( $diff_count < 0 ) |
|
| 416 | + while ($diff_count < 0) |
|
| 417 | 417 | array_push($final_rows, $diff_count++); |
| 418 | 418 | } |
| 419 | 419 | |
@@ -429,16 +429,16 @@ discard block |
||
| 429 | 429 | * @param string $string2 |
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | - public function compute_string_distance( $string1, $string2 ) { |
|
| 432 | + public function compute_string_distance($string1, $string2) { |
|
| 433 | 433 | // Vectors containing character frequency for all chars in each string |
| 434 | 434 | $chars1 = count_chars($string1); |
| 435 | 435 | $chars2 = count_chars($string2); |
| 436 | 436 | |
| 437 | 437 | // L1-norm of difference vector. |
| 438 | - $difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); |
|
| 438 | + $difference = array_sum(array_map(array($this, 'difference'), $chars1, $chars2)); |
|
| 439 | 439 | |
| 440 | 440 | // $string1 has zero length? Odd. Give huge penalty by not dividing. |
| 441 | - if ( !$string1 ) |
|
| 441 | + if ( ! $string1) |
|
| 442 | 442 | return $difference; |
| 443 | 443 | |
| 444 | 444 | // Return distance per character (of string1). |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * @param int $b |
| 454 | 454 | * @return int |
| 455 | 455 | */ |
| 456 | - public function difference( $a, $b ) { |
|
| 457 | - return abs( $a - $b ); |
|
| 456 | + public function difference($a, $b) { |
|
| 457 | + return abs($a - $b); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -466,8 +466,8 @@ discard block |
||
| 466 | 466 | * @param string $name Property to get. |
| 467 | 467 | * @return mixed Property. |
| 468 | 468 | */ |
| 469 | - public function __get( $name ) { |
|
| 470 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 469 | + public function __get($name) { |
|
| 470 | + if (in_array($name, $this->compat_fields)) { |
|
| 471 | 471 | return $this->$name; |
| 472 | 472 | } |
| 473 | 473 | } |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param mixed $value Property value. |
| 483 | 483 | * @return mixed Newly-set property. |
| 484 | 484 | */ |
| 485 | - public function __set( $name, $value ) { |
|
| 486 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 485 | + public function __set($name, $value) { |
|
| 486 | + if (in_array($name, $this->compat_fields)) { |
|
| 487 | 487 | return $this->$name = $value; |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -497,9 +497,9 @@ discard block |
||
| 497 | 497 | * @param string $name Property to check if set. |
| 498 | 498 | * @return bool Whether the property is set. |
| 499 | 499 | */ |
| 500 | - public function __isset( $name ) { |
|
| 501 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 502 | - return isset( $this->$name ); |
|
| 500 | + public function __isset($name) { |
|
| 501 | + if (in_array($name, $this->compat_fields)) { |
|
| 502 | + return isset($this->$name); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
@@ -511,9 +511,9 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @param string $name Property to unset. |
| 513 | 513 | */ |
| 514 | - public function __unset( $name ) { |
|
| 515 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 516 | - unset( $this->$name ); |
|
| 514 | + public function __unset($name) { |
|
| 515 | + if (in_array($name, $this->compat_fields)) { |
|
| 516 | + unset($this->$name); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | } |
@@ -536,8 +536,8 @@ discard block |
||
| 536 | 536 | */ |
| 537 | 537 | public function _splitOnWords($string, $newlineEscape = "\n") { |
| 538 | 538 | $string = str_replace("\0", '', $string); |
| 539 | - $words = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
| 540 | - $words = str_replace( "\n", $newlineEscape, $words ); |
|
| 539 | + $words = preg_split('/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 540 | + $words = str_replace("\n", $newlineEscape, $words); |
|
| 541 | 541 | return $words; |
| 542 | 542 | } |
| 543 | 543 | |
@@ -81,8 +81,9 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function __construct( $params = array() ) { |
| 83 | 83 | parent::__construct( $params ); |
| 84 | - if ( isset( $params[ 'show_split_view' ] ) ) |
|
| 85 | - $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 84 | + if ( isset( $params[ 'show_split_view' ] ) ) { |
|
| 85 | + $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 86 | + } |
|
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | /** |
@@ -280,8 +281,10 @@ discard block |
||
| 280 | 281 | // we double the length of chars not in those tags. |
| 281 | 282 | $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches; |
| 282 | 283 | $diff_ratio = $stripped_matches / $stripped_diff; |
| 283 | - if ( $diff_ratio > $this->_diff_threshold ) |
|
| 284 | - continue; // Too different. Don't save diffs. |
|
| 284 | + if ( $diff_ratio > $this->_diff_threshold ) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 287 | + // Too different. Don't save diffs. |
|
| 285 | 288 | } |
| 286 | 289 | |
| 287 | 290 | // Un-inline the diffs by removing del or ins |
@@ -292,23 +295,26 @@ discard block |
||
| 292 | 295 | |
| 293 | 296 | foreach ( array_keys($orig_rows) as $row ) { |
| 294 | 297 | // Both columns have blanks. Ignore them. |
| 295 | - if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) |
|
| 296 | - continue; |
|
| 298 | + if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) { |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 297 | 301 | |
| 298 | 302 | // If we have a word based diff, use it. Otherwise, use the normal line. |
| 299 | - if ( isset( $orig_diffs[$orig_rows[$row]] ) ) |
|
| 300 | - $orig_line = $orig_diffs[$orig_rows[$row]]; |
|
| 301 | - elseif ( isset( $orig[$orig_rows[$row]] ) ) |
|
| 302 | - $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
|
| 303 | - else |
|
| 304 | - $orig_line = ''; |
|
| 305 | - |
|
| 306 | - if ( isset( $final_diffs[$final_rows[$row]] ) ) |
|
| 307 | - $final_line = $final_diffs[$final_rows[$row]]; |
|
| 308 | - elseif ( isset( $final[$final_rows[$row]] ) ) |
|
| 309 | - $final_line = htmlspecialchars($final[$final_rows[$row]]); |
|
| 310 | - else |
|
| 311 | - $final_line = ''; |
|
| 303 | + if ( isset( $orig_diffs[$orig_rows[$row]] ) ) { |
|
| 304 | + $orig_line = $orig_diffs[$orig_rows[$row]]; |
|
| 305 | + } elseif ( isset( $orig[$orig_rows[$row]] ) ) { |
|
| 306 | + $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
|
| 307 | + } else { |
|
| 308 | + $orig_line = ''; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + if ( isset( $final_diffs[$final_rows[$row]] ) ) { |
|
| 312 | + $final_line = $final_diffs[$final_rows[$row]]; |
|
| 313 | + } elseif ( isset( $final[$final_rows[$row]] ) ) { |
|
| 314 | + $final_line = htmlspecialchars($final[$final_rows[$row]]); |
|
| 315 | + } else { |
|
| 316 | + $final_line = ''; |
|
| 317 | + } |
|
| 312 | 318 | |
| 313 | 319 | if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row. |
| 314 | 320 | $r .= $this->_added( array($final_line), false ); |
@@ -360,8 +366,9 @@ discard block |
||
| 360 | 366 | $f = (int) $f; |
| 361 | 367 | |
| 362 | 368 | // Already have better matches for these guys |
| 363 | - if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) |
|
| 364 | - continue; |
|
| 369 | + if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) { |
|
| 370 | + continue; |
|
| 371 | + } |
|
| 365 | 372 | |
| 366 | 373 | // First match for these guys. Must be best match |
| 367 | 374 | if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) { |
@@ -371,12 +378,14 @@ discard block |
||
| 371 | 378 | } |
| 372 | 379 | |
| 373 | 380 | // Best match of this final is already taken? Must mean this final is a new row. |
| 374 | - if ( isset($orig_matches[$o]) ) |
|
| 375 | - $final_matches[$f] = 'x'; |
|
| 381 | + if ( isset($orig_matches[$o]) ) { |
|
| 382 | + $final_matches[$f] = 'x'; |
|
| 383 | + } |
|
| 376 | 384 | |
| 377 | 385 | // Best match of this orig is already taken? Must mean this orig is a deleted row. |
| 378 | - elseif ( isset($final_matches[$f]) ) |
|
| 379 | - $orig_matches[$o] = 'x'; |
|
| 386 | + elseif ( isset($final_matches[$f]) ) { |
|
| 387 | + $orig_matches[$o] = 'x'; |
|
| 388 | + } |
|
| 380 | 389 | } |
| 381 | 390 | |
| 382 | 391 | // We read the text in this order |
@@ -397,24 +406,28 @@ discard block |
||
| 397 | 406 | array_splice( $final_rows, $orig_pos, 0, -1 ); |
| 398 | 407 | } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. |
| 399 | 408 | $diff_pos = $final_pos - $orig_pos; |
| 400 | - while ( $diff_pos < 0 ) |
|
| 401 | - array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 409 | + while ( $diff_pos < 0 ) { |
|
| 410 | + array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 411 | + } |
|
| 402 | 412 | } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. |
| 403 | 413 | $diff_pos = $orig_pos - $final_pos; |
| 404 | - while ( $diff_pos < 0 ) |
|
| 405 | - array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 414 | + while ( $diff_pos < 0 ) { |
|
| 415 | + array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 416 | + } |
|
| 406 | 417 | } |
| 407 | 418 | } |
| 408 | 419 | |
| 409 | 420 | // Pad the ends with blank rows if the columns aren't the same length |
| 410 | 421 | $diff_count = count($orig_rows) - count($final_rows); |
| 411 | 422 | if ( $diff_count < 0 ) { |
| 412 | - while ( $diff_count < 0 ) |
|
| 413 | - array_push($orig_rows, $diff_count++); |
|
| 423 | + while ( $diff_count < 0 ) { |
|
| 424 | + array_push($orig_rows, $diff_count++); |
|
| 425 | + } |
|
| 414 | 426 | } elseif ( $diff_count > 0 ) { |
| 415 | 427 | $diff_count = -1 * $diff_count; |
| 416 | - while ( $diff_count < 0 ) |
|
| 417 | - array_push($final_rows, $diff_count++); |
|
| 428 | + while ( $diff_count < 0 ) { |
|
| 429 | + array_push($final_rows, $diff_count++); |
|
| 430 | + } |
|
| 418 | 431 | } |
| 419 | 432 | |
| 420 | 433 | return array($orig_matches, $final_matches, $orig_rows, $final_rows); |
@@ -438,8 +451,9 @@ discard block |
||
| 438 | 451 | $difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); |
| 439 | 452 | |
| 440 | 453 | // $string1 has zero length? Odd. Give huge penalty by not dividing. |
| 441 | - if ( !$string1 ) |
|
| 442 | - return $difference; |
|
| 454 | + if ( !$string1 ) { |
|
| 455 | + return $difference; |
|
| 456 | + } |
|
| 443 | 457 | |
| 444 | 458 | // Return distance per character (of string1). |
| 445 | 459 | return $difference / strlen($string1); |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @since 0.71 |
| 22 | 22 | * |
| 23 | - * @param mixed $error Whether there was an error. |
|
| 23 | + * @param integer $error Whether there was an error. |
|
| 24 | 24 | * Default '0'. Accepts '0' or '1', true or false. |
| 25 | 25 | * @param string $error_message Error message if an error occurred. |
| 26 | 26 | */ |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Handle Trackbacks and Pingbacks Sent to WordPress |
|
| 4 | - * |
|
| 5 | - * @since 0.71 |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Trackbacks |
|
| 9 | - */ |
|
| 3 | + * Handle Trackbacks and Pingbacks Sent to WordPress |
|
| 4 | + * |
|
| 5 | + * @since 0.71 |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Trackbacks |
|
| 9 | + */ |
|
| 10 | 10 | |
| 11 | 11 | if (empty($wp)) { |
| 12 | 12 | require_once( dirname( __FILE__ ) . '/wp-load.php' ); |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | if (empty($wp)) { |
| 12 | - require_once( dirname( __FILE__ ) . '/wp-load.php' ); |
|
| 13 | - wp( array( 'tb' => '1' ) ); |
|
| 12 | + require_once(dirname(__FILE__).'/wp-load.php'); |
|
| 13 | + wp(array('tb' => '1')); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param string $error_message Error message if an error occurred. |
| 26 | 26 | */ |
| 27 | 27 | function trackback_response($error = 0, $error_message = '') { |
| 28 | - header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
|
| 28 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
| 29 | 29 | if ($error) { |
| 30 | 30 | echo '<?xml version="1.0" encoding="utf-8"?'.">\n"; |
| 31 | 31 | echo "<response>\n"; |
@@ -44,30 +44,30 @@ discard block |
||
| 44 | 44 | // Trackback is done by a POST. |
| 45 | 45 | $request_array = 'HTTP_POST_VARS'; |
| 46 | 46 | |
| 47 | -if ( !isset($_GET['tb_id']) || !$_GET['tb_id'] ) { |
|
| 47 | +if ( ! isset($_GET['tb_id']) || ! $_GET['tb_id']) { |
|
| 48 | 48 | $tb_id = explode('/', $_SERVER['REQUEST_URI']); |
| 49 | - $tb_id = intval( $tb_id[ count($tb_id) - 1 ] ); |
|
| 49 | + $tb_id = intval($tb_id[count($tb_id) - 1]); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -$tb_url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
| 52 | +$tb_url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
| 53 | 53 | $charset = isset($_POST['charset']) ? $_POST['charset'] : ''; |
| 54 | 54 | |
| 55 | 55 | // These three are stripslashed here so they can be properly escaped after mb_convert_encoding(). |
| 56 | -$title = isset($_POST['title']) ? wp_unslash($_POST['title']) : ''; |
|
| 57 | -$excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
|
| 58 | -$blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
|
| 56 | +$title = isset($_POST['title']) ? wp_unslash($_POST['title']) : ''; |
|
| 57 | +$excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
|
| 58 | +$blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
|
| 59 | 59 | |
| 60 | 60 | if ($charset) |
| 61 | - $charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) ); |
|
| 61 | + $charset = str_replace(array(',', ' '), '', strtoupper(trim($charset))); |
|
| 62 | 62 | else |
| 63 | 63 | $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS'; |
| 64 | 64 | |
| 65 | 65 | // No valid uses for UTF-7. |
| 66 | -if ( false !== strpos($charset, 'UTF-7') ) |
|
| 66 | +if (false !== strpos($charset, 'UTF-7')) |
|
| 67 | 67 | die; |
| 68 | 68 | |
| 69 | 69 | // For international trackbacks. |
| 70 | -if ( function_exists('mb_convert_encoding') ) { |
|
| 70 | +if (function_exists('mb_convert_encoding')) { |
|
| 71 | 71 | $title = mb_convert_encoding($title, get_option('blog_charset'), $charset); |
| 72 | 72 | $excerpt = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset); |
| 73 | 73 | $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset); |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | $excerpt = wp_slash($excerpt); |
| 79 | 79 | $blog_name = wp_slash($blog_name); |
| 80 | 80 | |
| 81 | -if ( is_single() || is_page() ) |
|
| 81 | +if (is_single() || is_page()) |
|
| 82 | 82 | $tb_id = $posts[0]->ID; |
| 83 | 83 | |
| 84 | -if ( !isset($tb_id) || !intval( $tb_id ) ) |
|
| 84 | +if ( ! isset($tb_id) || ! intval($tb_id)) |
|
| 85 | 85 | trackback_response(1, 'I really need an ID for this to work.'); |
| 86 | 86 | |
| 87 | 87 | if (empty($title) && empty($tb_url) && empty($blog_name)) { |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | exit; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | -if ( !empty($tb_url) && !empty($title) ) { |
|
| 94 | - header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
|
| 93 | +if ( ! empty($tb_url) && ! empty($title)) { |
|
| 94 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
| 95 | 95 | |
| 96 | - if ( !pings_open($tb_id) ) |
|
| 96 | + if ( ! pings_open($tb_id)) |
|
| 97 | 97 | trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
| 98 | 98 | |
| 99 | - $title = wp_html_excerpt( $title, 250, '…' ); |
|
| 100 | - $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
|
| 99 | + $title = wp_html_excerpt($title, 250, '…'); |
|
| 100 | + $excerpt = wp_html_excerpt($excerpt, 252, '…'); |
|
| 101 | 101 | |
| 102 | 102 | $comment_post_ID = (int) $tb_id; |
| 103 | 103 | $comment_author = $blog_name; |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | $comment_content = "<strong>$title</strong>\n\n$excerpt"; |
| 107 | 107 | $comment_type = 'trackback'; |
| 108 | 108 | |
| 109 | - $dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) ); |
|
| 110 | - if ( $dupe ) |
|
| 109 | + $dupe = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url)); |
|
| 110 | + if ($dupe) |
|
| 111 | 111 | trackback_response(1, 'We already have a ping from that URL for this post.'); |
| 112 | 112 | |
| 113 | 113 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
@@ -122,6 +122,6 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $trackback_id Trackback ID. |
| 124 | 124 | */ |
| 125 | - do_action( 'trackback_post', $trackback_id ); |
|
| 126 | - trackback_response( 0 ); |
|
| 125 | + do_action('trackback_post', $trackback_id); |
|
| 126 | + trackback_response(0); |
|
| 127 | 127 | } |
@@ -57,14 +57,16 @@ discard block |
||
| 57 | 57 | $excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
| 58 | 58 | $blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
| 59 | 59 | |
| 60 | -if ($charset) |
|
| 60 | +if ($charset) { |
|
| 61 | 61 | $charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) ); |
| 62 | -else |
|
| 62 | +} else { |
|
| 63 | 63 | $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS'; |
| 64 | +} |
|
| 64 | 65 | |
| 65 | 66 | // No valid uses for UTF-7. |
| 66 | -if ( false !== strpos($charset, 'UTF-7') ) |
|
| 67 | +if ( false !== strpos($charset, 'UTF-7') ) { |
|
| 67 | 68 | die; |
| 69 | +} |
|
| 68 | 70 | |
| 69 | 71 | // For international trackbacks. |
| 70 | 72 | if ( function_exists('mb_convert_encoding') ) { |
@@ -78,11 +80,13 @@ discard block |
||
| 78 | 80 | $excerpt = wp_slash($excerpt); |
| 79 | 81 | $blog_name = wp_slash($blog_name); |
| 80 | 82 | |
| 81 | -if ( is_single() || is_page() ) |
|
| 83 | +if ( is_single() || is_page() ) { |
|
| 82 | 84 | $tb_id = $posts[0]->ID; |
| 85 | +} |
|
| 83 | 86 | |
| 84 | -if ( !isset($tb_id) || !intval( $tb_id ) ) |
|
| 87 | +if ( !isset($tb_id) || !intval( $tb_id ) ) { |
|
| 85 | 88 | trackback_response(1, 'I really need an ID for this to work.'); |
| 89 | +} |
|
| 86 | 90 | |
| 87 | 91 | if (empty($title) && empty($tb_url) && empty($blog_name)) { |
| 88 | 92 | // If it doesn't look like a trackback at all. |
@@ -93,8 +97,9 @@ discard block |
||
| 93 | 97 | if ( !empty($tb_url) && !empty($title) ) { |
| 94 | 98 | header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
| 95 | 99 | |
| 96 | - if ( !pings_open($tb_id) ) |
|
| 97 | - trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
|
| 100 | + if ( !pings_open($tb_id) ) { |
|
| 101 | + trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
|
| 102 | + } |
|
| 98 | 103 | |
| 99 | 104 | $title = wp_html_excerpt( $title, 250, '…' ); |
| 100 | 105 | $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
@@ -107,8 +112,9 @@ discard block |
||
| 107 | 112 | $comment_type = 'trackback'; |
| 108 | 113 | |
| 109 | 114 | $dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) ); |
| 110 | - if ( $dupe ) |
|
| 111 | - trackback_response(1, 'We already have a ping from that URL for this post.'); |
|
| 115 | + if ( $dupe ) { |
|
| 116 | + trackback_response(1, 'We already have a ping from that URL for this post.'); |
|
| 117 | + } |
|
| 112 | 118 | |
| 113 | 119 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
| 114 | 120 | |
@@ -40,11 +40,17 @@ discard block |
||
| 40 | 40 | return $translations; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + /** |
|
| 44 | + * @param string $prefix |
|
| 45 | + */ |
|
| 43 | 46 | function extract_from_file( $file_name, $prefix ) { |
| 44 | 47 | $code = file_get_contents( $file_name ); |
| 45 | 48 | return $this->extract_from_code( $code, $prefix . $file_name ); |
| 46 | 49 | } |
| 47 | 50 | |
| 51 | + /** |
|
| 52 | + * @param string $path |
|
| 53 | + */ |
|
| 48 | 54 | function does_file_name_match( $path, $excludes, $includes ) { |
| 49 | 55 | if ( $includes ) { |
| 50 | 56 | $matched_any_include = false; |
@@ -128,6 +134,10 @@ discard block |
||
| 128 | 134 | return $entry; |
| 129 | 135 | } |
| 130 | 136 | |
| 137 | + /** |
|
| 138 | + * @param string $code |
|
| 139 | + * @param string $file_name |
|
| 140 | + */ |
|
| 131 | 141 | function extract_from_code( $code, $file_name ) { |
| 132 | 142 | $translations = new Translations; |
| 133 | 143 | $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
@@ -75,35 +75,35 @@ |
||
| 75 | 75 | for( $i = 0; $i < count( $rule ); ++$i ) { |
| 76 | 76 | if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
| 77 | 77 | switch( $rule[$i] ) { |
| 78 | - case 'string': |
|
| 79 | - if ( $complete ) { |
|
| 80 | - $multiple[] = $entry; |
|
| 81 | - $entry = new Translation_Entry; |
|
| 82 | - $complete = false; |
|
| 83 | - } |
|
| 84 | - $entry->singular = $call['args'][$i]; |
|
| 85 | - $complete = true; |
|
| 86 | - break; |
|
| 87 | - case 'singular': |
|
| 88 | - if ( $complete ) { |
|
| 89 | - $multiple[] = $entry; |
|
| 90 | - $entry = new Translation_Entry; |
|
| 91 | - $complete = false; |
|
| 92 | - } |
|
| 93 | - $entry->singular = $call['args'][$i]; |
|
| 94 | - $entry->is_plural = true; |
|
| 95 | - break; |
|
| 96 | - case 'plural': |
|
| 97 | - $entry->plural = $call['args'][$i]; |
|
| 98 | - $entry->is_plural = true; |
|
| 99 | - $complete = true; |
|
| 100 | - break; |
|
| 101 | - case 'context': |
|
| 102 | - $entry->context = $call['args'][$i]; |
|
| 103 | - foreach( $multiple as &$single_entry ) { |
|
| 104 | - $single_entry->context = $entry->context; |
|
| 105 | - } |
|
| 106 | - break; |
|
| 78 | + case 'string': |
|
| 79 | + if ( $complete ) { |
|
| 80 | + $multiple[] = $entry; |
|
| 81 | + $entry = new Translation_Entry; |
|
| 82 | + $complete = false; |
|
| 83 | + } |
|
| 84 | + $entry->singular = $call['args'][$i]; |
|
| 85 | + $complete = true; |
|
| 86 | + break; |
|
| 87 | + case 'singular': |
|
| 88 | + if ( $complete ) { |
|
| 89 | + $multiple[] = $entry; |
|
| 90 | + $entry = new Translation_Entry; |
|
| 91 | + $complete = false; |
|
| 92 | + } |
|
| 93 | + $entry->singular = $call['args'][$i]; |
|
| 94 | + $entry->is_plural = true; |
|
| 95 | + break; |
|
| 96 | + case 'plural': |
|
| 97 | + $entry->plural = $call['args'][$i]; |
|
| 98 | + $entry->is_plural = true; |
|
| 99 | + $complete = true; |
|
| 100 | + break; |
|
| 101 | + case 'context': |
|
| 102 | + $entry->context = $call['args'][$i]; |
|
| 103 | + foreach( $multiple as &$single_entry ) { |
|
| 104 | + $single_entry->context = $entry->context; |
|
| 105 | + } |
|
| 106 | + break; |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | if ( isset( $call['line'] ) && $call['line'] ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
|
| 2 | +$pomo = dirname(dirname(dirname(__FILE__))).'/src/wp-includes/pomo'; |
|
| 3 | 3 | require_once "$pomo/entry.php"; |
| 4 | 4 | require_once "$pomo/translations.php"; |
| 5 | 5 | |
@@ -10,55 +10,55 @@ discard block |
||
| 10 | 10 | class StringExtractor { |
| 11 | 11 | |
| 12 | 12 | var $rules = array( |
| 13 | - '__' => array( 'string' ), |
|
| 14 | - '_e' => array( 'string' ), |
|
| 15 | - '_n' => array( 'singular', 'plural' ), |
|
| 13 | + '__' => array('string'), |
|
| 14 | + '_e' => array('string'), |
|
| 15 | + '_n' => array('singular', 'plural'), |
|
| 16 | 16 | ); |
| 17 | 17 | var $comment_prefix = 'translators:'; |
| 18 | 18 | |
| 19 | - function __construct( $rules = array() ) { |
|
| 19 | + function __construct($rules = array()) { |
|
| 20 | 20 | $this->rules = $rules; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - function extract_from_directory( $dir, $excludes = array(), $includes = array(), $prefix = '' ) { |
|
| 23 | + function extract_from_directory($dir, $excludes = array(), $includes = array(), $prefix = '') { |
|
| 24 | 24 | $old_cwd = getcwd(); |
| 25 | - chdir( $dir ); |
|
| 25 | + chdir($dir); |
|
| 26 | 26 | $translations = new Translations; |
| 27 | - $file_names = (array) scandir( '.' ); |
|
| 28 | - foreach ( $file_names as $file_name ) { |
|
| 29 | - if ( '.' == $file_name || '..' == $file_name ) continue; |
|
| 30 | - if ( preg_match( '/\.php$/', $file_name ) && $this->does_file_name_match( $prefix . $file_name, $excludes, $includes ) ) { |
|
| 31 | - $extracted = $this->extract_from_file( $file_name, $prefix ); |
|
| 32 | - $translations->merge_originals_with( $extracted ); |
|
| 27 | + $file_names = (array) scandir('.'); |
|
| 28 | + foreach ($file_names as $file_name) { |
|
| 29 | + if ('.' == $file_name || '..' == $file_name) continue; |
|
| 30 | + if (preg_match('/\.php$/', $file_name) && $this->does_file_name_match($prefix.$file_name, $excludes, $includes)) { |
|
| 31 | + $extracted = $this->extract_from_file($file_name, $prefix); |
|
| 32 | + $translations->merge_originals_with($extracted); |
|
| 33 | 33 | } |
| 34 | - if ( is_dir( $file_name ) ) { |
|
| 35 | - $extracted = $this->extract_from_directory( $file_name, $excludes, $includes, $prefix . $file_name . '/' ); |
|
| 36 | - $translations->merge_originals_with( $extracted ); |
|
| 34 | + if (is_dir($file_name)) { |
|
| 35 | + $extracted = $this->extract_from_directory($file_name, $excludes, $includes, $prefix.$file_name.'/'); |
|
| 36 | + $translations->merge_originals_with($extracted); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | - chdir( $old_cwd ); |
|
| 39 | + chdir($old_cwd); |
|
| 40 | 40 | return $translations; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - function extract_from_file( $file_name, $prefix ) { |
|
| 44 | - $code = file_get_contents( $file_name ); |
|
| 45 | - return $this->extract_from_code( $code, $prefix . $file_name ); |
|
| 43 | + function extract_from_file($file_name, $prefix) { |
|
| 44 | + $code = file_get_contents($file_name); |
|
| 45 | + return $this->extract_from_code($code, $prefix.$file_name); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - function does_file_name_match( $path, $excludes, $includes ) { |
|
| 49 | - if ( $includes ) { |
|
| 48 | + function does_file_name_match($path, $excludes, $includes) { |
|
| 49 | + if ($includes) { |
|
| 50 | 50 | $matched_any_include = false; |
| 51 | - foreach( $includes as $include ) { |
|
| 52 | - if ( preg_match( '|^'.$include.'$|', $path ) ) { |
|
| 51 | + foreach ($includes as $include) { |
|
| 52 | + if (preg_match('|^'.$include.'$|', $path)) { |
|
| 53 | 53 | $matched_any_include = true; |
| 54 | 54 | break; |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | - if ( !$matched_any_include ) return false; |
|
| 57 | + if ( ! $matched_any_include) return false; |
|
| 58 | 58 | } |
| 59 | - if ( $excludes ) { |
|
| 60 | - foreach( $excludes as $exclude ) { |
|
| 61 | - if ( preg_match( '|^'.$exclude.'$|', $path ) ) { |
|
| 59 | + if ($excludes) { |
|
| 60 | + foreach ($excludes as $exclude) { |
|
| 61 | + if (preg_match('|^'.$exclude.'$|', $path)) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | return true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - function entry_from_call( $call, $file_name ) { |
|
| 70 | - $rule = isset( $this->rules[$call['name']] )? $this->rules[$call['name']] : null; |
|
| 71 | - if ( !$rule ) return null; |
|
| 69 | + function entry_from_call($call, $file_name) { |
|
| 70 | + $rule = isset($this->rules[$call['name']]) ? $this->rules[$call['name']] : null; |
|
| 71 | + if ( ! $rule) return null; |
|
| 72 | 72 | $entry = new Translation_Entry; |
| 73 | 73 | $multiple = array(); |
| 74 | 74 | $complete = false; |
| 75 | - for( $i = 0; $i < count( $rule ); ++$i ) { |
|
| 76 | - if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
|
| 77 | - switch( $rule[$i] ) { |
|
| 75 | + for ($i = 0; $i < count($rule); ++$i) { |
|
| 76 | + if ($rule[$i] && ( ! isset($call['args'][$i]) || ! is_string($call['args'][$i]) || '' == $call['args'][$i])) return false; |
|
| 77 | + switch ($rule[$i]) { |
|
| 78 | 78 | case 'string': |
| 79 | - if ( $complete ) { |
|
| 79 | + if ($complete) { |
|
| 80 | 80 | $multiple[] = $entry; |
| 81 | 81 | $entry = new Translation_Entry; |
| 82 | 82 | $complete = false; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $complete = true; |
| 86 | 86 | break; |
| 87 | 87 | case 'singular': |
| 88 | - if ( $complete ) { |
|
| 88 | + if ($complete) { |
|
| 89 | 89 | $multiple[] = $entry; |
| 90 | 90 | $entry = new Translation_Entry; |
| 91 | 91 | $complete = false; |
@@ -100,27 +100,27 @@ discard block |
||
| 100 | 100 | break; |
| 101 | 101 | case 'context': |
| 102 | 102 | $entry->context = $call['args'][$i]; |
| 103 | - foreach( $multiple as &$single_entry ) { |
|
| 103 | + foreach ($multiple as &$single_entry) { |
|
| 104 | 104 | $single_entry->context = $entry->context; |
| 105 | 105 | } |
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | - if ( isset( $call['line'] ) && $call['line'] ) { |
|
| 110 | - $references = array( $file_name . ':' . $call['line'] ); |
|
| 109 | + if (isset($call['line']) && $call['line']) { |
|
| 110 | + $references = array($file_name.':'.$call['line']); |
|
| 111 | 111 | $entry->references = $references; |
| 112 | - foreach( $multiple as &$single_entry ) { |
|
| 112 | + foreach ($multiple as &$single_entry) { |
|
| 113 | 113 | $single_entry->references = $references; |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - if ( isset( $call['comment'] ) && $call['comment'] ) { |
|
| 117 | - $comments = rtrim( $call['comment'] ) . "\n"; |
|
| 116 | + if (isset($call['comment']) && $call['comment']) { |
|
| 117 | + $comments = rtrim($call['comment'])."\n"; |
|
| 118 | 118 | $entry->extracted_comments = $comments; |
| 119 | - foreach( $multiple as &$single_entry ) { |
|
| 119 | + foreach ($multiple as &$single_entry) { |
|
| 120 | 120 | $single_entry->extracted_comments = $comments; |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - if ( $multiple && $entry ) { |
|
| 123 | + if ($multiple && $entry) { |
|
| 124 | 124 | $multiple[] = $entry; |
| 125 | 125 | return $multiple; |
| 126 | 126 | } |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | return $entry; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - function extract_from_code( $code, $file_name ) { |
|
| 131 | + function extract_from_code($code, $file_name) { |
|
| 132 | 132 | $translations = new Translations; |
| 133 | - $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
|
| 134 | - foreach( $function_calls as $call ) { |
|
| 135 | - $entry = $this->entry_from_call( $call, $file_name ); |
|
| 136 | - if ( is_array( $entry ) ) |
|
| 137 | - foreach( $entry as $single_entry ) |
|
| 138 | - $translations->add_entry_or_merge( $single_entry ); |
|
| 139 | - elseif ( $entry) |
|
| 140 | - $translations->add_entry_or_merge( $entry ); |
|
| 133 | + $function_calls = $this->find_function_calls(array_keys($this->rules), $code); |
|
| 134 | + foreach ($function_calls as $call) { |
|
| 135 | + $entry = $this->entry_from_call($call, $file_name); |
|
| 136 | + if (is_array($entry)) |
|
| 137 | + foreach ($entry as $single_entry) |
|
| 138 | + $translations->add_entry_or_merge($single_entry); |
|
| 139 | + elseif ($entry) |
|
| 140 | + $translations->add_entry_or_merge($entry); |
|
| 141 | 141 | } |
| 142 | 142 | return $translations; |
| 143 | 143 | } |
@@ -148,70 +148,70 @@ discard block |
||
| 148 | 148 | * - args - array for the function arguments. Each string literal is represented by itself, other arguments are represented by null. |
| 149 | 149 | * - line - line number |
| 150 | 150 | */ |
| 151 | - function find_function_calls( $function_names, $code ) { |
|
| 152 | - $tokens = token_get_all( $code ); |
|
| 151 | + function find_function_calls($function_names, $code) { |
|
| 152 | + $tokens = token_get_all($code); |
|
| 153 | 153 | $function_calls = array(); |
| 154 | 154 | $latest_comment = false; |
| 155 | 155 | $in_func = false; |
| 156 | - foreach( $tokens as $token ) { |
|
| 156 | + foreach ($tokens as $token) { |
|
| 157 | 157 | $id = $text = null; |
| 158 | - if ( is_array( $token ) ) list( $id, $text, $line ) = $token; |
|
| 159 | - if ( T_WHITESPACE == $id ) continue; |
|
| 160 | - if ( T_STRING == $id && in_array( $text, $function_names ) && !$in_func ) { |
|
| 158 | + if (is_array($token)) list($id, $text, $line) = $token; |
|
| 159 | + if (T_WHITESPACE == $id) continue; |
|
| 160 | + if (T_STRING == $id && in_array($text, $function_names) && ! $in_func) { |
|
| 161 | 161 | $in_func = true; |
| 162 | 162 | $paren_level = -1; |
| 163 | 163 | $args = array(); |
| 164 | 164 | $func_name = $text; |
| 165 | 165 | $func_line = $line; |
| 166 | - $func_comment = $latest_comment? $latest_comment : ''; |
|
| 166 | + $func_comment = $latest_comment ? $latest_comment : ''; |
|
| 167 | 167 | |
| 168 | 168 | $just_got_into_func = true; |
| 169 | 169 | $latest_comment = false; |
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | - if ( T_COMMENT == $id ) { |
|
| 173 | - $text = preg_replace( '%^\s+\*\s%m', '', $text ); |
|
| 174 | - $text = str_replace( array( "\r\n", "\n" ), ' ', $text );; |
|
| 175 | - $text = trim( preg_replace( '%^/\*|//%', '', preg_replace( '%\*/$%', '', $text ) ) ); |
|
| 176 | - if ( 0 === stripos( $text, $this->comment_prefix ) ) { |
|
| 172 | + if (T_COMMENT == $id) { |
|
| 173 | + $text = preg_replace('%^\s+\*\s%m', '', $text); |
|
| 174 | + $text = str_replace(array("\r\n", "\n"), ' ', $text); ; |
|
| 175 | + $text = trim(preg_replace('%^/\*|//%', '', preg_replace('%\*/$%', '', $text))); |
|
| 176 | + if (0 === stripos($text, $this->comment_prefix)) { |
|
| 177 | 177 | $latest_comment = $text; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | - if ( !$in_func ) continue; |
|
| 181 | - if ( '(' == $token ) { |
|
| 180 | + if ( ! $in_func) continue; |
|
| 181 | + if ('(' == $token) { |
|
| 182 | 182 | $paren_level++; |
| 183 | - if ( 0 == $paren_level ) { // start of first argument |
|
| 183 | + if (0 == $paren_level) { // start of first argument |
|
| 184 | 184 | $just_got_into_func = false; |
| 185 | 185 | $current_argument = null; |
| 186 | 186 | $current_argument_is_just_literal = true; |
| 187 | 187 | } |
| 188 | 188 | continue; |
| 189 | 189 | } |
| 190 | - if ( $just_got_into_func ) { |
|
| 190 | + if ($just_got_into_func) { |
|
| 191 | 191 | // there wasn't a opening paren just after the function name -- this means it is not a function |
| 192 | 192 | $in_func = false; |
| 193 | 193 | $just_got_into_func = false; |
| 194 | 194 | } |
| 195 | - if ( ')' == $token ) { |
|
| 196 | - if ( 0 == $paren_level ) { |
|
| 195 | + if (')' == $token) { |
|
| 196 | + if (0 == $paren_level) { |
|
| 197 | 197 | $in_func = false; |
| 198 | 198 | $args[] = $current_argument; |
| 199 | - $call = array( 'name' => $func_name, 'args' => $args, 'line' => $func_line ); |
|
| 200 | - if ( $func_comment ) $call['comment'] = $func_comment; |
|
| 199 | + $call = array('name' => $func_name, 'args' => $args, 'line' => $func_line); |
|
| 200 | + if ($func_comment) $call['comment'] = $func_comment; |
|
| 201 | 201 | $function_calls[] = $call; |
| 202 | 202 | } |
| 203 | 203 | $paren_level--; |
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | - if ( ',' == $token && 0 == $paren_level ) { |
|
| 206 | + if (',' == $token && 0 == $paren_level) { |
|
| 207 | 207 | $args[] = $current_argument; |
| 208 | 208 | $current_argument = null; |
| 209 | 209 | $current_argument_is_just_literal = true; |
| 210 | 210 | continue; |
| 211 | 211 | } |
| 212 | - if ( T_CONSTANT_ENCAPSED_STRING == $id && $current_argument_is_just_literal ) { |
|
| 212 | + if (T_CONSTANT_ENCAPSED_STRING == $id && $current_argument_is_just_literal) { |
|
| 213 | 213 | // we can use eval safely, because we are sure $text is just a string literal |
| 214 | - eval('$current_argument = '.$text.';' ); |
|
| 214 | + eval('$current_argument = '.$text.';'); |
|
| 215 | 215 | continue; |
| 216 | 216 | } |
| 217 | 217 | $current_argument_is_just_literal = false; |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | $translations = new Translations; |
| 27 | 27 | $file_names = (array) scandir( '.' ); |
| 28 | 28 | foreach ( $file_names as $file_name ) { |
| 29 | - if ( '.' == $file_name || '..' == $file_name ) continue; |
|
| 29 | + if ( '.' == $file_name || '..' == $file_name ) { |
|
| 30 | + continue; |
|
| 31 | + } |
|
| 30 | 32 | if ( preg_match( '/\.php$/', $file_name ) && $this->does_file_name_match( $prefix . $file_name, $excludes, $includes ) ) { |
| 31 | 33 | $extracted = $this->extract_from_file( $file_name, $prefix ); |
| 32 | 34 | $translations->merge_originals_with( $extracted ); |
@@ -54,7 +56,9 @@ discard block |
||
| 54 | 56 | break; |
| 55 | 57 | } |
| 56 | 58 | } |
| 57 | - if ( !$matched_any_include ) return false; |
|
| 59 | + if ( !$matched_any_include ) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 58 | 62 | } |
| 59 | 63 | if ( $excludes ) { |
| 60 | 64 | foreach( $excludes as $exclude ) { |
@@ -68,12 +72,16 @@ discard block |
||
| 68 | 72 | |
| 69 | 73 | function entry_from_call( $call, $file_name ) { |
| 70 | 74 | $rule = isset( $this->rules[$call['name']] )? $this->rules[$call['name']] : null; |
| 71 | - if ( !$rule ) return null; |
|
| 75 | + if ( !$rule ) { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 72 | 78 | $entry = new Translation_Entry; |
| 73 | 79 | $multiple = array(); |
| 74 | 80 | $complete = false; |
| 75 | 81 | for( $i = 0; $i < count( $rule ); ++$i ) { |
| 76 | - if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
|
| 82 | + if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 77 | 85 | switch( $rule[$i] ) { |
| 78 | 86 | case 'string': |
| 79 | 87 | if ( $complete ) { |
@@ -133,11 +141,12 @@ discard block |
||
| 133 | 141 | $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
| 134 | 142 | foreach( $function_calls as $call ) { |
| 135 | 143 | $entry = $this->entry_from_call( $call, $file_name ); |
| 136 | - if ( is_array( $entry ) ) |
|
| 137 | - foreach( $entry as $single_entry ) |
|
| 144 | + if ( is_array( $entry ) ) { |
|
| 145 | + foreach( $entry as $single_entry ) |
|
| 138 | 146 | $translations->add_entry_or_merge( $single_entry ); |
| 139 | - elseif ( $entry) |
|
| 140 | - $translations->add_entry_or_merge( $entry ); |
|
| 147 | + } elseif ( $entry) { |
|
| 148 | + $translations->add_entry_or_merge( $entry ); |
|
| 149 | + } |
|
| 141 | 150 | } |
| 142 | 151 | return $translations; |
| 143 | 152 | } |
@@ -155,8 +164,12 @@ discard block |
||
| 155 | 164 | $in_func = false; |
| 156 | 165 | foreach( $tokens as $token ) { |
| 157 | 166 | $id = $text = null; |
| 158 | - if ( is_array( $token ) ) list( $id, $text, $line ) = $token; |
|
| 159 | - if ( T_WHITESPACE == $id ) continue; |
|
| 167 | + if ( is_array( $token ) ) { |
|
| 168 | + list( $id, $text, $line ) = $token; |
|
| 169 | + } |
|
| 170 | + if ( T_WHITESPACE == $id ) { |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 160 | 173 | if ( T_STRING == $id && in_array( $text, $function_names ) && !$in_func ) { |
| 161 | 174 | $in_func = true; |
| 162 | 175 | $paren_level = -1; |
@@ -177,7 +190,9 @@ discard block |
||
| 177 | 190 | $latest_comment = $text; |
| 178 | 191 | } |
| 179 | 192 | } |
| 180 | - if ( !$in_func ) continue; |
|
| 193 | + if ( !$in_func ) { |
|
| 194 | + continue; |
|
| 195 | + } |
|
| 181 | 196 | if ( '(' == $token ) { |
| 182 | 197 | $paren_level++; |
| 183 | 198 | if ( 0 == $paren_level ) { // start of first argument |
@@ -197,7 +212,9 @@ discard block |
||
| 197 | 212 | $in_func = false; |
| 198 | 213 | $args[] = $current_argument; |
| 199 | 214 | $call = array( 'name' => $func_name, 'args' => $args, 'line' => $func_line ); |
| 200 | - if ( $func_comment ) $call['comment'] = $func_comment; |
|
| 215 | + if ( $func_comment ) { |
|
| 216 | + $call['comment'] = $func_comment; |
|
| 217 | + } |
|
| 201 | 218 | $function_calls[] = $call; |
| 202 | 219 | } |
| 203 | 220 | $paren_level--; |
@@ -153,6 +153,9 @@ discard block |
||
| 153 | 153 | unlink( $temp_file ); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | + /** |
|
| 157 | + * @param string $file |
|
| 158 | + */ |
|
| 156 | 159 | function tempnam( $file ) { |
| 157 | 160 | $tempnam = tempnam( sys_get_temp_dir(), $file ); |
| 158 | 161 | $this->temp_files[] = $tempnam; |
@@ -232,6 +235,9 @@ discard block |
||
| 232 | 235 | return $res; |
| 233 | 236 | } |
| 234 | 237 | |
| 238 | + /** |
|
| 239 | + * @param string $output |
|
| 240 | + */ |
|
| 235 | 241 | function wp_core($dir, $output) { |
| 236 | 242 | if ( file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
| 237 | 243 | |
@@ -242,6 +248,9 @@ discard block |
||
| 242 | 248 | ) ); |
| 243 | 249 | } |
| 244 | 250 | |
| 251 | + /** |
|
| 252 | + * @param string $output |
|
| 253 | + */ |
|
| 245 | 254 | function wp_frontend( $dir, $output ) { |
| 246 | 255 | if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
| 247 | 256 | return false; |
@@ -262,6 +271,9 @@ discard block |
||
| 262 | 271 | ) ); |
| 263 | 272 | } |
| 264 | 273 | |
| 274 | + /** |
|
| 275 | + * @param string $output |
|
| 276 | + */ |
|
| 265 | 277 | function wp_admin($dir, $output) { |
| 266 | 278 | if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
| 267 | 279 | return false; |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -require_once dirname( __FILE__ ) . '/not-gettexted.php'; |
|
| 3 | -require_once dirname( __FILE__ ) . '/pot-ext-meta.php'; |
|
| 4 | -require_once dirname( __FILE__ ) . '/extract.php'; |
|
| 2 | +require_once dirname(__FILE__).'/not-gettexted.php'; |
|
| 3 | +require_once dirname(__FILE__).'/pot-ext-meta.php'; |
|
| 4 | +require_once dirname(__FILE__).'/extract.php'; |
|
| 5 | 5 | |
| 6 | -if ( !defined( 'STDERR' ) ) { |
|
| 7 | - define( 'STDERR', fopen( 'php://stderr', 'w' ) ); |
|
| 6 | +if ( ! defined('STDERR')) { |
|
| 7 | + define('STDERR', fopen('php://stderr', 'w')); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | class MakePOT { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | 'comments_number_link' => array('string', 'singular', 'plural'), |
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - var $ms_files = array( 'ms-.*', '.*/ms-.*', '.*/my-.*', 'wp-activate\.php', 'wp-signup\.php', 'wp-admin/network\.php', 'wp-admin/includes/ms\.php', 'wp-admin/network/.*\.php', 'wp-admin/includes/class-wp-ms.*' ); |
|
| 56 | + var $ms_files = array('ms-.*', '.*/ms-.*', '.*/my-.*', 'wp-activate\.php', 'wp-signup\.php', 'wp-admin/network\.php', 'wp-admin/includes/ms\.php', 'wp-admin/network/.*\.php', 'wp-admin/includes/class-wp-ms.*'); |
|
| 57 | 57 | |
| 58 | 58 | var $temp_files = array(); |
| 59 | 59 | |
@@ -145,16 +145,16 @@ discard block |
||
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | 147 | function __construct($deprecated = true) { |
| 148 | - $this->extractor = new StringExtractor( $this->rules ); |
|
| 148 | + $this->extractor = new StringExtractor($this->rules); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function __destruct() { |
| 152 | - foreach ( $this->temp_files as $temp_file ) |
|
| 153 | - unlink( $temp_file ); |
|
| 152 | + foreach ($this->temp_files as $temp_file) |
|
| 153 | + unlink($temp_file); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - function tempnam( $file ) { |
|
| 157 | - $tempnam = tempnam( sys_get_temp_dir(), $file ); |
|
| 156 | + function tempnam($file) { |
|
| 157 | + $tempnam = tempnam(sys_get_temp_dir(), $file); |
|
| 158 | 158 | $this->temp_files[] = $tempnam; |
| 159 | 159 | return $tempnam; |
| 160 | 160 | } |
@@ -164,31 +164,31 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | function xgettext($project, $dir, $output_file, $placeholders = array(), $excludes = array(), $includes = array()) { |
| 167 | - $meta = array_merge( $this->meta['default'], $this->meta[$project] ); |
|
| 168 | - $placeholders = array_merge( $meta, $placeholders ); |
|
| 169 | - $meta['output'] = $this->realpath_missing( $output_file ); |
|
| 170 | - $placeholders['year'] = date( 'Y' ); |
|
| 171 | - $placeholder_keys = array_map( create_function( '$x', 'return "{".$x."}";' ), array_keys( $placeholders ) ); |
|
| 172 | - $placeholder_values = array_values( $placeholders ); |
|
| 173 | - foreach($meta as $key => $value) { |
|
| 167 | + $meta = array_merge($this->meta['default'], $this->meta[$project]); |
|
| 168 | + $placeholders = array_merge($meta, $placeholders); |
|
| 169 | + $meta['output'] = $this->realpath_missing($output_file); |
|
| 170 | + $placeholders['year'] = date('Y'); |
|
| 171 | + $placeholder_keys = array_map(create_function('$x', 'return "{".$x."}";'), array_keys($placeholders)); |
|
| 172 | + $placeholder_values = array_values($placeholders); |
|
| 173 | + foreach ($meta as $key => $value) { |
|
| 174 | 174 | $meta[$key] = str_replace($placeholder_keys, $placeholder_values, $value); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $originals = $this->extractor->extract_from_directory( $dir, $excludes, $includes ); |
|
| 177 | + $originals = $this->extractor->extract_from_directory($dir, $excludes, $includes); |
|
| 178 | 178 | $pot = new PO; |
| 179 | 179 | $pot->entries = $originals->entries; |
| 180 | 180 | |
| 181 | - $pot->set_header( 'Project-Id-Version', $meta['package-name'].' '.$meta['package-version'] ); |
|
| 182 | - $pot->set_header( 'Report-Msgid-Bugs-To', $meta['msgid-bugs-address'] ); |
|
| 183 | - $pot->set_header( 'POT-Creation-Date', gmdate( 'Y-m-d H:i:s+00:00' ) ); |
|
| 184 | - $pot->set_header( 'MIME-Version', '1.0' ); |
|
| 185 | - $pot->set_header( 'Content-Type', 'text/plain; charset=UTF-8' ); |
|
| 186 | - $pot->set_header( 'Content-Transfer-Encoding', '8bit' ); |
|
| 187 | - $pot->set_header( 'PO-Revision-Date', date( 'Y') . '-MO-DA HO:MI+ZONE' ); |
|
| 188 | - $pot->set_header( 'Last-Translator', 'FULL NAME <EMAIL@ADDRESS>' ); |
|
| 189 | - $pot->set_header( 'Language-Team', 'LANGUAGE <[email protected]>' ); |
|
| 190 | - $pot->set_comment_before_headers( $meta['comments'] ); |
|
| 191 | - $pot->export_to_file( $output_file ); |
|
| 181 | + $pot->set_header('Project-Id-Version', $meta['package-name'].' '.$meta['package-version']); |
|
| 182 | + $pot->set_header('Report-Msgid-Bugs-To', $meta['msgid-bugs-address']); |
|
| 183 | + $pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00')); |
|
| 184 | + $pot->set_header('MIME-Version', '1.0'); |
|
| 185 | + $pot->set_header('Content-Type', 'text/plain; charset=UTF-8'); |
|
| 186 | + $pot->set_header('Content-Transfer-Encoding', '8bit'); |
|
| 187 | + $pot->set_header('PO-Revision-Date', date('Y').'-MO-DA HO:MI+ZONE'); |
|
| 188 | + $pot->set_header('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>'); |
|
| 189 | + $pot->set_header('Language-Team', 'LANGUAGE <[email protected]>'); |
|
| 190 | + $pot->set_comment_before_headers($meta['comments']); |
|
| 191 | + $pot->export_to_file($output_file); |
|
| 192 | 192 | return true; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -199,203 +199,203 @@ discard block |
||
| 199 | 199 | 'default_output' => 'wordpress.pot', |
| 200 | 200 | 'includes' => array(), |
| 201 | 201 | 'excludes' => array_merge( |
| 202 | - array('wp-admin/includes/continents-cities\.php', 'wp-content/themes/twenty.*', ), |
|
| 202 | + array('wp-admin/includes/continents-cities\.php', 'wp-content/themes/twenty.*',), |
|
| 203 | 203 | $this->ms_files |
| 204 | 204 | ), |
| 205 | 205 | 'extract_not_gettexted' => false, |
| 206 | 206 | 'not_gettexted_files_filter' => false, |
| 207 | 207 | ); |
| 208 | - $args = array_merge( $defaults, $args ); |
|
| 209 | - extract( $args ); |
|
| 208 | + $args = array_merge($defaults, $args); |
|
| 209 | + extract($args); |
|
| 210 | 210 | $placeholders = array(); |
| 211 | - if ( $wp_version = $this->wp_version( $dir ) ) |
|
| 211 | + if ($wp_version = $this->wp_version($dir)) |
|
| 212 | 212 | $placeholders['version'] = $wp_version; |
| 213 | 213 | else |
| 214 | 214 | return false; |
| 215 | - $output = is_null( $output )? $default_output : $output; |
|
| 216 | - $res = $this->xgettext( $project, $dir, $output, $placeholders, $excludes, $includes ); |
|
| 217 | - if ( !$res ) return false; |
|
| 215 | + $output = is_null($output) ? $default_output : $output; |
|
| 216 | + $res = $this->xgettext($project, $dir, $output, $placeholders, $excludes, $includes); |
|
| 217 | + if ( ! $res) return false; |
|
| 218 | 218 | |
| 219 | - if ( $extract_not_gettexted ) { |
|
| 219 | + if ($extract_not_gettexted) { |
|
| 220 | 220 | $old_dir = getcwd(); |
| 221 | - $output = realpath( $output ); |
|
| 222 | - chdir( $dir ); |
|
| 221 | + $output = realpath($output); |
|
| 222 | + chdir($dir); |
|
| 223 | 223 | $php_files = NotGettexted::list_php_files('.'); |
| 224 | - $php_files = array_filter( $php_files, $not_gettexted_files_filter ); |
|
| 224 | + $php_files = array_filter($php_files, $not_gettexted_files_filter); |
|
| 225 | 225 | $not_gettexted = new NotGettexted; |
| 226 | - $res = $not_gettexted->command_extract( $output, $php_files ); |
|
| 227 | - chdir( $old_dir ); |
|
| 226 | + $res = $not_gettexted->command_extract($output, $php_files); |
|
| 227 | + chdir($old_dir); |
|
| 228 | 228 | /* Adding non-gettexted strings can repeat some phrases */ |
| 229 | - $output_shell = escapeshellarg( $output ); |
|
| 230 | - system( "msguniq --use-first $output_shell -o $output_shell" ); |
|
| 229 | + $output_shell = escapeshellarg($output); |
|
| 230 | + system("msguniq --use-first $output_shell -o $output_shell"); |
|
| 231 | 231 | } |
| 232 | 232 | return $res; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | function wp_core($dir, $output) { |
| 236 | - if ( file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 236 | + if (file_exists("$dir/wp-admin/user/about.php")) return false; |
|
| 237 | 237 | |
| 238 | - return $this->wp_generic( $dir, array( |
|
| 238 | + return $this->wp_generic($dir, array( |
|
| 239 | 239 | 'project' => 'wp-core', 'output' => $output, |
| 240 | 240 | 'extract_not_gettexted' => true, |
| 241 | - 'not_gettexted_files_filter' => array( $this, 'is_not_ms_file' ), |
|
| 242 | - ) ); |
|
| 241 | + 'not_gettexted_files_filter' => array($this, 'is_not_ms_file'), |
|
| 242 | + )); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - function wp_frontend( $dir, $output ) { |
|
| 246 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
| 245 | + function wp_frontend($dir, $output) { |
|
| 246 | + if ( ! file_exists("$dir/wp-admin/user/about.php")) { |
|
| 247 | 247 | return false; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $excludes = array( 'wp-admin/.*', 'wp-content/themes/.*', 'wp-includes/class-pop3\.php' ); |
|
| 250 | + $excludes = array('wp-admin/.*', 'wp-content/themes/.*', 'wp-includes/class-pop3\.php'); |
|
| 251 | 251 | |
| 252 | 252 | // Exclude Akismet all together for 3.9+. |
| 253 | - if ( file_exists( "$dir/wp-admin/css/about.css" ) ) { |
|
| 253 | + if (file_exists("$dir/wp-admin/css/about.css")) { |
|
| 254 | 254 | $excludes[] = 'wp-content/plugins/akismet/.*'; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - return $this->wp_generic( $dir, array( |
|
| 257 | + return $this->wp_generic($dir, array( |
|
| 258 | 258 | 'project' => 'wp-frontend', 'output' => $output, |
| 259 | 259 | 'includes' => array(), |
| 260 | 260 | 'excludes' => $excludes, |
| 261 | 261 | 'default_output' => 'wordpress.pot', |
| 262 | - ) ); |
|
| 262 | + )); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | function wp_admin($dir, $output) { |
| 266 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
| 266 | + if ( ! file_exists("$dir/wp-admin/user/about.php")) { |
|
| 267 | 267 | return false; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $frontend_pot = $this->tempnam( 'frontend.pot' ); |
|
| 271 | - if ( false === $frontend_pot ) { |
|
| 270 | + $frontend_pot = $this->tempnam('frontend.pot'); |
|
| 271 | + if (false === $frontend_pot) { |
|
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
|
| 276 | - if ( ! $frontend_result ) { |
|
| 275 | + $frontend_result = $this->wp_frontend($dir, $frontend_pot); |
|
| 276 | + if ( ! $frontend_result) { |
|
| 277 | 277 | return false; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $result = $this->wp_generic( $dir, array( |
|
| 280 | + $result = $this->wp_generic($dir, array( |
|
| 281 | 281 | 'project' => 'wp-admin', 'output' => $output, |
| 282 | - 'includes' => array( 'wp-admin/.*' ), |
|
| 283 | - 'excludes' => array( 'wp-admin/includes/continents-cities\.php', 'wp-admin/network/.*', 'wp-admin/network.php' ), |
|
| 282 | + 'includes' => array('wp-admin/.*'), |
|
| 283 | + 'excludes' => array('wp-admin/includes/continents-cities\.php', 'wp-admin/network/.*', 'wp-admin/network.php'), |
|
| 284 | 284 | 'default_output' => 'wordpress-admin.pot', |
| 285 | - ) ); |
|
| 286 | - if ( ! $result ) { |
|
| 285 | + )); |
|
| 286 | + if ( ! $result) { |
|
| 287 | 287 | return false; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $potextmeta = new PotExtMeta; |
| 291 | 291 | |
| 292 | - if ( ! file_exists( "$dir/wp-admin/css/about.css" ) ) { // < 3.9 |
|
| 293 | - $result = $potextmeta->append( "$dir/wp-content/plugins/akismet/akismet.php", $output ); |
|
| 294 | - if ( ! $result ) { |
|
| 292 | + if ( ! file_exists("$dir/wp-admin/css/about.css")) { // < 3.9 |
|
| 293 | + $result = $potextmeta->append("$dir/wp-content/plugins/akismet/akismet.php", $output); |
|
| 294 | + if ( ! $result) { |
|
| 295 | 295 | return false; |
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $result = $potextmeta->append( "$dir/wp-content/plugins/hello.php", $output ); |
|
| 300 | - if ( ! $result ) { |
|
| 299 | + $result = $potextmeta->append("$dir/wp-content/plugins/hello.php", $output); |
|
| 300 | + if ( ! $result) { |
|
| 301 | 301 | return false; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /* Adding non-gettexted strings can repeat some phrases */ |
| 305 | - $output_shell = escapeshellarg( $output ); |
|
| 306 | - system( "msguniq $output_shell -o $output_shell" ); |
|
| 305 | + $output_shell = escapeshellarg($output); |
|
| 306 | + system("msguniq $output_shell -o $output_shell"); |
|
| 307 | 307 | |
| 308 | - $common_pot = $this->tempnam( 'common.pot' ); |
|
| 309 | - if ( ! $common_pot ) { |
|
| 308 | + $common_pot = $this->tempnam('common.pot'); |
|
| 309 | + if ( ! $common_pot) { |
|
| 310 | 310 | return false; |
| 311 | 311 | } |
| 312 | - $admin_pot = realpath( is_null( $output ) ? 'wordpress-admin.pot' : $output ); |
|
| 313 | - system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot > $common_pot" ); |
|
| 314 | - system( "msgcat -u --use-first $admin_pot $common_pot -o $admin_pot" ); |
|
| 312 | + $admin_pot = realpath(is_null($output) ? 'wordpress-admin.pot' : $output); |
|
| 313 | + system("msgcat --more-than=1 --use-first $frontend_pot $admin_pot > $common_pot"); |
|
| 314 | + system("msgcat -u --use-first $admin_pot $common_pot -o $admin_pot"); |
|
| 315 | 315 | return true; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | function wp_network_admin($dir, $output) { |
| 319 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 319 | + if ( ! file_exists("$dir/wp-admin/user/about.php")) return false; |
|
| 320 | 320 | |
| 321 | - $frontend_pot = $this->tempnam( 'frontend.pot' ); |
|
| 322 | - if ( false === $frontend_pot ) return false; |
|
| 321 | + $frontend_pot = $this->tempnam('frontend.pot'); |
|
| 322 | + if (false === $frontend_pot) return false; |
|
| 323 | 323 | |
| 324 | - $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
|
| 325 | - if ( ! $frontend_result ) |
|
| 324 | + $frontend_result = $this->wp_frontend($dir, $frontend_pot); |
|
| 325 | + if ( ! $frontend_result) |
|
| 326 | 326 | return false; |
| 327 | 327 | |
| 328 | - $admin_pot = $this->tempnam( 'admin.pot' ); |
|
| 329 | - if ( false === $admin_pot ) return false; |
|
| 328 | + $admin_pot = $this->tempnam('admin.pot'); |
|
| 329 | + if (false === $admin_pot) return false; |
|
| 330 | 330 | |
| 331 | - $admin_result = $this->wp_admin( $dir, $admin_pot ); |
|
| 332 | - if ( ! $admin_result ) |
|
| 331 | + $admin_result = $this->wp_admin($dir, $admin_pot); |
|
| 332 | + if ( ! $admin_result) |
|
| 333 | 333 | return false; |
| 334 | 334 | |
| 335 | - $result = $this->wp_generic( $dir, array( |
|
| 335 | + $result = $this->wp_generic($dir, array( |
|
| 336 | 336 | 'project' => 'wp-network-admin', 'output' => $output, |
| 337 | - 'includes' => array( 'wp-admin/network/.*', 'wp-admin/network.php' ), |
|
| 337 | + 'includes' => array('wp-admin/network/.*', 'wp-admin/network.php'), |
|
| 338 | 338 | 'excludes' => array(), |
| 339 | 339 | 'default_output' => 'wordpress-admin-network.pot', |
| 340 | - ) ); |
|
| 340 | + )); |
|
| 341 | 341 | |
| 342 | - if ( ! $result ) { |
|
| 342 | + if ( ! $result) { |
|
| 343 | 343 | return false; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - $common_pot = $this->tempnam( 'common.pot' ); |
|
| 347 | - if ( ! $common_pot ) |
|
| 346 | + $common_pot = $this->tempnam('common.pot'); |
|
| 347 | + if ( ! $common_pot) |
|
| 348 | 348 | return false; |
| 349 | 349 | |
| 350 | - $net_admin_pot = realpath( is_null( $output ) ? 'wordpress-network-admin.pot' : $output ); |
|
| 351 | - system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot" ); |
|
| 352 | - system( "msgcat -u --use-first $net_admin_pot $common_pot -o $net_admin_pot" ); |
|
| 350 | + $net_admin_pot = realpath(is_null($output) ? 'wordpress-network-admin.pot' : $output); |
|
| 351 | + system("msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot"); |
|
| 352 | + system("msgcat -u --use-first $net_admin_pot $common_pot -o $net_admin_pot"); |
|
| 353 | 353 | return true; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | function wp_ms($dir, $output) { |
| 357 | - if ( file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 358 | - if ( !is_file("$dir/wp-admin/ms-users.php") ) return false; |
|
| 359 | - $core_pot = $this->tempnam( 'wordpress.pot' ); |
|
| 360 | - if ( false === $core_pot ) return false; |
|
| 361 | - $core_result = $this->wp_core( $dir, $core_pot ); |
|
| 362 | - if ( ! $core_result ) |
|
| 357 | + if (file_exists("$dir/wp-admin/user/about.php")) return false; |
|
| 358 | + if ( ! is_file("$dir/wp-admin/ms-users.php")) return false; |
|
| 359 | + $core_pot = $this->tempnam('wordpress.pot'); |
|
| 360 | + if (false === $core_pot) return false; |
|
| 361 | + $core_result = $this->wp_core($dir, $core_pot); |
|
| 362 | + if ( ! $core_result) |
|
| 363 | 363 | return false; |
| 364 | - $ms_result = $this->wp_generic( $dir, array( |
|
| 364 | + $ms_result = $this->wp_generic($dir, array( |
|
| 365 | 365 | 'project' => 'wp-ms', 'output' => $output, |
| 366 | 366 | 'includes' => $this->ms_files, |
| 367 | 367 | 'excludes' => array(), |
| 368 | 368 | 'default_output' => 'wordpress-ms.pot', |
| 369 | 369 | 'extract_not_gettexted' => true, |
| 370 | - 'not_gettexted_files_filter' => array( $this, 'is_ms_file' ), |
|
| 371 | - ) ); |
|
| 372 | - if ( !$ms_result ) { |
|
| 370 | + 'not_gettexted_files_filter' => array($this, 'is_ms_file'), |
|
| 371 | + )); |
|
| 372 | + if ( ! $ms_result) { |
|
| 373 | 373 | return false; |
| 374 | 374 | } |
| 375 | - $common_pot = $this->tempnam( 'common.pot' ); |
|
| 376 | - if ( ! $common_pot ) |
|
| 375 | + $common_pot = $this->tempnam('common.pot'); |
|
| 376 | + if ( ! $common_pot) |
|
| 377 | 377 | return false; |
| 378 | - $ms_pot = realpath( is_null( $output )? 'wordpress-ms.pot' : $output ); |
|
| 379 | - system( "msgcat --more-than=1 --use-first $core_pot $ms_pot > $common_pot" ); |
|
| 380 | - system( "msgcat -u --use-first $ms_pot $common_pot -o $ms_pot" ); |
|
| 378 | + $ms_pot = realpath(is_null($output) ? 'wordpress-ms.pot' : $output); |
|
| 379 | + system("msgcat --more-than=1 --use-first $core_pot $ms_pot > $common_pot"); |
|
| 380 | + system("msgcat -u --use-first $ms_pot $common_pot -o $ms_pot"); |
|
| 381 | 381 | return true; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | function wp_tz($dir, $output) { |
| 385 | 385 | $continents_path = 'wp-admin/includes/continents-cities.php'; |
| 386 | - if ( !file_exists( "$dir/$continents_path" ) ) return false; |
|
| 387 | - return $this->wp_generic( $dir, array( |
|
| 386 | + if ( ! file_exists("$dir/$continents_path")) return false; |
|
| 387 | + return $this->wp_generic($dir, array( |
|
| 388 | 388 | 'project' => 'wp-tz', 'output' => $output, |
| 389 | - 'includes' => array( $continents_path ), |
|
| 389 | + 'includes' => array($continents_path), |
|
| 390 | 390 | 'excludes' => array(), |
| 391 | 391 | 'default_output' => 'wordpress-continents-cities.pot', |
| 392 | - ) ); |
|
| 392 | + )); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | function wp_version($dir) { |
| 396 | 396 | $version_php = $dir.'/wp-includes/version.php'; |
| 397 | - if ( !is_readable( $version_php ) ) return false; |
|
| 398 | - return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches )? $matches[1] : false; |
|
| 397 | + if ( ! is_readable($version_php)) return false; |
|
| 398 | + return preg_match('/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents($version_php), $matches) ? $matches[1] : false; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -404,23 +404,23 @@ discard block |
||
| 404 | 404 | if (preg_match('/\$wpmu_version\s*=\s*\'(.*?)\';/', file_get_contents($dir.'/wp-includes/version.php'), $matches)) { |
| 405 | 405 | $placeholders['version'] = $matches[1]; |
| 406 | 406 | } |
| 407 | - $output = is_null($output)? 'wordpress.pot' : $output; |
|
| 407 | + $output = is_null($output) ? 'wordpress.pot' : $output; |
|
| 408 | 408 | return $this->xgettext('wp', $dir, $output, $placeholders); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
| 412 | 412 | function bb($dir, $output) { |
| 413 | 413 | $placeholders = array(); |
| 414 | - $output = is_null($output)? 'bbpress.pot' : $output; |
|
| 414 | + $output = is_null($output) ? 'bbpress.pot' : $output; |
|
| 415 | 415 | return $this->xgettext('bb', $dir, $output, $placeholders); |
| 416 | 416 | |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | function get_first_lines($filename, $lines = 30) { |
| 420 | 420 | $extf = fopen($filename, 'r'); |
| 421 | - if (!$extf) return false; |
|
| 421 | + if ( ! $extf) return false; |
|
| 422 | 422 | $first_lines = ''; |
| 423 | - foreach(range(1, $lines) as $x) { |
|
| 423 | + foreach (range(1, $lines) as $x) { |
|
| 424 | 424 | $line = fgets($extf); |
| 425 | 425 | if (feof($extf)) break; |
| 426 | 426 | if (false === $line) { |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | function generic($dir, $output) { |
| 443 | - $output = is_null($output)? "generic.pot" : $output; |
|
| 443 | + $output = is_null($output) ? "generic.pot" : $output; |
|
| 444 | 444 | return $this->xgettext('generic', $dir, $output, array()); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -462,41 +462,41 @@ discard block |
||
| 462 | 462 | $slug = $this->guess_plugin_slug($dir); |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - $plugins_dir = @opendir( $dir ); |
|
| 465 | + $plugins_dir = @opendir($dir); |
|
| 466 | 466 | $plugin_files = array(); |
| 467 | - if ( $plugins_dir ) { |
|
| 468 | - while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
| 469 | - if ( '.' === substr( $file, 0, 1 ) ) { |
|
| 467 | + if ($plugins_dir) { |
|
| 468 | + while (($file = readdir($plugins_dir)) !== false) { |
|
| 469 | + if ('.' === substr($file, 0, 1)) { |
|
| 470 | 470 | continue; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if ( '.php' === substr( $file, -4 ) ) { |
|
| 473 | + if ('.php' === substr($file, -4)) { |
|
| 474 | 474 | $plugin_files[] = $file; |
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | - closedir( $plugins_dir ); |
|
| 477 | + closedir($plugins_dir); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - if ( empty( $plugin_files ) ) { |
|
| 480 | + if (empty($plugin_files)) { |
|
| 481 | 481 | return false; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | $main_file = ''; |
| 485 | - foreach ( $plugin_files as $plugin_file ) { |
|
| 486 | - if ( ! is_readable( "$dir/$plugin_file" ) ) { |
|
| 485 | + foreach ($plugin_files as $plugin_file) { |
|
| 486 | + if ( ! is_readable("$dir/$plugin_file")) { |
|
| 487 | 487 | continue; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - $source = $this->get_first_lines( "$dir/$plugin_file", $this->max_header_lines ); |
|
| 490 | + $source = $this->get_first_lines("$dir/$plugin_file", $this->max_header_lines); |
|
| 491 | 491 | |
| 492 | 492 | // Stop when we find a file with a plugin name header in it. |
| 493 | - if ( $this->get_addon_header( 'Plugin Name', $source ) != false ) { |
|
| 493 | + if ($this->get_addon_header('Plugin Name', $source) != false) { |
|
| 494 | 494 | $main_file = "$dir/$plugin_file"; |
| 495 | 495 | break; |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - if ( empty( $main_file ) ) { |
|
| 499 | + if (empty($main_file)) { |
|
| 500 | 500 | return false; |
| 501 | 501 | } |
| 502 | 502 | |
@@ -505,9 +505,9 @@ discard block |
||
| 505 | 505 | $placeholders['name'] = $this->get_addon_header('Plugin Name', $source); |
| 506 | 506 | $placeholders['slug'] = $slug; |
| 507 | 507 | |
| 508 | - $output = is_null($output)? "$slug.pot" : $output; |
|
| 508 | + $output = is_null($output) ? "$slug.pot" : $output; |
|
| 509 | 509 | $res = $this->xgettext('wp-plugin', $dir, $output, $placeholders); |
| 510 | - if (!$res) return false; |
|
| 510 | + if ( ! $res) return false; |
|
| 511 | 511 | $potextmeta = new PotExtMeta; |
| 512 | 512 | $res = $potextmeta->append($main_file, $output); |
| 513 | 513 | /* Adding non-gettexted strings can repeat some phrases */ |
@@ -530,37 +530,37 @@ discard block |
||
| 530 | 530 | $placeholders['name'] = $this->get_addon_header('Theme Name', $source); |
| 531 | 531 | $placeholders['slug'] = $slug; |
| 532 | 532 | |
| 533 | - $license = $this->get_addon_header( 'License', $source ); |
|
| 534 | - if ( $license ) |
|
| 533 | + $license = $this->get_addon_header('License', $source); |
|
| 534 | + if ($license) |
|
| 535 | 535 | $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
| 536 | 536 | else |
| 537 | 537 | $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
| 538 | 538 | |
| 539 | - $output = is_null($output)? "$slug.pot" : $output; |
|
| 539 | + $output = is_null($output) ? "$slug.pot" : $output; |
|
| 540 | 540 | $res = $this->xgettext('wp-theme', $dir, $output, $placeholders); |
| 541 | - if (! $res ) |
|
| 541 | + if ( ! $res) |
|
| 542 | 542 | return false; |
| 543 | 543 | $potextmeta = new PotExtMeta; |
| 544 | - $res = $potextmeta->append( $main_file, $output, array( 'Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI' ) ); |
|
| 545 | - if ( ! $res ) |
|
| 544 | + $res = $potextmeta->append($main_file, $output, array('Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI')); |
|
| 545 | + if ( ! $res) |
|
| 546 | 546 | return false; |
| 547 | 547 | // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4. |
| 548 | - $extract_templates = ! in_array( $slug, array( 'twentyten', 'twentyeleven', 'default', 'classic' ) ); |
|
| 549 | - if ( ! $extract_templates ) { |
|
| 550 | - $wp_dir = dirname( dirname( dirname( $dir ) ) ); |
|
| 551 | - $extract_templates = file_exists( "$wp_dir/wp-admin/user/about.php" ) || ! file_exists( "$wp_dir/wp-load.php" ); |
|
| 548 | + $extract_templates = ! in_array($slug, array('twentyten', 'twentyeleven', 'default', 'classic')); |
|
| 549 | + if ( ! $extract_templates) { |
|
| 550 | + $wp_dir = dirname(dirname(dirname($dir))); |
|
| 551 | + $extract_templates = file_exists("$wp_dir/wp-admin/user/about.php") || ! file_exists("$wp_dir/wp-load.php"); |
|
| 552 | 552 | } |
| 553 | - if ( $extract_templates ) { |
|
| 554 | - $res = $potextmeta->append( $dir, $output, array( 'Template Name' ) ); |
|
| 555 | - if ( ! $res ) |
|
| 553 | + if ($extract_templates) { |
|
| 554 | + $res = $potextmeta->append($dir, $output, array('Template Name')); |
|
| 555 | + if ( ! $res) |
|
| 556 | 556 | return false; |
| 557 | - $files = scandir( $dir ); |
|
| 558 | - foreach ( $files as $file ) { |
|
| 559 | - if ( '.' == $file[0] || 'CVS' == $file ) |
|
| 557 | + $files = scandir($dir); |
|
| 558 | + foreach ($files as $file) { |
|
| 559 | + if ('.' == $file[0] || 'CVS' == $file) |
|
| 560 | 560 | continue; |
| 561 | - if ( is_dir( $dir . '/' . $file ) ) { |
|
| 562 | - $res = $potextmeta->append( $dir . '/' . $file, $output, array( 'Template Name' ) ); |
|
| 563 | - if ( ! $res ) |
|
| 561 | + if (is_dir($dir.'/'.$file)) { |
|
| 562 | + $res = $potextmeta->append($dir.'/'.$file, $output, array('Template Name')); |
|
| 563 | + if ( ! $res) |
|
| 564 | 564 | return false; |
| 565 | 565 | } |
| 566 | 566 | } |
@@ -572,47 +572,47 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | function bp($dir, $output) { |
| 575 | - $output = is_null($output)? "buddypress.pot" : $output; |
|
| 575 | + $output = is_null($output) ? "buddypress.pot" : $output; |
|
| 576 | 576 | return $this->xgettext('bp', $dir, $output, array(), array('bp-forums/bbpress/.*')); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - function glotpress( $dir, $output ) { |
|
| 580 | - $output = is_null( $output ) ? "glotpress.pot" : $output; |
|
| 581 | - return $this->xgettext( 'glotpress', $dir, $output ); |
|
| 579 | + function glotpress($dir, $output) { |
|
| 580 | + $output = is_null($output) ? "glotpress.pot" : $output; |
|
| 581 | + return $this->xgettext('glotpress', $dir, $output); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - function wporg_bb_forums( $dir, $output ) { |
|
| 585 | - $output = is_null( $output ) ? 'wporg.pot' : $output; |
|
| 586 | - return $this->xgettext( 'wporg-bb-forums', $dir, $output, array(), array( |
|
| 584 | + function wporg_bb_forums($dir, $output) { |
|
| 585 | + $output = is_null($output) ? 'wporg.pot' : $output; |
|
| 586 | + return $this->xgettext('wporg-bb-forums', $dir, $output, array(), array( |
|
| 587 | 587 | 'bb-plugins/elfakismet/.*', |
| 588 | 588 | 'bb-plugins/support-forum/.*', |
| 589 | - ) ); |
|
| 589 | + )); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - function rosetta( $dir, $output ) { |
|
| 593 | - $output = is_null( $output )? 'rosetta.pot' : $output; |
|
| 594 | - return $this->xgettext( 'rosetta', $dir, $output, array(), array(), array( |
|
| 592 | + function rosetta($dir, $output) { |
|
| 593 | + $output = is_null($output) ? 'rosetta.pot' : $output; |
|
| 594 | + return $this->xgettext('rosetta', $dir, $output, array(), array(), array( |
|
| 595 | 595 | 'mu-plugins/(roles|showcase|downloads)/.*\.php', |
| 596 | 596 | 'mu-plugins/rosetta.*\.php', |
| 597 | 597 | 'mu-plugins/rosetta/[^/]+\.php', |
| 598 | 598 | 'mu-plugins/rosetta/tmpl/.*\.php', |
| 599 | 599 | 'themes/rosetta/.*\.php', |
| 600 | - ) ); |
|
| 600 | + )); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - function is_ms_file( $file_name ) { |
|
| 603 | + function is_ms_file($file_name) { |
|
| 604 | 604 | $is_ms_file = false; |
| 605 | - $prefix = substr( $file_name, 0, 2 ) === './'? '\./' : ''; |
|
| 606 | - foreach( $this->ms_files as $ms_file ) |
|
| 607 | - if ( preg_match( '|^'.$prefix.$ms_file.'$|', $file_name ) ) { |
|
| 605 | + $prefix = substr($file_name, 0, 2) === './' ? '\./' : ''; |
|
| 606 | + foreach ($this->ms_files as $ms_file) |
|
| 607 | + if (preg_match('|^'.$prefix.$ms_file.'$|', $file_name)) { |
|
| 608 | 608 | $is_ms_file = true; |
| 609 | 609 | break; |
| 610 | 610 | } |
| 611 | 611 | return $is_ms_file; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - function is_not_ms_file( $file_name ) { |
|
| 615 | - return !$this->is_ms_file( $file_name ); |
|
| 614 | + function is_not_ms_file($file_name) { |
|
| 615 | + return ! $this->is_ms_file($file_name); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | if ($included_files[0] == __FILE__) { |
| 623 | 623 | $makepot = new MakePOT; |
| 624 | 624 | if ((3 == count($argv) || 4 == count($argv)) && in_array($method = str_replace('-', '_', $argv[1]), get_class_methods($makepot))) { |
| 625 | - $res = call_user_func(array($makepot, $method), realpath($argv[2]), isset($argv[3])? $argv[3] : null); |
|
| 625 | + $res = call_user_func(array($makepot, $method), realpath($argv[2]), isset($argv[3]) ? $argv[3] : null); |
|
| 626 | 626 | if (false === $res) { |
| 627 | 627 | fwrite(STDERR, "Couldn't generate POT file!\n"); |
| 628 | 628 | } |
@@ -149,8 +149,9 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function __destruct() { |
| 152 | - foreach ( $this->temp_files as $temp_file ) |
|
| 153 | - unlink( $temp_file ); |
|
| 152 | + foreach ( $this->temp_files as $temp_file ) { |
|
| 153 | + unlink( $temp_file ); |
|
| 154 | + } |
|
| 154 | 155 | } |
| 155 | 156 | |
| 156 | 157 | function tempnam( $file ) { |
@@ -208,13 +209,16 @@ discard block |
||
| 208 | 209 | $args = array_merge( $defaults, $args ); |
| 209 | 210 | extract( $args ); |
| 210 | 211 | $placeholders = array(); |
| 211 | - if ( $wp_version = $this->wp_version( $dir ) ) |
|
| 212 | - $placeholders['version'] = $wp_version; |
|
| 213 | - else |
|
| 214 | - return false; |
|
| 212 | + if ( $wp_version = $this->wp_version( $dir ) ) { |
|
| 213 | + $placeholders['version'] = $wp_version; |
|
| 214 | + } else { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 215 | 217 | $output = is_null( $output )? $default_output : $output; |
| 216 | 218 | $res = $this->xgettext( $project, $dir, $output, $placeholders, $excludes, $includes ); |
| 217 | - if ( !$res ) return false; |
|
| 219 | + if ( !$res ) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 218 | 222 | |
| 219 | 223 | if ( $extract_not_gettexted ) { |
| 220 | 224 | $old_dir = getcwd(); |
@@ -233,7 +237,9 @@ discard block |
||
| 233 | 237 | } |
| 234 | 238 | |
| 235 | 239 | function wp_core($dir, $output) { |
| 236 | - if ( file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 240 | + if ( file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 237 | 243 | |
| 238 | 244 | return $this->wp_generic( $dir, array( |
| 239 | 245 | 'project' => 'wp-core', 'output' => $output, |
@@ -316,21 +322,29 @@ discard block |
||
| 316 | 322 | } |
| 317 | 323 | |
| 318 | 324 | function wp_network_admin($dir, $output) { |
| 319 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 325 | + if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 320 | 328 | |
| 321 | 329 | $frontend_pot = $this->tempnam( 'frontend.pot' ); |
| 322 | - if ( false === $frontend_pot ) return false; |
|
| 330 | + if ( false === $frontend_pot ) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 323 | 333 | |
| 324 | 334 | $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
| 325 | - if ( ! $frontend_result ) |
|
| 326 | - return false; |
|
| 335 | + if ( ! $frontend_result ) { |
|
| 336 | + return false; |
|
| 337 | + } |
|
| 327 | 338 | |
| 328 | 339 | $admin_pot = $this->tempnam( 'admin.pot' ); |
| 329 | - if ( false === $admin_pot ) return false; |
|
| 340 | + if ( false === $admin_pot ) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 330 | 343 | |
| 331 | 344 | $admin_result = $this->wp_admin( $dir, $admin_pot ); |
| 332 | - if ( ! $admin_result ) |
|
| 333 | - return false; |
|
| 345 | + if ( ! $admin_result ) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 334 | 348 | |
| 335 | 349 | $result = $this->wp_generic( $dir, array( |
| 336 | 350 | 'project' => 'wp-network-admin', 'output' => $output, |
@@ -344,8 +358,9 @@ discard block |
||
| 344 | 358 | } |
| 345 | 359 | |
| 346 | 360 | $common_pot = $this->tempnam( 'common.pot' ); |
| 347 | - if ( ! $common_pot ) |
|
| 348 | - return false; |
|
| 361 | + if ( ! $common_pot ) { |
|
| 362 | + return false; |
|
| 363 | + } |
|
| 349 | 364 | |
| 350 | 365 | $net_admin_pot = realpath( is_null( $output ) ? 'wordpress-network-admin.pot' : $output ); |
| 351 | 366 | system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot" ); |
@@ -354,13 +369,20 @@ discard block |
||
| 354 | 369 | } |
| 355 | 370 | |
| 356 | 371 | function wp_ms($dir, $output) { |
| 357 | - if ( file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
| 358 | - if ( !is_file("$dir/wp-admin/ms-users.php") ) return false; |
|
| 372 | + if ( file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
| 373 | + return false; |
|
| 374 | + } |
|
| 375 | + if ( !is_file("$dir/wp-admin/ms-users.php") ) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 359 | 378 | $core_pot = $this->tempnam( 'wordpress.pot' ); |
| 360 | - if ( false === $core_pot ) return false; |
|
| 361 | - $core_result = $this->wp_core( $dir, $core_pot ); |
|
| 362 | - if ( ! $core_result ) |
|
| 379 | + if ( false === $core_pot ) { |
|
| 363 | 380 | return false; |
| 381 | + } |
|
| 382 | + $core_result = $this->wp_core( $dir, $core_pot ); |
|
| 383 | + if ( ! $core_result ) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 364 | 386 | $ms_result = $this->wp_generic( $dir, array( |
| 365 | 387 | 'project' => 'wp-ms', 'output' => $output, |
| 366 | 388 | 'includes' => $this->ms_files, |
@@ -373,8 +395,9 @@ discard block |
||
| 373 | 395 | return false; |
| 374 | 396 | } |
| 375 | 397 | $common_pot = $this->tempnam( 'common.pot' ); |
| 376 | - if ( ! $common_pot ) |
|
| 377 | - return false; |
|
| 398 | + if ( ! $common_pot ) { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 378 | 401 | $ms_pot = realpath( is_null( $output )? 'wordpress-ms.pot' : $output ); |
| 379 | 402 | system( "msgcat --more-than=1 --use-first $core_pot $ms_pot > $common_pot" ); |
| 380 | 403 | system( "msgcat -u --use-first $ms_pot $common_pot -o $ms_pot" ); |
@@ -383,7 +406,9 @@ discard block |
||
| 383 | 406 | |
| 384 | 407 | function wp_tz($dir, $output) { |
| 385 | 408 | $continents_path = 'wp-admin/includes/continents-cities.php'; |
| 386 | - if ( !file_exists( "$dir/$continents_path" ) ) return false; |
|
| 409 | + if ( !file_exists( "$dir/$continents_path" ) ) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 387 | 412 | return $this->wp_generic( $dir, array( |
| 388 | 413 | 'project' => 'wp-tz', 'output' => $output, |
| 389 | 414 | 'includes' => array( $continents_path ), |
@@ -394,7 +419,9 @@ discard block |
||
| 394 | 419 | |
| 395 | 420 | function wp_version($dir) { |
| 396 | 421 | $version_php = $dir.'/wp-includes/version.php'; |
| 397 | - if ( !is_readable( $version_php ) ) return false; |
|
| 422 | + if ( !is_readable( $version_php ) ) { |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 398 | 425 | return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches )? $matches[1] : false; |
| 399 | 426 | } |
| 400 | 427 | |
@@ -418,11 +445,15 @@ discard block |
||
| 418 | 445 | |
| 419 | 446 | function get_first_lines($filename, $lines = 30) { |
| 420 | 447 | $extf = fopen($filename, 'r'); |
| 421 | - if (!$extf) return false; |
|
| 448 | + if (!$extf) { |
|
| 449 | + return false; |
|
| 450 | + } |
|
| 422 | 451 | $first_lines = ''; |
| 423 | 452 | foreach(range(1, $lines) as $x) { |
| 424 | 453 | $line = fgets($extf); |
| 425 | - if (feof($extf)) break; |
|
| 454 | + if (feof($extf)) { |
|
| 455 | + break; |
|
| 456 | + } |
|
| 426 | 457 | if (false === $line) { |
| 427 | 458 | return false; |
| 428 | 459 | } |
@@ -433,10 +464,11 @@ discard block |
||
| 433 | 464 | |
| 434 | 465 | |
| 435 | 466 | function get_addon_header($header, &$source) { |
| 436 | - if (preg_match('|'.$header.':(.*)$|mi', $source, $matches)) |
|
| 437 | - return trim($matches[1]); |
|
| 438 | - else |
|
| 439 | - return false; |
|
| 467 | + if (preg_match('|'.$header.':(.*)$|mi', $source, $matches)) { |
|
| 468 | + return trim($matches[1]); |
|
| 469 | + } else { |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 440 | 472 | } |
| 441 | 473 | |
| 442 | 474 | function generic($dir, $output) { |
@@ -507,7 +539,9 @@ discard block |
||
| 507 | 539 | |
| 508 | 540 | $output = is_null($output)? "$slug.pot" : $output; |
| 509 | 541 | $res = $this->xgettext('wp-plugin', $dir, $output, $placeholders); |
| 510 | - if (!$res) return false; |
|
| 542 | + if (!$res) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 511 | 545 | $potextmeta = new PotExtMeta; |
| 512 | 546 | $res = $potextmeta->append($main_file, $output); |
| 513 | 547 | /* Adding non-gettexted strings can repeat some phrases */ |
@@ -531,19 +565,22 @@ discard block |
||
| 531 | 565 | $placeholders['slug'] = $slug; |
| 532 | 566 | |
| 533 | 567 | $license = $this->get_addon_header( 'License', $source ); |
| 534 | - if ( $license ) |
|
| 535 | - $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
|
| 536 | - else |
|
| 537 | - $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
|
| 568 | + if ( $license ) { |
|
| 569 | + $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
|
| 570 | + } else { |
|
| 571 | + $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
|
| 572 | + } |
|
| 538 | 573 | |
| 539 | 574 | $output = is_null($output)? "$slug.pot" : $output; |
| 540 | 575 | $res = $this->xgettext('wp-theme', $dir, $output, $placeholders); |
| 541 | - if (! $res ) |
|
| 542 | - return false; |
|
| 576 | + if (! $res ) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 543 | 579 | $potextmeta = new PotExtMeta; |
| 544 | 580 | $res = $potextmeta->append( $main_file, $output, array( 'Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI' ) ); |
| 545 | - if ( ! $res ) |
|
| 546 | - return false; |
|
| 581 | + if ( ! $res ) { |
|
| 582 | + return false; |
|
| 583 | + } |
|
| 547 | 584 | // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4. |
| 548 | 585 | $extract_templates = ! in_array( $slug, array( 'twentyten', 'twentyeleven', 'default', 'classic' ) ); |
| 549 | 586 | if ( ! $extract_templates ) { |
@@ -552,16 +589,19 @@ discard block |
||
| 552 | 589 | } |
| 553 | 590 | if ( $extract_templates ) { |
| 554 | 591 | $res = $potextmeta->append( $dir, $output, array( 'Template Name' ) ); |
| 555 | - if ( ! $res ) |
|
| 556 | - return false; |
|
| 592 | + if ( ! $res ) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 557 | 595 | $files = scandir( $dir ); |
| 558 | 596 | foreach ( $files as $file ) { |
| 559 | - if ( '.' == $file[0] || 'CVS' == $file ) |
|
| 560 | - continue; |
|
| 597 | + if ( '.' == $file[0] || 'CVS' == $file ) { |
|
| 598 | + continue; |
|
| 599 | + } |
|
| 561 | 600 | if ( is_dir( $dir . '/' . $file ) ) { |
| 562 | 601 | $res = $potextmeta->append( $dir . '/' . $file, $output, array( 'Template Name' ) ); |
| 563 | - if ( ! $res ) |
|
| 564 | - return false; |
|
| 602 | + if ( ! $res ) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 565 | 605 | } |
| 566 | 606 | } |
| 567 | 607 | } |
@@ -603,9 +643,10 @@ discard block |
||
| 603 | 643 | function is_ms_file( $file_name ) { |
| 604 | 644 | $is_ms_file = false; |
| 605 | 645 | $prefix = substr( $file_name, 0, 2 ) === './'? '\./' : ''; |
| 606 | - foreach( $this->ms_files as $ms_file ) |
|
| 607 | - if ( preg_match( '|^'.$prefix.$ms_file.'$|', $file_name ) ) { |
|
| 646 | + foreach( $this->ms_files as $ms_file ) { |
|
| 647 | + if ( preg_match( '|^'.$prefix.$ms_file.'$|', $file_name ) ) { |
|
| 608 | 648 | $is_ms_file = true; |
| 649 | + } |
|
| 609 | 650 | break; |
| 610 | 651 | } |
| 611 | 652 | return $is_ms_file; |
@@ -51,6 +51,9 @@ discard block |
||
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $dir |
|
| 56 | + */ |
|
| 54 | 57 | function list_php_files($dir) { |
| 55 | 58 | $files = array(); |
| 56 | 59 | $items = scandir( $dir ); |
@@ -67,16 +70,25 @@ discard block |
||
| 67 | 70 | } |
| 68 | 71 | |
| 69 | 72 | |
| 73 | + /** |
|
| 74 | + * @param string $global_array_name |
|
| 75 | + */ |
|
| 70 | 76 | function make_string_aggregator($global_array_name, $filename) { |
| 71 | 77 | $a = $global_array_name; |
| 72 | 78 | return create_function('$string, $comment_id, $line_number', 'global $'.$a.'; $'.$a.'[] = array($string, $comment_id, '.var_export($filename, true).', $line_number);'); |
| 73 | 79 | } |
| 74 | 80 | |
| 81 | + /** |
|
| 82 | + * @param string $global_mo_name |
|
| 83 | + */ |
|
| 75 | 84 | function make_mo_replacer($global_mo_name) { |
| 76 | 85 | $m = $global_mo_name; |
| 77 | 86 | return create_function('$token, $string', 'global $'.$m.'; return var_export($'.$m.'->translate($string), true);'); |
| 78 | 87 | } |
| 79 | 88 | |
| 89 | + /** |
|
| 90 | + * @param string $register_action |
|
| 91 | + */ |
|
| 80 | 92 | function walk_tokens(&$tokens, $string_action, $other_action, $register_action=null) { |
| 81 | 93 | |
| 82 | 94 | $current_comment_id = ''; |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | 10 | if ( ! defined( 'T_ML_COMMENT' ) ) |
| 11 | - define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 11 | + define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 12 | 12 | else |
| 13 | - define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 13 | + define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 14 | 14 | |
| 15 | 15 | $pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
| 16 | 16 | require_once "$pomo/po.php"; |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | * @subpackage tools |
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | -if ( ! defined( 'T_ML_COMMENT' ) ) |
|
| 11 | - define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 10 | +if ( ! defined('T_ML_COMMENT')) |
|
| 11 | + define('T_ML_COMMENT', T_COMMENT); |
|
| 12 | 12 | else |
| 13 | - define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 13 | + define('T_DOC_COMMENT', T_ML_COMMENT); |
|
| 14 | 14 | |
| 15 | -$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
|
| 15 | +$pomo = dirname(dirname(dirname(__FILE__))).'/src/wp-includes/pomo'; |
|
| 16 | 16 | require_once "$pomo/po.php"; |
| 17 | 17 | require_once "$pomo/mo.php"; |
| 18 | 18 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | var $STAGE_WHITESPACE_AFTER = 4; |
| 27 | 27 | var $STAGE_END_COMMENT = 4; |
| 28 | 28 | |
| 29 | - var $commands = array('extract' => 'command_extract', 'replace' => 'command_replace' ); |
|
| 29 | + var $commands = array('extract' => 'command_extract', 'replace' => 'command_replace'); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | function logmsg() { |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | if ($this->enable_logging) error_log(implode(' ', $args)); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - function stderr($msg, $nl=true) { |
|
| 38 | - fwrite(STDERR, $msg.($nl? "\n" : "")); |
|
| 37 | + function stderr($msg, $nl = true) { |
|
| 38 | + fwrite(STDERR, $msg.($nl ? "\n" : "")); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function cli_die($msg) { |
@@ -43,19 +43,19 @@ discard block |
||
| 43 | 43 | exit(1); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - function unchanged_token($token, $s='') { |
|
| 47 | - return is_array($token)? $token[1] : $token; |
|
| 46 | + function unchanged_token($token, $s = '') { |
|
| 47 | + return is_array($token) ? $token[1] : $token; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - function ignore_token($token, $s='') { |
|
| 50 | + function ignore_token($token, $s = '') { |
|
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function list_php_files($dir) { |
| 55 | 55 | $files = array(); |
| 56 | - $items = scandir( $dir ); |
|
| 57 | - foreach ( (array) $items as $item ) { |
|
| 58 | - $full_item = $dir . '/' . $item; |
|
| 56 | + $items = scandir($dir); |
|
| 57 | + foreach ((array) $items as $item) { |
|
| 58 | + $full_item = $dir.'/'.$item; |
|
| 59 | 59 | if ('.' == $item || '..' == $item) |
| 60 | 60 | continue; |
| 61 | 61 | if ('.php' == substr($item, -4)) |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | return create_function('$token, $string', 'global $'.$m.'; return var_export($'.$m.'->translate($string), true);'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - function walk_tokens(&$tokens, $string_action, $other_action, $register_action=null) { |
|
| 80 | + function walk_tokens(&$tokens, $string_action, $other_action, $register_action = null) { |
|
| 81 | 81 | |
| 82 | 82 | $current_comment_id = ''; |
| 83 | 83 | $current_string = ''; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $result = ''; |
| 87 | 87 | $line = 1; |
| 88 | 88 | |
| 89 | - foreach($tokens as $token) { |
|
| 89 | + foreach ($tokens as $token) { |
|
| 90 | 90 | if (is_array($token)) { |
| 91 | 91 | list($id, $text) = $token; |
| 92 | 92 | $line += substr_count($text, "\n"); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $stage = $this->STAGE_END_COMMENT; |
| 103 | 103 | $this->logmsg('end comment', $current_comment_id); |
| 104 | 104 | $result .= call_user_func($other_action, $token); |
| 105 | - if (!is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 105 | + if ( ! is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 106 | 106 | continue; |
| 107 | 107 | } |
| 108 | 108 | } else if (T_CONSTANT_ENCAPSED_STRING == $id) { |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | $global_name = '__entries_'.mt_rand(1, 1000); |
| 150 | 150 | $GLOBALS[$global_name] = array(); |
| 151 | 151 | |
| 152 | - foreach($filenames as $filename) { |
|
| 152 | + foreach ($filenames as $filename) { |
|
| 153 | 153 | $tokens = token_get_all(file_get_contents($filename)); |
| 154 | 154 | $aggregator = $this->make_string_aggregator($global_name, $filename); |
| 155 | 155 | $this->walk_tokens($tokens, array($this, 'ignore_token'), array($this, 'ignore_token'), $aggregator); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $potf = '-' == $pot_filename? STDOUT : @fopen($pot_filename, 'a'); |
|
| 158 | + $potf = '-' == $pot_filename ? STDOUT : @fopen($pot_filename, 'a'); |
|
| 159 | 159 | if (false === $potf) { |
| 160 | 160 | $this->cli_die("Couldn't open pot file: $pot_filename"); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - foreach($GLOBALS[$global_name] as $item) { |
|
| 163 | + foreach ($GLOBALS[$global_name] as $item) { |
|
| 164 | 164 | @list($string, $comment_id, $filename, $line_number) = $item; |
| 165 | - $filename = isset($filename)? preg_replace('|^\./|', '', $filename) : ''; |
|
| 166 | - $ref_line_number = isset($line_number)? ":$line_number" : ''; |
|
| 165 | + $filename = isset($filename) ? preg_replace('|^\./|', '', $filename) : ''; |
|
| 166 | + $ref_line_number = isset($line_number) ? ":$line_number" : ''; |
|
| 167 | 167 | $args = array( |
| 168 | 168 | 'singular' => $string, |
| 169 | 169 | 'extracted_comments' => "Not gettexted string $comment_id", |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | if (false === $res) { |
| 193 | 193 | $this->cli_die("Couldn't read MO file '$mo_filename'!"); |
| 194 | 194 | } |
| 195 | - foreach($filenames as $filename) { |
|
| 195 | + foreach ($filenames as $filename) { |
|
| 196 | 196 | $source = file_get_contents($filename); |
| 197 | - if ( strlen($source) > 150000 ) continue; |
|
| 197 | + if (strlen($source) > 150000) continue; |
|
| 198 | 198 | $tokens = token_get_all($source); |
| 199 | 199 | $new_file = $this->walk_tokens($tokens, $replacer, array($this, 'unchanged_token')); |
| 200 | 200 | $f = fopen($filename, 'w'); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | function cli() { |
| 216 | 216 | global $argv, $commands; |
| 217 | - if (count($argv) < 4 || !in_array($argv[1], array_keys($this->commands))) { |
|
| 217 | + if (count($argv) < 4 || ! in_array($argv[1], array_keys($this->commands))) { |
|
| 218 | 218 | $this->usage(); |
| 219 | 219 | exit(1); |
| 220 | 220 | } |
@@ -7,10 +7,11 @@ discard block |
||
| 7 | 7 | * @subpackage tools |
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | -if ( ! defined( 'T_ML_COMMENT' ) ) |
|
| 10 | +if ( ! defined( 'T_ML_COMMENT' ) ) { |
|
| 11 | 11 | define( 'T_ML_COMMENT', T_COMMENT ); |
| 12 | -else |
|
| 12 | +} else { |
|
| 13 | 13 | define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
| 14 | +} |
|
| 14 | 15 | |
| 15 | 16 | $pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
| 16 | 17 | require_once "$pomo/po.php"; |
@@ -31,7 +32,9 @@ discard block |
||
| 31 | 32 | |
| 32 | 33 | function logmsg() { |
| 33 | 34 | $args = func_get_args(); |
| 34 | - if ($this->enable_logging) error_log(implode(' ', $args)); |
|
| 35 | + if ($this->enable_logging) { |
|
| 36 | + error_log(implode(' ', $args)); |
|
| 37 | + } |
|
| 35 | 38 | } |
| 36 | 39 | |
| 37 | 40 | function stderr($msg, $nl=true) { |
@@ -56,12 +59,15 @@ discard block |
||
| 56 | 59 | $items = scandir( $dir ); |
| 57 | 60 | foreach ( (array) $items as $item ) { |
| 58 | 61 | $full_item = $dir . '/' . $item; |
| 59 | - if ('.' == $item || '..' == $item) |
|
| 60 | - continue; |
|
| 61 | - if ('.php' == substr($item, -4)) |
|
| 62 | - $files[] = $full_item; |
|
| 63 | - if (is_dir($full_item)) |
|
| 64 | - $files += array_merge($files, NotGettexted::list_php_files($full_item, $files)); |
|
| 62 | + if ('.' == $item || '..' == $item) { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + if ('.php' == substr($item, -4)) { |
|
| 66 | + $files[] = $full_item; |
|
| 67 | + } |
|
| 68 | + if (is_dir($full_item)) { |
|
| 69 | + $files += array_merge($files, NotGettexted::list_php_files($full_item, $files)); |
|
| 70 | + } |
|
| 65 | 71 | } |
| 66 | 72 | return $files; |
| 67 | 73 | } |
@@ -102,7 +108,9 @@ discard block |
||
| 102 | 108 | $stage = $this->STAGE_END_COMMENT; |
| 103 | 109 | $this->logmsg('end comment', $current_comment_id); |
| 104 | 110 | $result .= call_user_func($other_action, $token); |
| 105 | - if (!is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 111 | + if (!is_null($register_action)) { |
|
| 112 | + call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 113 | + } |
|
| 106 | 114 | continue; |
| 107 | 115 | } |
| 108 | 116 | } else if (T_CONSTANT_ENCAPSED_STRING == $id) { |
@@ -141,10 +149,11 @@ discard block |
||
| 141 | 149 | function command_extract() { |
| 142 | 150 | $args = func_get_args(); |
| 143 | 151 | $pot_filename = $args[0]; |
| 144 | - if (isset($args[1]) && is_array($args[1])) |
|
| 145 | - $filenames = $args[1]; |
|
| 146 | - else |
|
| 147 | - $filenames = array_slice($args, 1); |
|
| 152 | + if (isset($args[1]) && is_array($args[1])) { |
|
| 153 | + $filenames = $args[1]; |
|
| 154 | + } else { |
|
| 155 | + $filenames = array_slice($args, 1); |
|
| 156 | + } |
|
| 148 | 157 | |
| 149 | 158 | $global_name = '__entries_'.mt_rand(1, 1000); |
| 150 | 159 | $GLOBALS[$global_name] = array(); |
@@ -172,17 +181,20 @@ discard block |
||
| 172 | 181 | $entry = new Translation_Entry($args); |
| 173 | 182 | fwrite($potf, "\n".PO::export_entry($entry)."\n"); |
| 174 | 183 | } |
| 175 | - if ('-' != $pot_filename) fclose($potf); |
|
| 184 | + if ('-' != $pot_filename) { |
|
| 185 | + fclose($potf); |
|
| 186 | + } |
|
| 176 | 187 | return true; |
| 177 | 188 | } |
| 178 | 189 | |
| 179 | 190 | function command_replace() { |
| 180 | 191 | $args = func_get_args(); |
| 181 | 192 | $mo_filename = $args[0]; |
| 182 | - if (isset($args[1]) && is_array($args[1])) |
|
| 183 | - $filenames = $args[1]; |
|
| 184 | - else |
|
| 185 | - $filenames = array_slice($args, 1); |
|
| 193 | + if (isset($args[1]) && is_array($args[1])) { |
|
| 194 | + $filenames = $args[1]; |
|
| 195 | + } else { |
|
| 196 | + $filenames = array_slice($args, 1); |
|
| 197 | + } |
|
| 186 | 198 | |
| 187 | 199 | $global_name = '__mo_'.mt_rand(1, 1000); |
| 188 | 200 | $GLOBALS[$global_name] = new MO(); |
@@ -194,7 +206,9 @@ discard block |
||
| 194 | 206 | } |
| 195 | 207 | foreach($filenames as $filename) { |
| 196 | 208 | $source = file_get_contents($filename); |
| 197 | - if ( strlen($source) > 150000 ) continue; |
|
| 209 | + if ( strlen($source) > 150000 ) { |
|
| 210 | + continue; |
|
| 211 | + } |
|
| 198 | 212 | $tokens = token_get_all($source); |
| 199 | 213 | $new_file = $this->walk_tokens($tokens, $replacer, array($this, 'unchanged_token')); |
| 200 | 214 | $f = fopen($filename, 'w'); |