Changeset 42343 for trunk/src/wp-includes/theme.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/theme.php (modified) (95 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/theme.php
r41995 r42343 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( 34 'errors' => false, 35 'allowed' => null, 36 'blog_id' => 0, 37 ); 38 $args = wp_parse_args( $args, $defaults ); 35 39 36 40 $theme_directories = search_theme_directories(); … … 42 46 if ( isset( $theme_directories[ $current_theme ] ) ) { 43 47 $root_of_current_theme = get_raw_theme_root( $current_theme ); 44 if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) 48 if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) { 45 49 $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; 50 } 46 51 $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; 47 52 } 48 53 } 49 54 50 if ( empty( $theme_directories ) ) 55 if ( empty( $theme_directories ) ) { 51 56 return array(); 57 } 52 58 53 59 if ( is_multisite() && null !== $args['allowed'] ) { 54 60 $allowed = $args['allowed']; 55 if ( 'network' === $allowed ) 61 if ( 'network' === $allowed ) { 56 62 $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); 57 elseif ( 'site' === $allowed )63 } elseif ( 'site' === $allowed ) { 58 64 $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); 59 elseif ( $allowed )65 } elseif ( $allowed ) { 60 66 $theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); 61 else67 } else { 62 68 $theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); 63 } 64 65 $themes = array(); 69 } 70 } 71 72 $themes = array(); 66 73 static $_themes = array(); 67 74 68 75 foreach ( $theme_directories as $theme => $theme_root ) { 69 if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) 76 if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) { 70 77 $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; 71 else78 } else { 72 79 $themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); 80 } 73 81 } 74 82 75 83 if ( null !== $args['errors'] ) { 76 84 foreach ( $themes as $theme => $wp_theme ) { 77 if ( $wp_theme->errors() != $args['errors'] ) 85 if ( $wp_theme->errors() != $args['errors'] ) { 78 86 unset( $themes[ $theme ] ); 87 } 79 88 } 80 89 } … … 92 101 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme. 93 102 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() 94 * is used to calculate the theme root for the $stylesheet provided (or current theme).103 * is used to calculate the theme root for the $stylesheet provided (or current theme). 95 104 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence. 96 105 */ … … 98 107 global $wp_theme_directories; 99 108 100 if ( empty( $stylesheet ) ) 109 if ( empty( $stylesheet ) ) { 101 110 $stylesheet = get_stylesheet(); 111 } 102 112 103 113 if ( empty( $theme_root ) ) { 104 114 $theme_root = get_raw_theme_root( $stylesheet ); 105 if ( false === $theme_root ) 115 if ( false === $theme_root ) { 106 116 $theme_root = WP_CONTENT_DIR . '/themes'; 107 elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) )117 } elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { 108 118 $theme_root = WP_CONTENT_DIR . $theme_root; 119 } 109 120 } 110 121 … … 119 130 */ 120 131 function wp_clean_themes_cache( $clear_update_cache = true ) { 121 if ( $clear_update_cache ) 132 if ( $clear_update_cache ) { 122 133 delete_site_transient( 'update_themes' ); 134 } 123 135 search_theme_directories( true ); 124 foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) 136 foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) { 125 137 $theme->cache_delete(); 138 } 126 139 } 127 140 … … 132 145 * 133 146 * @return bool true if a child theme is in use, false otherwise. 134 * */147 */ 135 148 function is_child_theme() { 136 149 return ( TEMPLATEPATH !== STYLESHEETPATH ); … … 169 182 */ 170 183 function get_stylesheet_directory() { 171 $stylesheet = get_stylesheet();172 $theme_root = get_theme_root( $stylesheet );184 $stylesheet = get_stylesheet(); 185 $theme_root = get_theme_root( $stylesheet ); 173 186 $stylesheet_dir = "$theme_root/$stylesheet"; 174 187 … … 193 206 */ 194 207 function get_stylesheet_directory_uri() { 195 $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );196 $theme_root_uri = get_theme_root_uri( $stylesheet );208 $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); 209 $theme_root_uri = get_theme_root_uri( $stylesheet ); 197 210 $stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; 198 211 … … 221 234 function get_stylesheet_uri() { 222 235 $stylesheet_dir_uri = get_stylesheet_directory_uri(); 223 $stylesheet_uri = $stylesheet_dir_uri . '/style.css';236 $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; 224 237 /** 225 238 * Filters the URI of the current theme stylesheet. … … 257 270 global $wp_locale; 258 271 $stylesheet_dir_uri = get_stylesheet_directory_uri(); 259 $dir = get_stylesheet_directory();260 $locale = get_locale();261 if ( file_exists( "$dir/$locale.css") )272 $dir = get_stylesheet_directory(); 273 $locale = get_locale(); 274 if ( file_exists( "$dir/$locale.css" ) ) { 262 275 $stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; 263 elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )276 } elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) { 264 277 $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; 265 else278 } else { 266 279 $stylesheet_uri = ''; 280 } 267 281 /** 268 282 * Filters the localized stylesheet URI. … … 302 316 */ 303 317 function get_template_directory() { 304 $template = get_template();305 $theme_root = get_theme_root( $template );318 $template = get_template(); 319 $theme_root = get_theme_root( $template ); 306 320 $template_dir = "$theme_root/$template"; 307 321 … … 326 340 */ 327 341 function get_template_directory_uri() { 328 $template = str_replace( '%2F', '/', rawurlencode( get_template() ) );329 $theme_root_uri = get_theme_root_uri( $template );342 $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); 343 $theme_root_uri = get_theme_root_uri( $template ); 330 344 $template_dir_uri = "$theme_root_uri/$template"; 331 345 … … 354 368 global $wp_theme_directories; 355 369 356 if ( count( $wp_theme_directories) <= 1 )370 if ( count( $wp_theme_directories ) <= 1 ) { 357 371 return '/themes'; 372 } 358 373 359 374 $theme_roots = get_site_transient( 'theme_roots' ); … … 414 429 static $found_themes = null; 415 430 416 if ( empty( $wp_theme_directories ) ) 431 if ( empty( $wp_theme_directories ) ) { 417 432 return false; 418 419 if ( ! $force && isset( $found_themes ) ) 433 } 434 435 if ( ! $force && isset( $found_themes ) ) { 420 436 return $found_themes; 437 } 421 438 422 439 $found_themes = array(); … … 429 446 // to use in get_theme_root(). 430 447 foreach ( $wp_theme_directories as $theme_root ) { 431 if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) 448 if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { 432 449 $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; 433 else450 } else { 434 451 $relative_theme_roots[ $theme_root ] = $theme_root; 452 } 435 453 } 436 454 … … 448 466 foreach ( $cached_roots as $theme_dir => $theme_root ) { 449 467 // A cached theme root is no longer around, so skip it. 450 if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) 468 if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) { 451 469 continue; 470 } 452 471 $found_themes[ $theme_dir ] = array( 453 472 'theme_file' => $theme_dir . '/style.css', … … 457 476 return $found_themes; 458 477 } 459 if ( ! is_int( $cache_expiration ) ) 478 if ( ! is_int( $cache_expiration ) ) { 460 479 $cache_expiration = 1800; // half hour 480 } 461 481 } else { 462 482 $cache_expiration = 1800; // half hour … … 473 493 } 474 494 foreach ( $dirs as $dir ) { 475 if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) 495 if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) { 476 496 continue; 497 } 477 498 if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { 478 499 // wp-content/themes/a-single-theme … … 492 513 } 493 514 foreach ( $sub_dirs as $sub_dir ) { 494 if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) 515 if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) { 495 516 continue; 496 if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) 517 } 518 if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) { 497 519 continue; 520 } 498 521 $found_themes[ $dir . '/' . $sub_dir ] = array( 499 522 'theme_file' => $dir . '/' . $sub_dir . '/style.css', 500 523 'theme_root' => $theme_root, 501 524 ); 502 $found_theme = true;525 $found_theme = true; 503 526 } 504 527 // Never mind the above, it's just a theme missing a style.css. 505 528 // Return it; WP_Theme will catch the error. 506 if ( ! $found_theme ) 529 if ( ! $found_theme ) { 507 530 $found_themes[ $dir ] = array( 508 531 'theme_file' => $dir . '/style.css', 509 532 'theme_root' => $theme_root, 510 533 ); 534 } 511 535 } 512 536 } … … 515 539 asort( $found_themes ); 516 540 517 $theme_roots = array();541 $theme_roots = array(); 518 542 $relative_theme_roots = array_flip( $relative_theme_roots ); 519 543 … … 522 546 } 523 547 524 if ( $theme_roots != get_site_transient( 'theme_roots' ) ) 548 if ( $theme_roots != get_site_transient( 'theme_roots' ) ) { 525 549 set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); 550 } 526 551 527 552 return $found_themes; … … 546 571 // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. 547 572 // This gives relative theme roots the benefit of the doubt when things go haywire. 548 if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) 573 if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) { 549 574 $theme_root = WP_CONTENT_DIR . $theme_root; 575 } 550 576 } else { 551 577 $theme_root = WP_CONTENT_DIR . '/themes'; … … 572 598 * 573 599 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. 574 * Default is to leverage the main theme root.600 * Default is to leverage the main theme root. 575 601 * @param string $theme_root Optional. The theme root for which calculations will be based, preventing 576 * the need for a get_raw_theme_root() call.602 * the need for a get_raw_theme_root() call. 577 603 * @return string Themes URI. 578 604 */ … … 580 606 global $wp_theme_directories; 581 607 582 if ( $stylesheet_or_template && ! $theme_root ) 608 if ( $stylesheet_or_template && ! $theme_root ) { 583 609 $theme_root = get_raw_theme_root( $stylesheet_or_template ); 610 } 584 611 585 612 if ( $stylesheet_or_template && $theme_root ) { 586 613 if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { 587 614 // Absolute path. Make an educated guess. YMMV -- but note the filter below. 588 if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) 615 if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { 589 616 $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); 590 elseif ( 0 === strpos( $theme_root, ABSPATH ) )617 } elseif ( 0 === strpos( $theme_root, ABSPATH ) ) { 591 618 $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); 592 elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) )619 } elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) { 593 620 $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); 594 else621 } else { 595 622 $theme_root_uri = $theme_root; 623 } 596 624 } else { 597 625 $theme_root_uri = content_url( $theme_root ); … … 636 664 // If requesting the root for the current theme, consult options to avoid calling get_theme_roots() 637 665 if ( ! $skip_cache ) { 638 if ( get_option('stylesheet') == $stylesheet_or_template ) 639 $theme_root = get_option('stylesheet_root'); 640 elseif ( get_option('template') == $stylesheet_or_template ) 641 $theme_root = get_option('template_root'); 642 } 643 644 if ( empty($theme_root) ) { 666 if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) { 667 $theme_root = get_option( 'stylesheet_root' ); 668 } elseif ( get_option( 'template' ) == $stylesheet_or_template ) { 669 $theme_root = get_option( 'template_root' ); 670 } 671 } 672 673 if ( empty( $theme_root ) ) { 645 674 $theme_roots = get_theme_roots(); 646 if ( !empty($theme_roots[$stylesheet_or_template]) ) 647 $theme_root = $theme_roots[$stylesheet_or_template]; 675 if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) { 676 $theme_root = $theme_roots[ $stylesheet_or_template ]; 677 } 648 678 } 649 679 … … 658 688 function locale_stylesheet() { 659 689 $stylesheet = get_locale_stylesheet_uri(); 660 if ( empty( $stylesheet) )690 if ( empty( $stylesheet ) ) { 661 691 return; 692 } 662 693 echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; 663 694 } … … 691 722 692 723 if ( is_array( $_sidebars_widgets ) ) { 693 set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); 724 set_theme_mod( 725 'sidebars_widgets', array( 726 'time' => time(), 727 'data' => $_sidebars_widgets, 728 ) 729 ); 694 730 } 695 731 … … 716 752 } 717 753 718 $new_name = $new_theme->get('Name');754 $new_name = $new_theme->get( 'Name' ); 719 755 720 756 update_option( 'current_theme', $new_name ); … … 776 812 * @param bool $validate Whether to validate the current theme. Default true. 777 813 */ 778 if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) 814 if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) { 779 815 return true; 816 } 780 817 781 818 if ( ! file_exists( get_template_directory() . '/index.php' ) ) { … … 823 860 function get_theme_mods() { 824 861 $theme_slug = get_option( 'stylesheet' ); 825 $mods = get_option( "theme_mods_$theme_slug" );862 $mods = get_option( "theme_mods_$theme_slug" ); 826 863 if ( false === $mods ) { 827 864 $theme_name = get_option( 'current_theme' ); 828 if ( false === $theme_name ) 829 $theme_name = wp_get_theme()->get('Name'); 865 if ( false === $theme_name ) { 866 $theme_name = wp_get_theme()->get( 'Name' ); 867 } 830 868 $mods = get_option( "mods_$theme_name" ); // Deprecated location. 831 869 if ( is_admin() && false !== $mods ) { … … 854 892 $mods = get_theme_mods(); 855 893 856 if ( isset( $mods[ $name] ) ) {894 if ( isset( $mods[ $name ] ) ) { 857 895 /** 858 896 * Filters the theme modification, or 'theme_mod', value. … … 867 905 * @param string $current_mod The value of the current theme modification. 868 906 */ 869 return apply_filters( "theme_mod_{$name}", $mods[ $name] );870 } 871 872 if ( is_string( $default ) ) 907 return apply_filters( "theme_mod_{$name}", $mods[ $name ] ); 908 } 909 910 if ( is_string( $default ) ) { 873 911 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 912 } 874 913 875 914 /** This filter is documented in wp-includes/theme.php */ … … 886 925 */ 887 926 function set_theme_mod( $name, $value ) { 888 $mods = get_theme_mods();927 $mods = get_theme_mods(); 889 928 $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; 890 929 … … 920 959 $mods = get_theme_mods(); 921 960 922 if ( ! isset( $mods[ $name ] ) ) 961 if ( ! isset( $mods[ $name ] ) ) { 923 962 return; 963 } 924 964 925 965 unset( $mods[ $name ] ); … … 943 983 // Old style. 944 984 $theme_name = get_option( 'current_theme' ); 945 if ( false === $theme_name ) 946 $theme_name = wp_get_theme()->get('Name'); 985 if ( false === $theme_name ) { 986 $theme_name = wp_get_theme()->get( 'Name' ); 987 } 947 988 delete_option( 'mods_' . $theme_name ); 948 989 } … … 956 997 */ 957 998 function get_header_textcolor() { 958 return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );999 return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); 959 1000 } 960 1001 … … 976 1017 */ 977 1018 function display_header_text() { 978 if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) 1019 if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { 979 1020 return false; 1021 } 980 1022 981 1023 $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); … … 1006 1048 $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); 1007 1049 1008 if ( 'remove-header' == $url ) 1050 if ( 'remove-header' == $url ) { 1009 1051 return false; 1010 1011 if ( is_random_header_image() ) 1052 } 1053 1054 if ( is_random_header_image() ) { 1012 1055 $url = get_random_header_image(); 1056 } 1013 1057 1014 1058 return esc_url_raw( set_url_scheme( $url ) ); … … 1025 1069 */ 1026 1070 function get_header_image_tag( $attr = array() ) { 1027 $header = get_custom_header();1071 $header = get_custom_header(); 1028 1072 $header->url = get_header_image(); 1029 1073 … … 1032 1076 } 1033 1077 1034 $width = absint( $header->width );1078 $width = absint( $header->width ); 1035 1079 $height = absint( $header->height ); 1036 1080 … … 1038 1082 $attr, 1039 1083 array( 1040 'src' => $header->url,1041 'width' => $width,1084 'src' => $header->url, 1085 'width' => $width, 1042 1086 'height' => $height, 1043 'alt' => get_bloginfo( 'name' ),1087 'alt' => get_bloginfo( 'name' ), 1044 1088 ) 1045 1089 ); … … 1052 1096 if ( is_array( $image_meta ) ) { 1053 1097 $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); 1054 $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id );1098 $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); 1055 1099 1056 1100 if ( $srcset && $sizes ) { 1057 1101 $attr['srcset'] = $srcset; 1058 $attr['sizes'] = $sizes;1102 $attr['sizes'] = $sizes; 1059 1103 } 1060 1104 } … … 1111 1155 global $_wp_default_headers; 1112 1156 $header_image_mod = get_theme_mod( 'header_image', '' ); 1113 $headers = array();1114 1115 if ( 'random-uploaded-image' == $header_image_mod ) 1157 $headers = array(); 1158 1159 if ( 'random-uploaded-image' == $header_image_mod ) { 1116 1160 $headers = get_uploaded_header_images(); 1117 elseif ( ! empty( $_wp_default_headers ) ) {1161 } elseif ( ! empty( $_wp_default_headers ) ) { 1118 1162 if ( 'random-default-image' == $header_image_mod ) { 1119 1163 $headers = $_wp_default_headers; 1120 1164 } else { 1121 if ( current_theme_supports( 'custom-header', 'random-default' ) ) 1165 if ( current_theme_supports( 'custom-header', 'random-default' ) ) { 1122 1166 $headers = $_wp_default_headers; 1123 } 1124 } 1125 1126 if ( empty( $headers ) ) 1167 } 1168 } 1169 } 1170 1171 if ( empty( $headers ) ) { 1127 1172 return new stdClass; 1173 } 1128 1174 1129 1175 $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; 1130 1176 1131 $_wp_random_header->url =sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() );1132 $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() );1177 $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); 1178 $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); 1133 1179 } 1134 1180 return $_wp_random_header; … … 1144 1190 function get_random_header_image() { 1145 1191 $random_image = _get_random_header_data(); 1146 if ( empty( $random_image->url ) ) 1192 if ( empty( $random_image->url ) ) { 1147 1193 return ''; 1194 } 1148 1195 return $random_image->url; 1149 1196 } … … 1165 1212 1166 1213 if ( 'any' == $type ) { 1167 if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) 1214 if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) { 1168 1215 return true; 1216 } 1169 1217 } else { 1170 if ( "random-$type-image" == $header_image_mod ) 1218 if ( "random-$type-image" == $header_image_mod ) { 1171 1219 return true; 1172 elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() )1220 } elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) { 1173 1221 return true; 1222 } 1174 1223 } 1175 1224 … … 1200 1249 1201 1250 // @todo caching 1202 $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); 1203 1204 if ( empty( $headers ) ) 1251 $headers = get_posts( 1252 array( 1253 'post_type' => 'attachment', 1254 'meta_key' => '_wp_attachment_is_custom_header', 1255 'meta_value' => get_option( 'stylesheet' ), 1256 'orderby' => 'none', 1257 'nopaging' => true, 1258 ) 1259 ); 1260 1261 if ( empty( $headers ) ) { 1205 1262 return array(); 1263 } 1206 1264 1207 1265 foreach ( (array) $headers as $header ) { 1208 $url = esc_url_raw( wp_get_attachment_url( $header->ID ) );1209 $header_data = wp_get_attachment_metadata( $header->ID );1266 $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); 1267 $header_data = wp_get_attachment_metadata( $header->ID ); 1210 1268 $header_index = $header->ID; 1211 1269 1212 $header_images[$header_index] = array(); 1213 $header_images[$header_index]['attachment_id'] = $header->ID; 1214 $header_images[$header_index]['url'] = $url; 1215 $header_images[$header_index]['thumbnail_url'] = $url; 1216 $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); 1217 $header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : ''; 1218 1219 if ( isset( $header_data['width'] ) ) 1220 $header_images[$header_index]['width'] = $header_data['width']; 1221 if ( isset( $header_data['height'] ) ) 1222 $header_images[$header_index]['height'] = $header_data['height']; 1270 $header_images[ $header_index ] = array(); 1271 $header_images[ $header_index ]['attachment_id'] = $header->ID; 1272 $header_images[ $header_index ]['url'] = $url; 1273 $header_images[ $header_index ]['thumbnail_url'] = $url; 1274 $header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); 1275 $header_images[ $header_index ]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : ''; 1276 1277 if ( isset( $header_data['width'] ) ) { 1278 $header_images[ $header_index ]['width'] = $header_data['width']; 1279 } 1280 if ( isset( $header_data['height'] ) ) { 1281 $header_images[ $header_index ]['height'] = $header_data['height']; 1282 } 1223 1283 } 1224 1284 … … 1244 1304 if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { 1245 1305 $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); 1246 $data = array();1247 $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args );1306 $data = array(); 1307 $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); 1248 1308 if ( ! empty( $_wp_default_headers ) ) { 1249 1309 foreach ( (array) $_wp_default_headers as $default_header ) { 1250 1310 $url = vsprintf( $default_header['url'], $directory_args ); 1251 1311 if ( $data['url'] == $url ) { 1252 $data = $default_header;1253 $data['url'] = $url;1312 $data = $default_header; 1313 $data['url'] = $url; 1254 1314 $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); 1255 1315 break; … … 1335 1395 */ 1336 1396 function get_header_video_url() { 1337 $id = absint( get_theme_mod( 'header_video' ) );1397 $id = absint( get_theme_mod( 'header_video' ) ); 1338 1398 $url = esc_url( get_theme_mod( 'external_header_video' ) ); 1339 1399 … … 1394 1454 'pause' => __( 'Pause' ), 1395 1455 'play' => __( 'Play' ), 1396 'pauseSpeak' => __( 'Video is paused.' ),1397 'playSpeak' => __( 'Video is playing.' ),1456 'pauseSpeak' => __( 'Video is paused.' ), 1457 'playSpeak' => __( 'Video is playing.' ), 1398 1458 ), 1399 1459 ); … … 1504 1564 */ 1505 1565 function get_background_image() { 1506 return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) );1566 return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) ); 1507 1567 } 1508 1568 … … 1524 1584 */ 1525 1585 function get_background_color() { 1526 return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) );1586 return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) ); 1527 1587 } 1528 1588 … … 1622 1682 function wp_custom_css_cb() { 1623 1683 $styles = wp_get_custom_css(); 1624 if ( $styles || is_customize_preview() ) : ?> 1684 if ( $styles || is_customize_preview() ) : 1685 ?> 1625 1686 <style type="text/css" id="wp-custom-css"> 1626 1687 <?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div > span` is not interpreted properly. ?> 1627 1688 </style> 1628 <?php endif; 1689 <?php 1690 endif; 1629 1691 } 1630 1692 … … 1665 1727 if ( ! $post && -1 !== $post_id ) { 1666 1728 $query = new WP_Query( $custom_css_query_vars ); 1667 $post = $query->post;1729 $post = $query->post; 1668 1730 /* 1669 1731 * Cache the lookup. See wp_update_custom_css_post(). … … 1674 1736 } else { 1675 1737 $query = new WP_Query( $custom_css_query_vars ); 1676 $post = $query->post;1738 $post = $query->post; 1677 1739 } 1678 1740 … … 1730 1792 */ 1731 1793 function wp_update_custom_css_post( $css, $args = array() ) { 1732 $args = wp_parse_args( $args, array( 1733 'preprocessed' => '', 1734 'stylesheet' => get_stylesheet(), 1735 ) ); 1794 $args = wp_parse_args( 1795 $args, array( 1796 'preprocessed' => '', 1797 'stylesheet' => get_stylesheet(), 1798 ) 1799 ); 1736 1800 1737 1801 $data = array( 1738 'css' => $css,1802 'css' => $css, 1739 1803 'preprocessed' => $args['preprocessed'], 1740 1804 ); … … 1776 1840 1777 1841 $post_data = array( 1778 'post_title' => $args['stylesheet'],1779 'post_name' => sanitize_title( $args['stylesheet'] ),1780 'post_type' => 'custom_css',1781 'post_status' => 'publish',1782 'post_content' => $data['css'],1842 'post_title' => $args['stylesheet'], 1843 'post_name' => sanitize_title( $args['stylesheet'] ), 1844 'post_type' => 'custom_css', 1845 'post_status' => 'publish', 1846 'post_content' => $data['css'], 1783 1847 'post_content_filtered' => $data['preprocessed'], 1784 1848 ); … … 1788 1852 if ( $post ) { 1789 1853 $post_data['ID'] = $post->ID; 1790 $r = wp_update_post( wp_slash( $post_data ), true );1854 $r = wp_update_post( wp_slash( $post_data ), true ); 1791 1855 } else { 1792 1856 $r = wp_insert_post( wp_slash( $post_data ), true ); … … 1830 1894 * 1831 1895 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. 1832 * Defaults to 'editor-style.css'1896 * Defaults to 'editor-style.css' 1833 1897 */ 1834 1898 function add_editor_style( $stylesheet = 'editor-style.css' ) { 1835 1899 add_theme_support( 'editor-style' ); 1836 1900 1837 if ( ! is_admin() ) 1901 if ( ! is_admin() ) { 1838 1902 return; 1903 } 1839 1904 1840 1905 global $editor_styles; … … 1842 1907 $stylesheet = (array) $stylesheet; 1843 1908 if ( is_rtl() ) { 1844 $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0]);1845 $stylesheet[] = $rtl_stylesheet;1909 $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); 1910 $stylesheet[] = $rtl_stylesheet; 1846 1911 } 1847 1912 … … 1859 1924 */ 1860 1925 function remove_editor_styles() { 1861 if ( ! current_theme_supports( 'editor-style' ) ) 1926 if ( ! current_theme_supports( 'editor-style' ) ) { 1862 1927 return false; 1928 } 1863 1929 _remove_theme_support( 'editor-style' ); 1864 if ( is_admin() ) 1930 if ( is_admin() ) { 1865 1931 $GLOBALS['editor_styles'] = array(); 1932 } 1866 1933 return true; 1867 1934 } … … 1883 1950 1884 1951 $editor_styles = array_unique( array_filter( $editor_styles ) ); 1885 $style_uri = get_stylesheet_directory_uri();1886 $style_dir = get_stylesheet_directory();1952 $style_uri = get_stylesheet_directory_uri(); 1953 $style_dir = get_stylesheet_directory(); 1887 1954 1888 1955 // Support externally referenced styles (like, say, fonts). … … 1939 2006 1940 2007 $core_content = array( 1941 'widgets' => array( 1942 'text_business_info' => array( 'text', array( 1943 'title' => _x( 'Find Us', 'Theme starter content' ), 1944 'text' => join( '', array( 1945 '<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n", 1946 _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", 1947 '<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n", 1948 _x( 'Monday—Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ) 1949 ) ), 1950 'filter' => true, 1951 'visual' => true, 1952 ) ), 1953 'text_about' => array( 'text', array( 1954 'title' => _x( 'About This Site', 'Theme starter content' ), 1955 'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), 1956 'filter' => true, 1957 'visual' => true, 1958 ) ), 1959 'archives' => array( 'archives', array( 1960 'title' => _x( 'Archives', 'Theme starter content' ), 1961 ) ), 1962 'calendar' => array( 'calendar', array( 1963 'title' => _x( 'Calendar', 'Theme starter content' ), 1964 ) ), 1965 'categories' => array( 'categories', array( 1966 'title' => _x( 'Categories', 'Theme starter content' ), 1967 ) ), 1968 'meta' => array( 'meta', array( 1969 'title' => _x( 'Meta', 'Theme starter content' ), 1970 ) ), 1971 'recent-comments' => array( 'recent-comments', array( 1972 'title' => _x( 'Recent Comments', 'Theme starter content' ), 1973 ) ), 1974 'recent-posts' => array( 'recent-posts', array( 1975 'title' => _x( 'Recent Posts', 'Theme starter content' ), 1976 ) ), 1977 'search' => array( 'search', array( 1978 'title' => _x( 'Search', 'Theme starter content' ), 1979 ) ), 2008 'widgets' => array( 2009 'text_business_info' => array( 2010 'text', 2011 array( 2012 'title' => _x( 'Find Us', 'Theme starter content' ), 2013 'text' => join( 2014 '', array( 2015 '<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n", 2016 _x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", 2017 '<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n", 2018 _x( 'Monday—Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ), 2019 ) 2020 ), 2021 'filter' => true, 2022 'visual' => true, 2023 ), 2024 ), 2025 'text_about' => array( 2026 'text', 2027 array( 2028 'title' => _x( 'About This Site', 'Theme starter content' ), 2029 'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), 2030 'filter' => true, 2031 'visual' => true, 2032 ), 2033 ), 2034 'archives' => array( 2035 'archives', 2036 array( 2037 'title' => _x( 'Archives', 'Theme starter content' ), 2038 ), 2039 ), 2040 'calendar' => array( 2041 'calendar', 2042 array( 2043 'title' => _x( 'Calendar', 'Theme starter content' ), 2044 ), 2045 ), 2046 'categories' => array( 2047 'categories', 2048 array( 2049 'title' => _x( 'Categories', 'Theme starter content' ), 2050 ), 2051 ), 2052 'meta' => array( 2053 'meta', 2054 array( 2055 'title' => _x( 'Meta', 'Theme starter content' ), 2056 ), 2057 ), 2058 'recent-comments' => array( 2059 'recent-comments', 2060 array( 2061 'title' => _x( 'Recent Comments', 'Theme starter content' ), 2062 ), 2063 ), 2064 'recent-posts' => array( 2065 'recent-posts', 2066 array( 2067 'title' => _x( 'Recent Posts', 'Theme starter content' ), 2068 ), 2069 ), 2070 'search' => array( 2071 'search', 2072 array( 2073 'title' => _x( 'Search', 'Theme starter content' ), 2074 ), 2075 ), 1980 2076 ), 1981 2077 'nav_menus' => array( 1982 'link_home' => array(1983 'type' => 'custom',2078 'link_home' => array( 2079 'type' => 'custom', 1984 2080 'title' => _x( 'Home', 'Theme starter content' ), 1985 'url' => home_url( '/' ),2081 'url' => home_url( '/' ), 1986 2082 ), 1987 'page_home' => array( // Deprecated in favor of link_home.1988 'type' => 'post_type',1989 'object' => 'page',2083 'page_home' => array( // Deprecated in favor of link_home. 2084 'type' => 'post_type', 2085 'object' => 'page', 1990 2086 'object_id' => '{{home}}', 1991 2087 ), 1992 'page_about' => array(1993 'type' => 'post_type',1994 'object' => 'page',2088 'page_about' => array( 2089 'type' => 'post_type', 2090 'object' => 'page', 1995 2091 'object_id' => '{{about}}', 1996 2092 ), 1997 'page_blog' => array(1998 'type' => 'post_type',1999 'object' => 'page',2093 'page_blog' => array( 2094 'type' => 'post_type', 2095 'object' => 'page', 2000 2096 'object_id' => '{{blog}}', 2001 2097 ), 2002 'page_news' => array(2003 'type' => 'post_type',2004 'object' => 'page',2098 'page_news' => array( 2099 'type' => 'post_type', 2100 'object' => 'page', 2005 2101 'object_id' => '{{news}}', 2006 2102 ), 2007 'page_contact' => array(2008 'type' => 'post_type',2009 'object' => 'page',2103 'page_contact' => array( 2104 'type' => 'post_type', 2105 'object' => 'page', 2010 2106 'object_id' => '{{contact}}', 2011 2107 ), 2012 2108 2013 'link_email' => array(2109 'link_email' => array( 2014 2110 'title' => _x( 'Email', 'Theme starter content' ), 2015 'url' => 'mailto:wordpress@example.com',2111 'url' => 'mailto:wordpress@example.com', 2016 2112 ), 2017 'link_facebook' => array(2113 'link_facebook' => array( 2018 2114 'title' => _x( 'Facebook', 'Theme starter content' ), 2019 'url' => 'https://www.facebook.com/wordpress',2115 'url' => 'https://www.facebook.com/wordpress', 2020 2116 ), 2021 2117 'link_foursquare' => array( 2022 2118 'title' => _x( 'Foursquare', 'Theme starter content' ), 2023 'url' => 'https://foursquare.com/',2119 'url' => 'https://foursquare.com/', 2024 2120 ), 2025 'link_github' => array(2121 'link_github' => array( 2026 2122 'title' => _x( 'GitHub', 'Theme starter content' ), 2027 'url' => 'https://github.com/wordpress/',2123 'url' => 'https://github.com/wordpress/', 2028 2124 ), 2029 'link_instagram' => array(2125 'link_instagram' => array( 2030 2126 'title' => _x( 'Instagram', 'Theme starter content' ), 2031 'url' => 'https://www.instagram.com/explore/tags/wordcamp/',2127 'url' => 'https://www.instagram.com/explore/tags/wordcamp/', 2032 2128 ), 2033 'link_linkedin' => array(2129 'link_linkedin' => array( 2034 2130 'title' => _x( 'LinkedIn', 'Theme starter content' ), 2035 'url' => 'https://www.linkedin.com/company/1089783',2131 'url' => 'https://www.linkedin.com/company/1089783', 2036 2132 ), 2037 'link_pinterest' => array(2133 'link_pinterest' => array( 2038 2134 'title' => _x( 'Pinterest', 'Theme starter content' ), 2039 'url' => 'https://www.pinterest.com/',2135 'url' => 'https://www.pinterest.com/', 2040 2136 ), 2041 'link_twitter' => array(2137 'link_twitter' => array( 2042 2138 'title' => _x( 'Twitter', 'Theme starter content' ), 2043 'url' => 'https://twitter.com/wordpress',2139 'url' => 'https://twitter.com/wordpress', 2044 2140 ), 2045 'link_yelp' => array(2141 'link_yelp' => array( 2046 2142 'title' => _x( 'Yelp', 'Theme starter content' ), 2047 'url' => 'https://www.yelp.com',2143 'url' => 'https://www.yelp.com', 2048 2144 ), 2049 'link_youtube' => array(2145 'link_youtube' => array( 2050 2146 'title' => _x( 'YouTube', 'Theme starter content' ), 2051 'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA',2147 'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA', 2052 2148 ), 2053 2149 ), 2054 'posts' => array(2055 'home' => array(2056 'post_type' => 'page',2057 'post_title' => _x( 'Home', 'Theme starter content' ),2150 'posts' => array( 2151 'home' => array( 2152 'post_type' => 'page', 2153 'post_title' => _x( 'Home', 'Theme starter content' ), 2058 2154 'post_content' => _x( 'Welcome to your site! This is your homepage, which is what most visitors will see when they come to your site for the first time.', 'Theme starter content' ), 2059 2155 ), 2060 'about' => array(2061 'post_type' => 'page',2062 'post_title' => _x( 'About', 'Theme starter content' ),2156 'about' => array( 2157 'post_type' => 'page', 2158 'post_title' => _x( 'About', 'Theme starter content' ), 2063 2159 'post_content' => _x( 'You might be an artist who would like to introduce yourself and your work here or maybe you’re a business with a mission to describe.', 'Theme starter content' ), 2064 2160 ), 2065 'contact' => array(2066 'post_type' => 'page',2067 'post_title' => _x( 'Contact', 'Theme starter content' ),2161 'contact' => array( 2162 'post_type' => 'page', 2163 'post_title' => _x( 'Contact', 'Theme starter content' ), 2068 2164 'post_content' => _x( 'This is a page with some basic contact information, such as an address and phone number. You might also try a plugin to add a contact form.', 'Theme starter content' ), 2069 2165 ), 2070 'blog' => array(2071 'post_type' => 'page',2166 'blog' => array( 2167 'post_type' => 'page', 2072 2168 'post_title' => _x( 'Blog', 'Theme starter content' ), 2073 2169 ), 2074 'news' => array(2075 'post_type' => 'page',2170 'news' => array( 2171 'post_type' => 'page', 2076 2172 'post_title' => _x( 'News', 'Theme starter content' ), 2077 2173 ), 2078 2174 2079 2175 'homepage-section' => array( 2080 'post_type' => 'page',2081 'post_title' => _x( 'A homepage section', 'Theme starter content' ),2176 'post_type' => 'page', 2177 'post_title' => _x( 'A homepage section', 'Theme starter content' ), 2082 2178 'post_content' => _x( 'This is an example of a homepage section. Homepage sections can be any page other than the homepage itself, including the page that shows your latest blog posts.', 'Theme starter content' ), 2083 2179 ), … … 2088 2184 2089 2185 foreach ( $config as $type => $args ) { 2090 switch ( $type ) {2186 switch ( $type ) { 2091 2187 // Use options and theme_mods as-is. 2092 case 'options' :2093 case 'theme_mods' :2188 case 'options': 2189 case 'theme_mods': 2094 2190 $content[ $type ] = $config[ $type ]; 2095 2191 break; 2096 2192 2097 2193 // Widgets are grouped into sidebars. 2098 case 'widgets' :2194 case 'widgets': 2099 2195 foreach ( $config[ $type ] as $sidebar_id => $widgets ) { 2100 2196 foreach ( $widgets as $id => $widget ) { … … 2118 2214 2119 2215 // And nav menu items are grouped into nav menus. 2120 case 'nav_menus' :2216 case 'nav_menus': 2121 2217 foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) { 2122 2218 … … 2145 2241 2146 2242 // Attachments are posts but have special treatment. 2147 case 'attachments' :2243 case 'attachments': 2148 2244 foreach ( $config[ $type ] as $id => $item ) { 2149 2245 if ( ! empty( $item['file'] ) ) { … … 2154 2250 2155 2251 // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work. 2156 case 'posts' :2252 case 'posts': 2157 2253 foreach ( $config[ $type ] as $id => $item ) { 2158 2254 if ( is_array( $item ) ) { … … 2222 2318 global $_wp_theme_features; 2223 2319 2224 if ( func_num_args() == 1 ) 2320 if ( func_num_args() == 1 ) { 2225 2321 $args = true; 2226 else2322 } else { 2227 2323 $args = array_slice( func_get_args(), 1 ); 2324 } 2228 2325 2229 2326 switch ( $feature ) { … … 2244 2341 break; 2245 2342 2246 case 'post-formats' :2343 case 'post-formats': 2247 2344 if ( is_array( $args[0] ) ) { 2248 2345 $post_formats = get_post_format_slugs(); … … 2253 2350 break; 2254 2351 2255 case 'html5' :2352 case 'html5': 2256 2353 // You can't just pass 'html5', you need to pass an array of types. 2257 2354 if ( empty( $args[0] ) ) { … … 2264 2361 2265 2362 // Calling 'html5' again merges, rather than overwrites. 2266 if ( isset( $_wp_theme_features['html5'] ) ) 2363 if ( isset( $_wp_theme_features['html5'] ) ) { 2267 2364 $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); 2365 } 2268 2366 break; 2269 2367 … … 2279 2377 'header-text' => '', 2280 2378 ); 2281 $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );2379 $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults ); 2282 2380 2283 2381 // Allow full flexibility if no size is specified. … … 2288 2386 break; 2289 2387 2290 case 'custom-header-uploads' :2388 case 'custom-header-uploads': 2291 2389 return add_theme_support( 'custom-header', array( 'uploads' => true ) ); 2292 2390 2293 case 'custom-header' :2294 if ( ! is_array( $args ) ) 2391 case 'custom-header': 2392 if ( ! is_array( $args ) ) { 2295 2393 $args = array( 0 => array() ); 2394 } 2296 2395 2297 2396 $defaults = array( 2298 'default-image' => '',2299 'random-default' => false,2300 'width' => 0,2301 'height' => 0,2302 'flex-height' => false,2303 'flex-width' => false,2304 'default-text-color' => '',2305 'header-text' => true,2306 'uploads' => true,2307 'wp-head-callback' => '',2308 'admin-head-callback' => '',2397 'default-image' => '', 2398 'random-default' => false, 2399 'width' => 0, 2400 'height' => 0, 2401 'flex-height' => false, 2402 'flex-width' => false, 2403 'default-text-color' => '', 2404 'header-text' => true, 2405 'uploads' => true, 2406 'wp-head-callback' => '', 2407 'admin-head-callback' => '', 2309 2408 'admin-preview-callback' => '', 2310 'video' => false,2311 'video-active-callback' => 'is_front_page',2409 'video' => false, 2410 'video-active-callback' => 'is_front_page', 2312 2411 ); 2313 2412 … … 2317 2416 // Merge in data from previous add_theme_support() calls. 2318 2417 // The first value registered wins. (A child theme is set up first.) 2319 if ( isset( $_wp_theme_features['custom-header'] ) ) 2418 if ( isset( $_wp_theme_features['custom-header'] ) ) { 2320 2419 $args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); 2420 } 2321 2421 2322 2422 // Load in the defaults at the end, as we need to insure first one wins. 2323 2423 // This will cause all constants to be defined, as each arg will then be set to the default. 2324 if ( $jit ) 2424 if ( $jit ) { 2325 2425 $args[0] = wp_parse_args( $args[0], $defaults ); 2426 } 2326 2427 2327 2428 // If a constant was defined, use that value. Otherwise, define the constant to ensure … … 2331 2432 // Constants are lame. Don't reference them. This is just for backward compatibility. 2332 2433 2333 if ( defined( 'NO_HEADER_TEXT' ) ) 2434 if ( defined( 'NO_HEADER_TEXT' ) ) { 2334 2435 $args[0]['header-text'] = ! NO_HEADER_TEXT; 2335 elseif ( isset( $args[0]['header-text'] ) )2436 } elseif ( isset( $args[0]['header-text'] ) ) { 2336 2437 define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); 2337 2338 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 2438 } 2439 2440 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) { 2339 2441 $args[0]['width'] = (int) HEADER_IMAGE_WIDTH; 2340 elseif ( isset( $args[0]['width'] ) )2442 } elseif ( isset( $args[0]['width'] ) ) { 2341 2443 define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); 2342 2343 if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) 2444 } 2445 2446 if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) { 2344 2447 $args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; 2345 elseif ( isset( $args[0]['height'] ) )2448 } elseif ( isset( $args[0]['height'] ) ) { 2346 2449 define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); 2347 2348 if ( defined( 'HEADER_TEXTCOLOR' ) ) 2450 } 2451 2452 if ( defined( 'HEADER_TEXTCOLOR' ) ) { 2349 2453 $args[0]['default-text-color'] = HEADER_TEXTCOLOR; 2350 elseif ( isset( $args[0]['default-text-color'] ) )2454 } elseif ( isset( $args[0]['default-text-color'] ) ) { 2351 2455 define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); 2352 2353 if ( defined( 'HEADER_IMAGE' ) ) 2456 } 2457 2458 if ( defined( 'HEADER_IMAGE' ) ) { 2354 2459 $args[0]['default-image'] = HEADER_IMAGE; 2355 elseif ( isset( $args[0]['default-image'] ) )2460 } elseif ( isset( $args[0]['default-image'] ) ) { 2356 2461 define( 'HEADER_IMAGE', $args[0]['default-image'] ); 2357 2358 if ( $jit && ! empty( $args[0]['default-image'] ) ) 2462 } 2463 2464 if ( $jit && ! empty( $args[0]['default-image'] ) ) { 2359 2465 $args[0]['random-default'] = false; 2466 } 2360 2467 2361 2468 // If headers are supported, and we still don't have a defined width or height, 2362 2469 // we have implicit flex sizes. 2363 2470 if ( $jit ) { 2364 if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) 2471 if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) { 2365 2472 $args[0]['flex-width'] = true; 2366 if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) 2473 } 2474 if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) { 2367 2475 $args[0]['flex-height'] = true; 2476 } 2368 2477 } 2369 2478 2370 2479 break; 2371 2480 2372 case 'custom-background' :2373 if ( ! is_array( $args ) ) 2481 case 'custom-background': 2482 if ( ! is_array( $args ) ) { 2374 2483 $args = array( 0 => array() ); 2484 } 2375 2485 2376 2486 $defaults = array( … … 2392 2502 2393 2503 // Merge in data from previous add_theme_support() calls. The first value registered wins. 2394 if ( isset( $_wp_theme_features['custom-background'] ) ) 2504 if ( isset( $_wp_theme_features['custom-background'] ) ) { 2395 2505 $args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); 2396 2397 if ( $jit ) 2506 } 2507 2508 if ( $jit ) { 2398 2509 $args[0] = wp_parse_args( $args[0], $defaults ); 2399 2400 if ( defined( 'BACKGROUND_COLOR' ) ) 2510 } 2511 2512 if ( defined( 'BACKGROUND_COLOR' ) ) { 2401 2513 $args[0]['default-color'] = BACKGROUND_COLOR; 2402 elseif ( isset( $args[0]['default-color'] ) || $jit )2514 } elseif ( isset( $args[0]['default-color'] ) || $jit ) { 2403 2515 define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); 2404 2405 if ( defined( 'BACKGROUND_IMAGE' ) ) 2516 } 2517 2518 if ( defined( 'BACKGROUND_IMAGE' ) ) { 2406 2519 $args[0]['default-image'] = BACKGROUND_IMAGE; 2407 elseif ( isset( $args[0]['default-image'] ) || $jit )2520 } elseif ( isset( $args[0]['default-image'] ) || $jit ) { 2408 2521 define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); 2522 } 2409 2523 2410 2524 break; 2411 2525 2412 2526 // Ensure that 'title-tag' is accessible in the admin. 2413 case 'title-tag' :2527 case 'title-tag': 2414 2528 // Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. 2415 2529 if ( did_action( 'wp_loaded' ) ) { 2416 2530 /* translators: 1: Theme support 2: hook name */ 2417 _doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( __( 'Theme support for %1$s should be registered before the %2$s hook.' ), 2418 '<code>title-tag</code>', '<code>wp_loaded</code>' ), '4.1.0' ); 2531 _doing_it_wrong( 2532 "add_theme_support( 'title-tag' )", sprintf( 2533 __( 'Theme support for %1$s should be registered before the %2$s hook.' ), 2534 '<code>title-tag</code>', '<code>wp_loaded</code>' 2535 ), '4.1.0' 2536 ); 2419 2537 2420 2538 return false; … … 2442 2560 2443 2561 $args = get_theme_support( 'custom-header' ); 2444 if ( $args[0]['wp-head-callback'] ) 2562 if ( $args[0]['wp-head-callback'] ) { 2445 2563 add_action( 'wp_head', $args[0]['wp-head-callback'] ); 2564 } 2446 2565 2447 2566 if ( is_admin() ) { … … 2501 2620 function get_theme_support( $feature ) { 2502 2621 global $_wp_theme_features; 2503 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 2622 if ( ! isset( $_wp_theme_features[ $feature ] ) ) { 2504 2623 return false; 2505 2506 if ( func_num_args() <= 1 ) 2624 } 2625 2626 if ( func_num_args() <= 1 ) { 2507 2627 return $_wp_theme_features[ $feature ]; 2628 } 2508 2629 2509 2630 $args = array_slice( func_get_args(), 1 ); 2510 2631 switch ( $feature ) { 2511 case 'custom-logo' :2512 case 'custom-header' :2513 case 'custom-background' :2514 if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) 2632 case 'custom-logo': 2633 case 'custom-header': 2634 case 'custom-background': 2635 if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) { 2515 2636 return $_wp_theme_features[ $feature ][0][ $args[0] ]; 2637 } 2516 2638 return false; 2517 2639 2518 default :2640 default: 2519 2641 return $_wp_theme_features[ $feature ]; 2520 2642 } … … 2534 2656 function remove_theme_support( $feature ) { 2535 2657 // Blacklist: for internal registrations not used directly by themes. 2536 if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) 2658 if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) { 2537 2659 return false; 2660 } 2538 2661 2539 2662 return _remove_theme_support( $feature ); … … 2556 2679 2557 2680 switch ( $feature ) { 2558 case 'custom-header-uploads' :2559 if ( ! isset( $_wp_theme_features['custom-header'] ) ) 2681 case 'custom-header-uploads': 2682 if ( ! isset( $_wp_theme_features['custom-header'] ) ) { 2560 2683 return false; 2684 } 2561 2685 add_theme_support( 'custom-header', array( 'uploads' => false ) ); 2562 2686 return; // Do not continue - custom-header-uploads no longer exists. 2563 2687 } 2564 2688 2565 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 2689 if ( ! isset( $_wp_theme_features[ $feature ] ) ) { 2566 2690 return false; 2691 } 2567 2692 2568 2693 switch ( $feature ) { 2569 case 'custom-header' :2570 if ( ! did_action( 'wp_loaded' ) ) 2694 case 'custom-header': 2695 if ( ! did_action( 'wp_loaded' ) ) { 2571 2696 break; 2697 } 2572 2698 $support = get_theme_support( 'custom-header' ); 2573 2699 if ( isset( $support[0]['wp-head-callback'] ) ) { … … 2580 2706 break; 2581 2707 2582 case 'custom-background' :2583 if ( ! did_action( 'wp_loaded' ) ) 2708 case 'custom-background': 2709 if ( ! did_action( 'wp_loaded' ) ) { 2584 2710 break; 2711 } 2585 2712 $support = get_theme_support( 'custom-background' ); 2586 2713 remove_action( 'wp_head', $support[0]['wp-head-callback'] ); … … 2607 2734 global $_wp_theme_features; 2608 2735 2609 if ( 'custom-header-uploads' == $feature ) 2736 if ( 'custom-header-uploads' == $feature ) { 2610 2737 return current_theme_supports( 'custom-header', 'uploads' ); 2611 2612 if ( !isset( $_wp_theme_features[$feature] ) ) 2738 } 2739 2740 if ( ! isset( $_wp_theme_features[ $feature ] ) ) { 2613 2741 return false; 2742 } 2614 2743 2615 2744 // If no args passed then no extra checks need be performed 2616 if ( func_num_args() <= 1 ) 2745 if ( func_num_args() <= 1 ) { 2617 2746 return true; 2747 } 2618 2748 2619 2749 $args = array_slice( func_get_args(), 1 ); … … 2624 2754 // an array of types to add_theme_support(). If no array was passed, then 2625 2755 // any type is accepted 2626 if ( true === $_wp_theme_features[ $feature] )// Registered for all types2756 if ( true === $_wp_theme_features[ $feature ] ) { // Registered for all types 2627 2757 return true; 2758 } 2628 2759 $content_type = $args[0]; 2629 return in_array( $content_type, $_wp_theme_features[ $feature][0] );2760 return in_array( $content_type, $_wp_theme_features[ $feature ][0] ); 2630 2761 2631 2762 case 'html5': … … 2637 2768 2638 2769 $type = $args[0]; 2639 return in_array( $type, $_wp_theme_features[ $feature][0] );2770 return in_array( $type, $_wp_theme_features[ $feature ][0] ); 2640 2771 2641 2772 case 'custom-logo': … … 2660 2791 * @param string $feature The theme feature. 2661 2792 */ 2662 return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature] );2793 return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); 2663 2794 } 2664 2795 … … 2674 2805 function require_if_theme_supports( $feature, $include ) { 2675 2806 if ( current_theme_supports( $feature ) ) { 2676 require ( $include );2807 require( $include ); 2677 2808 return true; 2678 2809 } … … 2773 2904 2774 2905 $is_customize_admin_page = ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ); 2775 $should_include = (2906 $should_include = ( 2776 2907 $is_customize_admin_page 2777 2908 || … … 2790 2921 * the values should contain any characters needing slashes anyway. 2791 2922 */ 2792 $keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );2923 $keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' ); 2793 2924 $input_vars = array_merge( 2794 2925 wp_array_slice_assoc( $_GET, $keys ), … … 2796 2927 ); 2797 2928 2798 $theme = null;2799 $changeset_uuid = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists.2929 $theme = null; 2930 $changeset_uuid = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists. 2800 2931 $messenger_channel = null; 2801 $autosaved = null;2802 $branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter.2932 $autosaved = null; 2933 $branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter. 2803 2934 2804 2935 if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) { … … 2837 2968 'customize_save' === wp_unslash( $_REQUEST['action'] ) 2838 2969 ); 2839 $settings_previewed = ! $is_customize_save_action;2970 $settings_previewed = ! $is_customize_save_action; 2840 2971 2841 2972 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; … … 2872 3003 if ( empty( $wp_customize ) ) { 2873 3004 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 2874 $wp_customize = new WP_Customize_Manager( array( 2875 'changeset_uuid' => $changeset_post->post_name, 2876 'settings_previewed' => false, 2877 ) ); 3005 $wp_customize = new WP_Customize_Manager( 3006 array( 3007 'changeset_uuid' => $changeset_post->post_name, 3008 'settings_previewed' => false, 3009 ) 3010 ); 2878 3011 } 2879 3012 … … 2899 3032 do_action( 'customize_register', $wp_customize ); 2900 3033 } 2901 $wp_customize->_publish_changeset_values( $changeset_post->ID ) ;3034 $wp_customize->_publish_changeset_values( $changeset_post->ID ); 2902 3035 2903 3036 /* … … 2947 3080 $admin_origin = parse_url( admin_url() ); 2948 3081 $home_origin = parse_url( home_url() ); 2949 $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host'] ) );3082 $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); 2950 3083 2951 3084 $browser = array( … … 2967 3100 2968 3101 $wp_scripts = wp_scripts(); 2969 $data = $wp_scripts->get_data( 'customize-loader', 'data' );2970 if ( $data ) 3102 $data = $wp_scripts->get_data( 'customize-loader', 'data' ); 3103 if ( $data ) { 2971 3104 $script = "$data\n$script"; 3105 } 2972 3106 2973 3107 $wp_scripts->add_data( 'customize-loader', 'data', $script ); … … 2980 3114 * 2981 3115 * @param string $stylesheet Optional. Theme to customize. Defaults to current theme. 2982 * The theme's stylesheet will be urlencoded if necessary.3116 * The theme's stylesheet will be urlencoded if necessary. 2983 3117 * @return string 2984 3118 */ 2985 3119 function wp_customize_url( $stylesheet = null ) { 2986 3120 $url = admin_url( 'customize.php' ); 2987 if ( $stylesheet ) 3121 if ( $stylesheet ) { 2988 3122 $url .= '?theme=' . urlencode( $stylesheet ); 3123 } 2989 3124 return esc_url( $url ); 2990 3125 } … … 3009 3144 $admin_origin = parse_url( admin_url() ); 3010 3145 $home_origin = parse_url( home_url() ); 3011 $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host'] ) );3146 $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); 3012 3147 3013 3148 ?>
Note: See TracChangeset
for help on using the changeset viewer.