Ticket #15926: 15926.2.patch
File 15926.2.patch, 33.2 KB (added by , 14 years ago) |
---|
-
wp-admin/custom-header.php
205 205 if ( isset($this->default_headers[$_POST['default-header']]) ) 206 206 set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url'])); 207 207 } 208 209 if ( isset($_POST['alt-text']) ) { 210 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options'); 211 $alt = preg_replace('/[^0-9a-zA-Z ]/', '', $_POST['alt-text']); 212 set_theme_mod('header_alt', $alt); 213 } 208 214 } 209 215 210 216 /** … … 456 462 <?php } ?> 457 463 </td> 458 464 </tr> 459 <?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?> 465 460 466 <tr valign="top"> 461 467 <th scope="row"><?php _e( 'Upload Image' ); ?></th> 462 468 <td> … … 468 474 <input type="file" id="upload" name="import" /> 469 475 <input type="hidden" name="action" value="save" /> 470 476 <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?> 471 < ?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>477 <input type="submit" class="button" value="<?php esc_attr_e( 'Upload' ); ?>" /> 472 478 </p> 473 479 </form> 474 480 </td> 475 481 </tr> 476 <?php endif; ?> 482 477 483 </tbody> 478 484 </table> 479 485 … … 484 490 <tr valign="top"> 485 491 <th scope="row"><?php _e( 'Default Images' ); ?></th> 486 492 <td> 487 <?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>488 493 <p><?php _e( 'If you don‘t want to upload your own image, you can use one of these cool headers.' ) ?></p> 489 <?php else: ?>490 <p><?php _e( 'You can use one of these cool headers.' ) ?>491 <?php endif; ?>492 494 <?php 493 495 $this->show_default_header_selector(); 494 496 ?> 495 497 </td> 496 498 </tr> 497 499 <?php endif; 500 if ( get_header_image() ) : 501 ?> 502 <tr valign="top"> 503 <th scope="row"><?php _e( 'Alternative Text' ); ?></th> 504 <td> 505 <fieldset> 506 <legend class="screen-reader-text"> 507 <span><?php _e( 'Alternative Text' ); ?></span> 508 </legend> 509 <input type="text" name="alt-text" id="alt-text" value="<?php echo esc_html(get_background_alt()) ?>" /> 510 </fieldset></td> 511 </tr> 498 512 499 if ( get_header_image() ) : ?>500 513 <tr valign="top"> 501 514 <th scope="row"><?php _e( 'Remove Image' ); ?></th> 502 515 <td> 503 516 <p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?></p> 504 < ?php submit_button( __( 'Remove Header Image' ), 'button', 'removeheader', false ); ?>517 <input type="submit" class="button" name="removeheader" value="<?php esc_attr_e( 'Remove Header Image' ); ?>" /> 505 518 </td> 506 519 </tr> 507 520 <?php endif; … … 511 524 <th scope="row"><?php _e( 'Reset Image' ); ?></th> 512 525 <td> 513 526 <p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></p> 514 < ?php submit_button( __( 'Restore Original Header Image' ), 'button', 'resetheader', false ); ?>527 <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e( 'Restore Original Header Image' ); ?>" /> 515 528 </td> 516 529 </tr> 517 530 <?php endif; ?> … … 550 563 <th scope="row"><?php _e('Reset Text Color'); ?></th> 551 564 <td> 552 565 <p><?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?></p> 553 < ?php submit_button( __( 'Restore Original Header Text' ), 'button', 'resettext', false ); ?>566 <input type="submit" class="button" name="resettext" value="<?php esc_attr_e( 'Restore Original Header Text' ); ?>" /> 554 567 </td> 555 568 </tr> 556 569 <?php } ?> … … 559 572 </table> 560 573 <?php endif; 561 574 562 do_action( 'custom_header_options' );563 564 575 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 565 566 <?php submit_button( null, 'primary', 'save-header-options' ); ?> 576 <p class="submit"><input type="submit" class="button-primary" name="save-header-options" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p> 567 577 </form> 568 578 </div> 569 579 … … 576 586 */ 577 587 function step_2() { 578 588 check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload'); 579 if ( ! current_theme_supports( 'custom-header-uploads' ) )580 wp_die( 'Cheatin’ uh?' );581 582 589 $overrides = array('test_form' => false); 583 590 $file = wp_handle_upload($_FILES['import'], $overrides); 584 591 … … 637 644 <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" /> 638 645 </div> 639 646 647 <p class="submit"> 640 648 <input type="hidden" name="x1" id="x1" value="0"/> 641 649 <input type="hidden" name="y1" id="y1" value="0"/> 642 650 <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/> … … 644 652 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 645 653 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 646 654 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 647 648 <?php submit_button( __( 'Crop and Publish' ) ); ?> 655 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Crop and Publish' ); ?>" /> 649 656 </p> 650 657 </form> 651 658 </div> … … 659 666 */ 660 667 function step_3() { 661 668 check_admin_referer('custom-header-crop-image'); 662 if ( ! current_theme_supports( 'custom-header-uploads' ) )663 wp_die( 'Cheatin’ uh?' );664 665 669 if ( $_POST['oitar'] > 1 ) { 666 670 $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; 667 671 $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; -
wp-content/themes/twentyten/header.php
72 72 ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && 73 73 $image[1] >= HEADER_IMAGE_WIDTH ) : 74 74 // Houston, we have a new header image! 75 echo get_the_post_thumbnail( $post->ID );76 else if ( get_header_image() ): ?>77 <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />75 echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); 76 else : ?> 77 <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="<?php header_alt(); ?>" /> 78 78 <?php endif; ?> 79 79 </div><!-- #branding --> 80 80 -
wp-includes/theme.php
166 166 * The description will have the tags filtered with the following HTML elements 167 167 * whitelisted. The <b>'a'</b> element with the <em>href</em> and <em>title</em> 168 168 * attributes. The <b>abbr</b> element with the <em>title</em> attribute. The 169 * <b>acronym< /b> element with the <em>title</em> attribute allowed. The169 * <b>acronym<b> element with the <em>title</em> attribute allowed. The 170 170 * <b>code</b>, <b>em</b>, and <b>strong</b> elements also allowed. 171 171 * 172 172 * The style.css file must contain theme name, theme URI, and description. The … … 239 239 if ( empty( $theme_data['AuthorURI'] ) ) { 240 240 $theme_data['Author'] = $theme_data['AuthorName']; 241 241 } else { 242 $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], esc_attr__( 'Visit author homepage' ), $theme_data['AuthorName'] );242 $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], __( 'Visit author homepage' ), $theme_data['AuthorName'] ); 243 243 } 244 244 } 245 245 … … 267 267 if ( isset($wp_themes) ) 268 268 return $wp_themes; 269 269 270 /* Register the default root as a theme directory */ 271 register_theme_directory( get_theme_root() ); 272 270 273 if ( !$theme_files = search_theme_directories() ) 271 274 return false; 272 275 … … 385 388 $template_files = array_unique($template_files); 386 389 $stylesheet_files = array_unique($stylesheet_files); 387 390 388 $template_dir = $template_directory;389 $stylesheet_dir = $theme_root . '/' . $stylesheet;391 $template_dir = dirname($template_files[0]); 392 $stylesheet_dir = dirname($stylesheet_files[0]); 390 393 391 394 if ( empty($template_dir) ) 392 395 $template_dir = '/'; … … 396 399 // Check for theme name collision. This occurs if a theme is copied to 397 400 // a new theme directory and the theme header is not updated. Whichever 398 401 // theme is first keeps the name. Subsequent themes get a suffix applied. 399 // The Twenty Ten,Default and Classic themes always trump their pretenders.402 // The Default and Classic themes always trump their pretenders. 400 403 if ( isset($wp_themes[$name]) ) { 401 $trump_cards = array( 402 'classic' => 'WordPress Classic', 403 'default' => 'WordPress Default', 404 'twentyten' => 'Twenty Ten', 405 ); 406 if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) { 404 if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) && 405 ('default' == $stylesheet || 'classic' == $stylesheet) ) { 407 406 // If another theme has claimed to be one of our default themes, move 408 407 // them aside. 409 408 $suffix = $wp_themes[$name]['Stylesheet']; … … 467 466 * 468 467 * @since 2.9.0 469 468 * 470 * @return array |string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.469 * @return array Theme roots 471 470 */ 472 471 function get_theme_roots() { 473 global $wp_theme_directories;474 475 if ( count($wp_theme_directories) <= 1 )476 return '/themes';477 478 472 $theme_roots = get_site_transient( 'theme_roots' ); 479 473 if ( false === $theme_roots ) { 480 474 get_themes(); … … 519 513 $theme_names = array_keys($themes); 520 514 $current_template = get_option('template'); 521 515 $current_stylesheet = get_option('stylesheet'); 522 $current_theme = ' Twenty Ten';516 $current_theme = 'WordPress Default'; 523 517 524 518 if ( $themes ) { 525 519 foreach ( (array) $theme_names as $theme_name ) { … … 594 588 595 589 while ( ($theme_dir = readdir($themes_dir)) !== false ) { 596 590 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { 597 if ( $theme_dir [0]== '.' || $theme_dir == 'CVS' )591 if ( $theme_dir{0} == '.' || $theme_dir == 'CVS' ) 598 592 continue; 599 593 600 594 $stylish_dir = @opendir($theme_root . '/' . $theme_dir); … … 617 611 $found_subdir_themes = false; 618 612 while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) { 619 613 if ( is_dir( $subdir . '/' . $theme_subdir) && is_readable($subdir . '/' . $theme_subdir) ) { 620 if ( $theme_subdir [0]== '.' || $theme_subdir == 'CVS' )614 if ( $theme_subdir{0} == '.' || $theme_subdir == 'CVS' ) 621 615 continue; 622 616 623 617 $stylish_dir = @opendir($subdir . '/' . $theme_subdir); … … 651 645 * Does not have trailing slash. 652 646 * 653 647 * @since 1.5.0 648 * @param $stylesheet_or_template The stylesheet or template name of the theme 654 649 * @uses apply_filters() Calls 'theme_root' filter on path. 655 650 * 656 * @param string $stylesheet_or_template The stylesheet or template name of the theme657 651 * @return string Theme path. 658 652 */ 659 653 function get_theme_root( $stylesheet_or_template = false ) { 660 if ( $stylesheet_or_template ) { 661 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) ) 662 $theme_root = WP_CONTENT_DIR . $theme_root; 654 if ($stylesheet_or_template) { 655 $theme_roots = get_theme_roots(); 656 657 if ( ! empty( $theme_roots[$stylesheet_or_template] ) ) 658 $theme_root = WP_CONTENT_DIR . $theme_roots[$stylesheet_or_template]; 663 659 else 664 660 $theme_root = WP_CONTENT_DIR . '/themes'; 665 661 } else { … … 675 671 * Does not have trailing slash. 676 672 * 677 673 * @since 1.5.0 674 * @param $stylesheet_or_template The stylesheet or template name of the theme 678 675 * 679 * @param string $stylesheet_or_template The stylesheet or template name of the theme680 676 * @return string Themes URI. 681 677 */ 682 678 function get_theme_root_uri( $stylesheet_or_template = false ) { 683 if ( $stylesheet_or_template ) { 684 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) ) 685 $theme_root_uri = content_url( $theme_root ); 686 else 687 $theme_root_uri = content_url( 'themes' ); 688 } else { 679 $theme_roots = get_theme_roots(); 680 681 if ( isset( $theme_roots[$stylesheet_or_template] ) && $theme_roots[$stylesheet_or_template] ) 682 $theme_root_uri = content_url( $theme_roots[$stylesheet_or_template] ); 683 else 689 684 $theme_root_uri = content_url( 'themes' ); 690 }691 685 692 686 return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template ); 693 687 } 694 688 695 689 /** 696 * Get the raw theme root relative to the content directory with no filters applied.690 * Retrieve path to file without the use of extension. 697 691 * 698 * @since 3.1.0 699 * 700 * @param string $stylesheet_or_template The stylesheet or template name of the theme 701 * @return string Theme root 702 */ 703 function get_raw_theme_root( $stylesheet_or_template, $no_cache = false ) { 704 global $wp_theme_directories; 705 706 if ( count($wp_theme_directories) <= 1 ) 707 return '/themes'; 708 709 $theme_root = false; 710 711 // If requesting the root for the current theme, consult options to avoid calling get_theme_roots() 712 if ( !$no_cache ) { 713 if ( get_option('stylesheet') == $stylesheet_or_template ) 714 $theme_root = get_option('stylesheet_root'); 715 elseif ( get_option('template') == $stylesheet_or_template ) 716 $theme_root = get_option('template_root'); 717 } 718 719 if ( empty($theme_root) ) { 720 $theme_roots = get_theme_roots(); 721 if ( !empty($theme_roots[$stylesheet_or_template]) ) 722 $theme_root = $theme_roots[$stylesheet_or_template]; 723 } 724 725 return $theme_root; 726 } 727 728 /** 729 * Retrieve path to a template 730 * 731 * Used to quickly retrieve the path of a template without including the file 732 * extension. It will also check the parent theme, if the file exists, with 733 * the use of {@link locate_template()}. Allows for more generic template location 692 * Used to quickly retrieve the path of file without including the file 693 * extension. It will also check the parent template, if the file exists, with 694 * the use of {@link locate_template()}. Allows for more generic file location 734 695 * without the use of the other get_*_template() functions. 735 696 * 697 * Can be used with include() or require() to retrieve path. 698 * <code> 699 * if( '' != get_query_template( '404' ) ) 700 * include( get_query_template( '404' ) ); 701 * </code> 702 * or the same can be accomplished with 703 * <code> 704 * if( '' != get_404_template() ) 705 * include( get_404_template() ); 706 * </code> 707 * 736 708 * @since 1.5.0 737 709 * 738 710 * @param string $type Filename without extension. 739 * @param array $templates An optional list of template candidates740 711 * @return string Full path to file. 741 712 */ 742 function get_query_template( $type, $templates = array()) {713 function get_query_template($type) { 743 714 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 744 745 if ( empty( $templates ) ) 746 $templates = array("{$type}.php"); 747 748 $templates = apply_filters( "{$type}_template_hierarchy", $templates ); 749 750 return apply_filters( "{$type}_template", locate_template( $templates ) ); 715 return apply_filters("{$type}_template", locate_template(array("{$type}.php"))); 751 716 } 752 717 753 718 /** … … 780 745 * @return string 781 746 */ 782 747 function get_archive_template() { 783 $post_type = get_query_var( 'post_type' ); 784 785 $templates = array(); 786 787 if ( $post_type ) 788 $templates[] = "archive-{$post_type}.php"; 789 $templates[] = 'archive.php'; 790 791 return get_query_template( 'archive', $templates ); 748 return get_query_template('archive'); 792 749 } 793 750 794 751 /** … … 799 756 * @return string 800 757 */ 801 758 function get_author_template() { 802 $author = get_queried_object(); 759 $author_id = absint( get_query_var( 'author' ) ); 760 $author = get_user_by( 'id', $author_id ); 761 $author = $author->user_nicename; 803 762 804 763 $templates = array(); 805 764 806 $templates[] = "author-{$author->user_nicename}.php"; 807 $templates[] = "author-{$author->ID}.php"; 765 if ( $author ) 766 $templates[] = "author-{$author}.php"; 767 if ( $author_id ) 768 $templates[] = "author-{$author_id}.php"; 808 769 $templates[] = 'author.php'; 809 770 810 return get_query_template( 'author', $templates ); 771 $template = locate_template( $templates ); 772 return apply_filters( 'author_template', $template ); 811 773 } 812 774 813 775 /** … … 823 785 * @return string 824 786 */ 825 787 function get_category_template() { 826 $category = get_queried_object(); 788 $cat_ID = absint( get_query_var('cat') ); 789 $category = get_category( $cat_ID ); 827 790 828 791 $templates = array(); 829 792 830 $templates[] = "category-{$category->slug}.php"; 831 $templates[] = "category-{$category->term_id}.php"; 793 if ( !is_wp_error($category) ) 794 $templates[] = "category-{$category->slug}.php"; 795 796 $templates[] = "category-$cat_ID.php"; 832 797 $templates[] = "category.php"; 833 798 834 return get_query_template( 'category', $templates ); 799 $template = locate_template($templates); 800 return apply_filters('category_template', $template); 835 801 } 836 802 837 803 /** … … 847 813 * @return string 848 814 */ 849 815 function get_tag_template() { 850 $tag = get_queried_object(); 816 $tag_id = absint( get_query_var('tag_id') ); 817 $tag_name = get_query_var('tag'); 851 818 852 819 $templates = array(); 853 820 854 $templates[] = "tag-{$tag->slug}.php"; 855 $templates[] = "tag-{$tag->term_id}.php"; 821 if ( $tag_name ) 822 $templates[] = "tag-$tag_name.php"; 823 if ( $tag_id ) 824 $templates[] = "tag-$tag_id.php"; 856 825 $templates[] = "tag.php"; 857 826 858 return get_query_template( 'tag', $templates ); 827 $template = locate_template($templates); 828 return apply_filters('tag_template', $template); 859 829 } 860 830 861 831 /** … … 870 840 * template is used. If none of the files exist, then it will fall back on to 871 841 * index.php. 872 842 * 873 * @since 2.5.0843 * @since unknown (2.6.0 most likely) 874 844 * @uses apply_filters() Calls 'taxonomy_template' filter on found path. 875 845 * 876 846 * @return string 877 847 */ 878 848 function get_taxonomy_template() { 879 $t erm = get_queried_object();880 $t axonomy = $term->taxonomy;849 $taxonomy = get_query_var('taxonomy'); 850 $term = get_query_var('term'); 881 851 882 852 $templates = array(); 853 if ( $taxonomy && $term ) 854 $templates[] = "taxonomy-$taxonomy-$term.php"; 855 if ( $taxonomy ) 856 $templates[] = "taxonomy-$taxonomy.php"; 883 857 884 $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";885 $templates[] = "taxonomy-$taxonomy.php";886 858 $templates[] = "taxonomy.php"; 887 859 888 return get_query_template( 'taxonomy', $templates ); 860 $template = locate_template($templates); 861 return apply_filters('taxonomy_template', $template); 889 862 } 890 863 891 864 /** … … 912 885 * @return string 913 886 */ 914 887 function get_home_template() { 915 $templates = array( 'home.php', 'index.php' ); 916 917 return get_query_template( 'home', $templates ); 888 $template = locate_template(array('home.php', 'index.php')); 889 return apply_filters('home_template', $template); 918 890 } 919 891 920 892 /** … … 928 900 * @return string 929 901 */ 930 902 function get_front_page_template() { 931 $templates = array('front-page.php'); 932 933 return get_query_template( 'front_page', $templates ); 903 return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) ); 934 904 } 935 905 936 906 /** … … 945 915 * @return string 946 916 */ 947 917 function get_page_template() { 948 $id = get_queried_object_id(); 918 global $wp_query; 919 920 $id = (int) $wp_query->get_queried_object_id(); 949 921 $template = get_post_meta($id, '_wp_page_template', true); 950 922 $pagename = get_query_var('pagename'); 951 923 952 924 if ( !$pagename && $id > 0 ) { 953 925 // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object 954 $post = get_queried_object();926 $post = $wp_query->get_queried_object(); 955 927 $pagename = $post->post_name; 956 928 } 957 929 … … 967 939 $templates[] = "page-$id.php"; 968 940 $templates[] = "page.php"; 969 941 970 return get_query_template( 'page', $templates);942 return apply_filters('page_template', locate_template($templates)); 971 943 } 972 944 973 945 /** … … 1000 972 * @return string 1001 973 */ 1002 974 function get_single_template() { 1003 $object = get_queried_object();975 global $wp_query; 1004 976 1005 $templates = array(); 1006 1007 $templates[] = "single-{$object->post_type}.php"; 1008 $templates[] = "single.php"; 1009 1010 return get_query_template( 'single', $templates ); 977 $object = $wp_query->get_queried_object(); 978 $templates = array('single-' . $object->post_type . '.php', 'single.php'); 979 return apply_filters('single_template', locate_template($templates)); 1011 980 } 1012 981 1013 982 /** … … 1050 1019 * @return string 1051 1020 */ 1052 1021 function get_comments_popup_template() { 1053 $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ));1022 $template = locate_template(array("comments-popup.php")); 1054 1023 1055 1024 // Backward compat code will be removed in a future release 1056 1025 if ('' == $template) 1057 1026 $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; 1058 1027 1059 return $template;1028 return apply_filters('comments_popup_template', $template); 1060 1029 } 1061 1030 1062 1031 /** … … 1067 1036 * 1068 1037 * @since 2.7.0 1069 1038 * 1070 * @param string|array $template_names Template file(s) to search for, inorder.1039 * @param array $template_names Array of template files to search for in priority order. 1071 1040 * @param bool $load If true the template file will be loaded if it is found. 1072 1041 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 1073 1042 * @return string The template filename if one is located. 1074 1043 */ 1075 1044 function locate_template($template_names, $load = false, $require_once = true ) { 1045 if ( !is_array($template_names) ) 1046 return ''; 1047 1076 1048 $located = ''; 1077 foreach ( (array)$template_names as $template_name ) {1049 foreach ( $template_names as $template_name ) { 1078 1050 if ( !$template_name ) 1079 1051 continue; 1080 1052 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { … … 1143 1115 if ( !current_user_can( 'switch_themes' ) ) 1144 1116 return; 1145 1117 1146 // Admin Thickbox requests1147 if ( isset( $_GET['preview_iframe'] ) )1148 show_admin_bar( false );1149 1150 1118 $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']); 1151 1119 1152 1120 if ( validate_file($_GET['template']) ) … … 1239 1207 /** 1240 1208 * Switches current theme to new template and stylesheet names. 1241 1209 * 1242 * @since 2.5.01210 * @since unknown 1243 1211 * @uses do_action() Calls 'switch_theme' action on updated theme display name. 1244 1212 * 1245 1213 * @param string $template Template name 1246 1214 * @param string $stylesheet Stylesheet name. 1247 1215 */ 1248 1216 function switch_theme($template, $stylesheet) { 1249 global $wp_theme_directories;1250 1251 1217 update_option('template', $template); 1252 1218 update_option('stylesheet', $stylesheet); 1253 if ( count($wp_theme_directories) > 1 ) {1254 update_option('template_root', get_raw_theme_root($template, true));1255 update_option('stylesheet_root', get_raw_theme_root($stylesheet, true));1256 }1257 1219 delete_option('current_theme'); 1258 1220 $theme = get_current_theme(); 1259 if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) {1260 $default_theme_mods = (array) get_option( "mods_$theme" );1261 add_option( "theme_mods_$stylesheet", $default_theme_mods );1262 }1263 1221 do_action('switch_theme', $theme); 1264 1222 } 1265 1223 … … 1291 1249 return false; 1292 1250 } 1293 1251 1294 if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {1295 switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );1296 return false;1297 }1298 1299 1252 return true; 1300 1253 } 1301 1254 1302 1255 /** 1303 * Retrieve all theme modifications.1304 *1305 * @since 3.1.01306 *1307 * @return array Theme modifications.1308 */1309 function get_theme_mods() {1310 $theme_slug = get_option( 'stylesheet' );1311 if ( false === ( $mods = get_option( "theme_mods_$theme_slug" ) ) ) {1312 $theme_name = get_current_theme();1313 $mods = get_option( "mods_$theme_name" ); // Deprecated location.1314 if ( is_admin() && false !== $mods ) {1315 update_option( "theme_mods_$theme_slug", $mods );1316 delete_option( "mods_$theme_name" );1317 }1318 }1319 return $mods;1320 }1321 1322 /**1323 1256 * Retrieve theme modification value for the current theme. 1324 1257 * 1325 1258 * If the modification name does not exist, then the $default will be passed … … 1334 1267 * @param bool|string $default 1335 1268 * @return string 1336 1269 */ 1337 function get_theme_mod( $name, $default = false) {1338 $ mods = get_theme_mods();1270 function get_theme_mod($name, $default = false) { 1271 $theme = get_current_theme(); 1339 1272 1340 if ( isset( $mods[ $name ] ) ) 1341 return apply_filters( "theme_mod_$name", $mods[ $name ] ); 1273 $mods = get_option( "mods_$theme" ); 1342 1274 1343 return apply_filters( "theme_mod_$name", sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ) ); 1275 if ( isset($mods[$name]) ) 1276 return apply_filters( "theme_mod_$name", $mods[$name] ); 1277 1278 return apply_filters( "theme_mod_$name", sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()) ); 1344 1279 } 1345 1280 1346 1281 /** … … 1351 1286 * @param string $name Theme modification name. 1352 1287 * @param string $value theme modification value. 1353 1288 */ 1354 function set_theme_mod( $name, $value) {1355 $ mods = get_theme_mods();1289 function set_theme_mod($name, $value) { 1290 $theme = get_current_theme(); 1356 1291 1357 $mods [ $name ] = $value;1292 $mods = get_option("mods_$theme"); 1358 1293 1359 $theme = get_option( 'stylesheet' ); 1360 update_option( "theme_mods_$theme", $mods ); 1294 $mods[$name] = $value; 1295 1296 update_option("mods_$theme", $mods); 1297 wp_cache_delete("mods_$theme", 'options'); 1361 1298 } 1362 1299 1363 1300 /** … … 1372 1309 * @return null 1373 1310 */ 1374 1311 function remove_theme_mod( $name ) { 1375 $ mods = get_theme_mods();1312 $theme = get_current_theme(); 1376 1313 1377 if ( ! isset( $mods[ $name ] ) ) 1314 $mods = get_option("mods_$theme"); 1315 1316 if ( !isset($mods[$name]) ) 1378 1317 return; 1379 1318 1380 unset( $mods[ $name ]);1319 unset($mods[$name]); 1381 1320 1382 if ( empty( $mods) )1321 if ( empty($mods) ) 1383 1322 return remove_theme_mods(); 1384 1323 1385 $theme = get_option( 'stylesheet');1386 update_option( "theme_mods_$theme", $mods);1324 update_option("mods_$theme", $mods); 1325 wp_cache_delete("mods_$theme", 'options'); 1387 1326 } 1388 1327 1389 1328 /** … … 1392 1331 * @since 2.1.0 1393 1332 */ 1394 1333 function remove_theme_mods() { 1395 delete_option( 'theme_mods_' . get_option( 'stylesheet' ) ); 1396 delete_option( 'mods_' . get_current_theme() ); 1334 $theme = get_current_theme(); 1335 1336 delete_option("mods_$theme"); 1397 1337 } 1398 1338 1399 1339 /** … … 1428 1368 * @return string 1429 1369 */ 1430 1370 function get_header_image() { 1431 $default = defined( 'HEADER_IMAGE') ? HEADER_IMAGE : '';1371 $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : ''; 1432 1372 1433 $url = get_theme_mod( 'header_image', $default ); 1434 1435 if ( is_ssl() ) 1436 $url = str_replace( 'http://', 'https://', $url ); 1437 else 1438 $url = str_replace( 'https://', 'http://', $url ); 1439 1440 return $url; 1373 return get_theme_mod('header_image', $default); 1441 1374 } 1442 1375 1443 1376 /** … … 1464 1397 * @param callback $admin_header_callback Call on custom header administration screen. 1465 1398 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional. 1466 1399 */ 1467 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '') {1468 if ( ! empty( $header_callback) )1400 function add_custom_image_header($header_callback, $admin_header_callback, $admin_image_div_callback = '') { 1401 if ( ! empty($header_callback) ) 1469 1402 add_action('wp_head', $header_callback); 1470 1403 1471 add_theme_support( 'custom-header', array( 'callback' => $header_callback ) ); 1472 add_theme_support( 'custom-header-uploads' ); 1404 add_theme_support( 'custom-header' ); 1473 1405 1474 1406 if ( ! is_admin() ) 1475 1407 return; 1476 1477 global $custom_image_header; 1478 1479 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1480 $custom_image_header = new Custom_Image_Header( $admin_header_callback, $admin_image_div_callback ); 1481 add_action( 'admin_menu', array( &$custom_image_header, 'init' ) ); 1408 require_once(ABSPATH . 'wp-admin/custom-header.php'); 1409 $GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback, $admin_image_div_callback); 1410 add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init')); 1482 1411 } 1483 1412 1484 1413 /** 1485 * Remove image header support.1486 *1487 * @since 3.1.01488 * @see add_custom_image_header()1489 *1490 * @return bool Whether support was removed.1491 */1492 function remove_custom_image_header() {1493 if ( ! current_theme_supports( 'custom-header' ) )1494 return false;1495 1496 $callback = get_theme_support( 'custom-header' );1497 remove_action( 'wp_head', $callback[0]['callback'] );1498 _remove_theme_support( 'custom-header' );1499 remove_theme_support( 'custom-header-uploads' );1500 1501 if ( is_admin() ) {1502 remove_action( 'admin_menu', array( &$GLOBALS['custom_image_header'], 'init' ) );1503 unset( $GLOBALS['custom_image_header'] );1504 }1505 1506 return true;1507 }1508 1509 /**1510 1414 * Register a selection of default headers to be displayed by the custom header admin UI. 1511 1415 * 1512 1416 * @since 3.0.0 … … 1528 1432 * @see register_default_headers() 1529 1433 * @since 3.0.0 1530 1434 * 1531 * @param string|array $headerThe header string id (key of array) to remove, or an array thereof.1435 * @param string|array The header string id (key of array) to remove, or an array thereof. 1532 1436 * @return True on success, false on failure. 1533 1437 */ 1534 1438 function unregister_default_headers( $header ) { … … 1566 1470 } 1567 1471 1568 1472 /** 1473 * Retrieve background image alt attribute for custom background. 1474 * 1475 * @uses HEADER_ALT 1476 * 1477 * @return string 1478 */ 1479 function get_header_alt() { 1480 $default = defined('HEADER_ALT') ? HEADER_ALT : ''; 1481 1482 return get_theme_mod('header_alt', $default); 1483 } 1484 1485 /** 1486 * Display background image alt attribute. 1487 * 1488 * 1489 */ 1490 function header_alt() { 1491 echo get_header_alt(); 1492 } 1493 1494 /** 1569 1495 * Retrieve value for custom background color. 1570 1496 * 1571 1497 * @since 3.0.0 … … 1603 1529 * @param callback $admin_header_callback Call on custom background administration screen. 1604 1530 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional. 1605 1531 */ 1606 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {1607 if ( isset( $GLOBALS['custom_background']) )1532 function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') { 1533 if ( isset($GLOBALS['custom_background']) ) 1608 1534 return; 1609 1535 1610 if ( empty( $header_callback) )1536 if ( empty($header_callback) ) 1611 1537 $header_callback = '_custom_background_cb'; 1612 1538 1613 add_action( 'wp_head', $header_callback);1539 add_action('wp_head', $header_callback); 1614 1540 1615 add_theme_support( 'custom-background' , array( 'callback' => $header_callback ));1541 add_theme_support( 'custom-background' ); 1616 1542 1617 1543 if ( ! is_admin() ) 1618 1544 return; 1619 require_once( ABSPATH . 'wp-admin/custom-background.php');1620 $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback);1621 add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ));1545 require_once(ABSPATH . 'wp-admin/custom-background.php'); 1546 $GLOBALS['custom_background'] =& new Custom_Background($admin_header_callback, $admin_image_div_callback); 1547 add_action('admin_menu', array(&$GLOBALS['custom_background'], 'init')); 1622 1548 } 1623 1549 1624 1550 /** 1625 * Remove custom background support.1626 *1627 * @since 3.1.01628 * @see add_custom_background()1629 *1630 * @return bool Whether support was removed.1631 */1632 function remove_custom_background() {1633 if ( ! current_theme_supports( 'custom-background' ) )1634 return false;1635 1636 $callback = get_theme_support( 'custom-background' );1637 remove_action( 'wp_head', $callback[0]['callback'] );1638 _remove_theme_support( 'custom-background' );1639 1640 if ( is_admin() ) {1641 remove_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) );1642 unset( $GLOBALS['custom_background'] );1643 }1644 1645 return true;1646 }1647 1648 /**1649 1551 * Default custom background callback. 1650 1552 * 1651 1553 * @since 3.0.0 … … 1694 1596 * the theme root. It also accepts an array of stylesheets. 1695 1597 * It is optional and defaults to 'editor-style.css'. 1696 1598 * 1697 * Supports RTL stylesheets automatically by searching for the -rtl prefix, e.g.1698 * editor-style-rtl.css. If an array of stylesheets is passed to add_editor_style(),1699 * RTL is only added for the first stylesheet.1700 *1701 1599 * @since 3.0.0 1702 1600 * 1703 1601 * @param mixed $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. … … 1722 1620 } 1723 1621 1724 1622 /** 1725 * Removes all visual editor stylesheets.1726 *1727 * @since 3.1.01728 *1729 * @return bool True on success, false if there were no stylesheets to remove.1730 */1731 function remove_editor_styles() {1732 if ( ! current_theme_supports( 'editor-style' ) )1733 return false;1734 _remove_theme_support( 'editor-style' );1735 if ( is_admin() )1736 $GLOBALS['editor_styles'] = array();1737 return true;1738 }1739 1740 /**1741 1623 * Allows a theme to register its support of a certain feature 1742 1624 * 1743 1625 * Must be called in the theme's functions.php file to work. … … 1754 1636 $_wp_theme_features[$feature] = true; 1755 1637 else 1756 1638 $_wp_theme_features[$feature] = array_slice( func_get_args(), 1 ); 1757 1758 if ( $feature == 'post-formats' && is_array( $_wp_theme_features[$feature][0] ) )1759 $_wp_theme_features[$feature][0] = array_intersect( $_wp_theme_features[$feature][0], array_keys( get_post_format_slugs() ) );1760 1639 } 1761 1640 1762 1641 /** 1763 * Gets the theme support arguments passed when registering that support1764 *1765 * @since 3.11766 * @param string $feature the feature to check1767 * @return array The array of extra arguments1768 */1769 function get_theme_support( $feature ) {1770 global $_wp_theme_features;1771 if ( !isset( $_wp_theme_features[$feature] ) )1772 return false;1773 else1774 return $_wp_theme_features[$feature];1775 }1776 1777 /**1778 1642 * Allows a theme to de-register its support of a certain feature 1779 1643 * 1780 1644 * Should be called in the theme's functions.php file. Generally would … … 1789 1653 // Blacklist: for internal registrations not used directly by themes. 1790 1654 if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) ) 1791 1655 return false; 1792 return _remove_theme_support( $feature );1793 }1794 1656 1795 /**1796 * Do not use. Removes theme support internally, ignorant of the blacklist.1797 *1798 * @access private1799 * @since 3.1.01800 */1801 function _remove_theme_support( $feature ) {1802 1657 global $_wp_theme_features; 1803 1658 1804 1659 if ( ! isset( $_wp_theme_features[$feature] ) )