Ticket #7657: 7657.r8961.diff
File 7657.r8961.diff, 21.2 KB (added by , 16 years ago) |
---|
-
theme.php
7 7 */ 8 8 9 9 /** 10 * Get current theme name.10 * Retrieve name of the current stylesheet. 11 11 * 12 * The theme name that the administrator has currently set the front end theme12 * The theme name that the administrator has currently set the front end theme 13 13 * as. 14 14 * 15 * For all extensive purposes, the template name and the stylesheet name are 16 * going to be the same for most cases. 17 * 15 18 * @since 1.5.0 16 * @uses apply_filters() Calls 'stylesheet' filter 19 * @uses apply_filters() Calls 'stylesheet' filter on stylesheet name. 17 20 * 18 * @return string 21 * @return string Stylesheet name. 19 22 */ 20 23 function get_stylesheet() { 21 24 return apply_filters('stylesheet', get_option('stylesheet')); 22 25 } 23 26 24 27 /** 25 * get_stylesheet_directory() - {@internal Missing Short Description}}28 * Retrieve stylesheet directory path for current theme. 26 29 * 27 * {@internal Missing Long Description}}28 *29 30 * @since 1.5.0 31 * @uses apply_filters() Calls 'stylesheet_directory' filter on stylesheet directory and theme name. 30 32 * 31 * @return unknown33 * @return string Path to current theme directory. 32 34 */ 33 35 function get_stylesheet_directory() { 34 36 $stylesheet = get_stylesheet(); … … 37 39 } 38 40 39 41 /** 40 * get_stylesheet_directory_uri() - {@internal Missing Short Description}}42 * Retrieve stylesheet directory URI. 41 43 * 42 * {@internal Missing Long Description}}43 *44 44 * @since 1.5.0 45 45 * 46 * @return unknown46 * @return string 47 47 */ 48 48 function get_stylesheet_directory_uri() { 49 49 $stylesheet = get_stylesheet(); … … 52 52 } 53 53 54 54 /** 55 * get_stylesheet_uri() - {@internal Missing Short Description}}55 * Retrieve URI of current theme stylesheet. 56 56 * 57 * {@internal Missing Long Description}} 57 * The stylesheet file name is 'style.css' which is appended to {@link 58 * get_stylesheet_directory_uri() stylesheet directory URI} path. 58 59 * 59 60 * @since 1.5.0 61 * @uses apply_filters() Calls 'stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI. 60 62 * 61 * @return unknown63 * @return string 62 64 */ 63 65 function get_stylesheet_uri() { 64 66 $stylesheet_dir_uri = get_stylesheet_directory_uri(); … … 67 69 } 68 70 69 71 /** 70 * get_locale_stylesheet_uri() - {@internal Missing Short Description}}72 * Retrieve localized stylesheet URI. 71 73 * 72 74 * {@internal Missing Long Description}} 73 75 * 74 76 * @since 2.1.0 77 * @uses apply_filters() Calls 'locale_stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI. 75 78 * 76 * @return unknown79 * @return string 77 80 */ 78 81 function get_locale_stylesheet_uri() { 79 82 global $wp_locale; … … 90 93 } 91 94 92 95 /** 93 * get_template() - {@internal Missing Short Description}}96 * Retrieve name of the current theme. 94 97 * 95 * {@internal Missing Long Description}}96 *97 98 * @since 1.5.0 99 * @uses apply_filters() Calls 'template' filter on template option. 98 100 * 99 * @return unknown101 * @return string Template name. 100 102 */ 101 103 function get_template() { 102 104 return apply_filters('template', get_option('template')); 103 105 } 104 106 105 107 /** 106 * get_template_directory() - {@internal Missing Short Description}}108 * Retrieve current theme directory. 107 109 * 108 * {@internal Missing Long Description}}109 *110 110 * @since 1.5.0 111 * @uses apply_filters() Calls 'template_directory' filter on template directory path and template name. 111 112 * 112 * @return unknown113 * @return string Template directory path. 113 114 */ 114 115 function get_template_directory() { 115 116 $template = get_template(); … … 118 119 } 119 120 120 121 /** 121 * get_template_directory_uri() - {@internal Missing Short Description}}122 * Retrieve theme directory URI. 122 123 * 123 * {@internal Missing Long Description}}124 *125 124 * @since 1.5.0 125 * @uses apply_filters() Calls 'template_directory_uri' filter on template directory URI path and template name. 126 126 * 127 * @return unknown127 * @return string Template directory URI. 128 128 */ 129 129 function get_template_directory_uri() { 130 130 $template = get_template(); … … 133 133 } 134 134 135 135 /** 136 * get_theme_data() - {@internal Missing Short Description}}136 * Retrieve theme data from parsed theme file. 137 137 * 138 138 * {@internal Missing Long Description}} 139 139 * 140 140 * @since 1.5.0 141 141 * 142 * @param unknown_type $theme_file143 * @return unknown142 * @param string $theme_file Theme file path. 143 * @return array Theme data. 144 144 */ 145 145 function get_theme_data( $theme_file ) { 146 146 $themes_allowed_tags = array( … … 207 207 } 208 208 209 209 /** 210 * get_themes() - {@internal Missing Short Description}}210 * Retrieve list of themes with theme data in theme directory. 211 211 * 212 212 * {@internal Missing Long Description}} 213 213 * 214 214 * @since 1.5.0 215 215 * 216 * @return unknown216 * @return array Theme list with theme data. 217 217 */ 218 218 function get_themes() { 219 219 global $wp_themes, $wp_broken_themes; … … 400 400 } 401 401 402 402 /** 403 * get_theme() - {@internal Missing Short Description}}403 * Retrieve theme data. 404 404 * 405 * {@internal Missing Long Description}}406 *407 405 * @since 1.5.0 408 406 * 409 * @param unknown_type $theme410 * @return unknown407 * @param string $theme Theme name. 408 * @return array|null Null, if theme name does not exist. Theme data, if exists. 411 409 */ 412 410 function get_theme($theme) { 413 411 $themes = get_themes(); … … 415 413 if ( array_key_exists($theme, $themes) ) 416 414 return $themes[$theme]; 417 415 418 return NULL;416 return null; 419 417 } 420 418 421 419 /** 422 * get_current_theme() - {@internal Missing Short Description}}420 * Retrieve current theme display name. 423 421 * 424 * {@internal Missing Long Description}} 422 * If the 'current_theme' option has already been set, then it will be returned 423 * instead. If it is not set, then each theme will be iterated over until both 424 * the current stylesheet and current template name. 425 425 * 426 426 * @since 1.5.0 427 427 * 428 * @return unknown428 * @return string 429 429 */ 430 430 function get_current_theme() { 431 431 if ( $theme = get_option('current_theme') ) … … 453 453 } 454 454 455 455 /** 456 * get_theme_root() - {@internal Missing Short Description}}456 * Retrieve path to themes directory. 457 457 * 458 * {@internal Missing Long Description}}458 * Does not have trailing slash. 459 459 * 460 460 * @since 1.5.0 461 * @uses apply_filters() Calls 'theme_root' filter on path. 461 462 * 462 * @return unknown463 * @return string Theme path. 463 464 */ 464 465 function get_theme_root() { 465 466 return apply_filters('theme_root', WP_CONTENT_DIR . "/themes"); 466 467 } 467 468 468 469 /** 469 * get_theme_root_uri() - {@internal Missing Short Description}}470 * Retrieve URI for themes directory. 470 471 * 471 * {@internal Missing Long Description}}472 * Does not have trailing slash. 472 473 * 473 474 * @since 1.5.0 474 475 * 475 * @return unknown476 * @return string Themes URI. 476 477 */ 477 478 function get_theme_root_uri() { 478 479 return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl')); 479 480 } 480 481 481 482 /** 482 * get_query_template() - {@internal Missing Short Description}}483 * Retrieve path to file without the use of extension. 483 484 * 484 * {@internal Missing Long Description}} 485 * Used to quickly retrieve the path of file without including the file 486 * extension. It will also check the parent template, if the file exists, with 487 * the use of {@link locate_template()}. Allows for more generic file location 488 * without the use of the other get_*_template() functions. 485 489 * 490 * Can be used with include() or require() to retrieve path. 491 * <code> 492 * if( '' != get_query_template( '404' ) ) 493 * include( get_query_template( '404' ) ); 494 * </code> 495 * or the same can be accomplished with 496 * <code> 497 * if( '' != get_404_template() ) 498 * include( get_404_template() ); 499 * </code> 500 * 486 501 * @since 1.5.0 487 502 * 488 * @param unknown_type $type489 * @return unknown503 * @param string $type Filename without extension. 504 * @return string Full path to file. 490 505 */ 491 506 function get_query_template($type) { 492 507 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); … … 494 509 } 495 510 496 511 /** 497 * get_404_template() - {@internal Missing Short Description}}512 * Retrieve path of 404 template in current or parent template. 498 513 * 499 * {@internal Missing Long Description}}500 *501 514 * @since 1.5.0 502 515 * 503 * @return unknown516 * @return string 504 517 */ 505 518 function get_404_template() { 506 519 return get_query_template('404'); 507 520 } 508 521 509 522 /** 510 * get_archive_template() - {@internal Missing Short Description}}523 * Retrieve path of archive template in current or parent template. 511 524 * 512 * {@internal Missing Long Description}}513 *514 525 * @since 1.5.0 515 526 * 516 * @return unknown527 * @return string 517 528 */ 518 529 function get_archive_template() { 519 530 return get_query_template('archive'); 520 531 } 521 532 522 533 /** 523 * get_author_template() - {@internal Missing Short Description}}534 * Retrieve path of author template in current or parent template. 524 535 * 525 * {@internal Missing Long Description}}526 *527 536 * @since 1.5.0 528 537 * 529 * @return unknown538 * @return string 530 539 */ 531 540 function get_author_template() { 532 541 return get_query_template('author'); 533 542 } 534 543 535 544 /** 536 * get_category_template() - {@internal Missing Short Description}}545 * Retrieve path of category template in current or parent template. 537 546 * 538 * {@internal Missing Long Description}} 547 * Works by retrieving the current category ID, for example 'category-1.php' and 548 * will fallback to category.php template, if the ID category file doesn't 549 * exist. 539 550 * 540 551 * @since 1.5.0 552 * @uses apply_filters() Calls 'category_template' on file path of category template. 541 553 * 542 * @return unknown554 * @return string 543 555 */ 544 556 function get_category_template() { 545 $template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php',"category.php"));557 $template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php', 'category.php')); 546 558 return apply_filters('category_template', $template); 547 559 } 548 560 549 561 /** 550 * get_tag_template() - {@internal Missing Short Description}}562 * Retrieve path of tag template in current or parent template. 551 563 * 552 * {@internal Missing Long Description}} 564 * Works by retrieving the current tag ID, for example 'tag-1.php' and will 565 * fallback to tag.php template, if the ID tag file doesn't exist. 553 566 * 554 567 * @since 2.3.0 568 * @uses apply_filters() Calls 'tag_template' on file path of tag template. 555 569 * 556 * @return unknown570 * @return string 557 571 */ 558 572 function get_tag_template() { 559 $template = locate_template(array("tag-" . absint( get_query_var('tag') ) . '.php', "tag.php"));573 $template = locate_template(array("tag-" . absint( get_query_var('tag') ) . '.php', 'tag.php')); 560 574 return apply_filters('tag_template', $template); 561 575 } 562 576 563 /**564 * get_date_template() - {@internal Missing Short Description}}565 *566 * {@internal Missing Long Description}}567 *568 * @since 1.5.0569 *570 * @return unknown571 */572 577 function get_taxonomy_template() { 573 578 $taxonomy = get_query_var('taxonomy'); 574 579 $term = get_query_var('term'); … … 578 583 $templates[] = "taxonomy-$taxonomy-$term.php"; 579 584 if ( $taxonomy ) 580 585 $templates[] = "taxonomy-$taxonomy.php"; 581 586 582 587 $templates[] = "taxonomy.php"; 583 588 584 589 $template = locate_template($templates); 585 590 return apply_filters('taxonomy_template', $template); 586 591 } 587 592 593 /** 594 * Retrieve path of date template in current or parent template. 595 * 596 * @since 1.5.0 597 * 598 * @return string 599 */ 588 600 function get_date_template() { 589 601 return get_query_template('date'); 590 602 } 591 603 592 604 /** 593 * get_home_template() - {@internal Missing Short Description}}605 * Retrieve path of home template in current or parent template. 594 606 * 595 * {@internal Missing Long Description}}607 * Attempts to locate 'home.php' first before falling back to 'index.php'. 596 608 * 597 609 * @since 1.5.0 610 * @uses apply_filters() Calls 'home_template' on file path of home template. 598 611 * 599 * @return unknown612 * @return string 600 613 */ 601 614 function get_home_template() { 602 $template = locate_template(array('home.php', 'index.php'));615 $template = locate_template(array('home.php', 'index.php')); 603 616 return apply_filters('home_template', $template); 604 617 } 605 618 606 619 /** 607 * get_page_template() - {@internal Missing Short Description}}620 * Retrieve path of page template in current or parent template. 608 621 * 609 * {@internal Missing Long Description}} 622 * First attempt is to look for the file in the '_wp_page_template' page meta 623 * data. The second attempt, if the first has a file and is not empty, is to 624 * look for 'page.php'. 610 625 * 611 626 * @since 1.5.0 612 627 * 613 * @return unknown628 * @return string 614 629 */ 615 630 function get_page_template() { 616 631 global $wp_query; … … 624 639 $templates = array(); 625 640 if ( !empty($template) && !validate_file($template) ) 626 641 $templates[] = $template; 627 642 628 643 $templates[] = "page.php"; 629 644 630 645 return apply_filters('page_template', locate_template($templates)); 631 646 } 632 647 633 648 /** 634 * get_paged_template() - {@internal Missing Short Description}}649 * Retrieve path of paged template in current or parent template. 635 650 * 636 * {@internal Missing Long Description}}637 *638 651 * @since 1.5.0 639 652 * 640 * @return unknown653 * @return string 641 654 */ 642 655 function get_paged_template() { 643 656 return get_query_template('paged'); 644 657 } 645 658 646 659 /** 647 * get_search_template() - {@internal Missing Short Description}}660 * Retrieve path of search template in current or parent template. 648 661 * 649 * {@internal Missing Long Description}}650 *651 662 * @since 1.5.0 652 663 * 653 * @return unknown664 * @return string 654 665 */ 655 666 function get_search_template() { 656 667 return get_query_template('search'); 657 668 } 658 669 659 670 /** 660 * get_single_template() - {@internal Missing Short Description}}671 * Retrieve path of single template in current or parent template. 661 672 * 662 * {@internal Missing Long Description}}663 *664 673 * @since 1.5.0 665 674 * 666 675 * @return unknown … … 670 679 } 671 680 672 681 /** 673 * get_attachment_template() - {@internal Missing Short Description}}682 * Retrieve path of attachment template in current or parent template. 674 683 * 675 * {@internal Missing Long Description}} 684 * The attachment path first checks if the first part of the mime type exists. 685 * The second check is for the second part of the mime type. The last check is 686 * for both types separated by an underscore. If neither are found then the file 687 * 'attachment.php' is checked and returned. 676 688 * 689 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and 690 * finally 'text_plain.php'. 691 * 677 692 * @since 2.0.0 678 693 * 679 * @return unknown694 * @return string 680 695 */ 681 696 function get_attachment_template() { 682 697 global $posts; … … 692 707 } 693 708 694 709 /** 695 * get_comments_popup_template() - {@internal Missing Short Description}}710 * Retrieve path of comment popup template in current or parent template. 696 711 * 697 * {@internal Missing Long Description}} 712 * Checks for comment popup template in current template, if it exists or in the 713 * parent template. If it doesn't exist, then it retrieves the comment-popup.php 714 * file from the default theme. The default theme must then exist for it to 715 * work. 698 716 * 699 717 * @since 1.5.0 718 * @uses apply_filters() Calls 'comments_popup_template' filter on path. 700 719 * 701 * @return unknown720 * @return string 702 721 */ 703 722 function get_comments_popup_template() { 704 723 $template = locate_template(array("comments-popup.php")); … … 709 728 } 710 729 711 730 /** 712 * Ret urns the name of the highest priority template file that exists731 * Retrieve the name of the highest priority template file that exists. 713 732 * 714 733 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which 715 734 * inherit from a parent theme can just overload one file. 716 * @since 2.7717 735 * 718 * @param array $template_names Array of template files to search for in priority order 736 * @since 2.7.0 737 * 738 * @param array $template_names Array of template files to search for in priority order. 719 739 * @param bool $load If true the template file will be loaded if it is found. 720 740 * @return string The template filename if one is located. 721 741 */ 722 742 function locate_template($template_names, $load = false) { 723 743 if (!is_array($template_names)) 724 744 return ''; 725 745 726 746 $located = ''; 727 747 foreach($template_names as $template_name) { 728 748 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { … … 733 753 break; 734 754 } 735 755 } 736 756 737 757 if ($load && '' != $located) 738 758 load_template($located); 739 759 740 760 return $located; 741 761 } 742 762 743 763 /** 744 * load_template() - {@internal Missing Short Description}}764 * Require once the template file with WordPress environment. 745 765 * 746 * {@internal Missing Long Description}} 766 * The globals are set up for the template file to ensure that the WordPress 767 * environment is available from within the function. The query variables are 768 * also available. 747 769 * 748 770 * @since 1.5.0 749 771 * 750 * @param unknown_type $_template_file772 * @param string $_template_file Path to template file. 751 773 */ 752 774 function load_template($_template_file) { 753 775 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; … … 759 781 } 760 782 761 783 /** 762 * locale_stylesheet() - {@internal Missing Short Description}}784 * Display localized stylesheet link element. 763 785 * 764 * {@internal Missing Long Description}}765 *766 786 * @since 2.1.0 767 787 */ 768 788 function locale_stylesheet() { … … 773 793 } 774 794 775 795 /** 776 * switch_theme() -{@internal Missing Short Description}}796 * {@internal Missing Short Description}} 777 797 * 778 798 * {@internal Missing Long Description}} 779 799 * … … 838 858 } 839 859 840 860 /** 841 * validate_current_theme() - {@internal Missing Short Description}}861 * Checks that current theme files 'index.php' and 'style.css' exists. 842 862 * 843 * {@internal Missing Long Description}} 863 * Does not check the 'default' theme. The 'default' theme should always exist 864 * or should have another theme renamed to that template name and directory 865 * path. Will switch theme to default if current theme does not validate. 844 866 * 845 867 * @since 1.5.0 846 868 * 847 * @return unknown869 * @return bool 848 870 */ 849 871 function validate_current_theme() { 850 872 // Don't validate during an install/upgrade. … … 865 887 } 866 888 867 889 /** 868 * get_theme_mod() - {@internal Missing Short Description}}890 * Retrieve theme modification value for the current theme. 869 891 * 870 * {@internal Missing Long Description}} 892 * If the modification name does not exist, then the $default will be passed 893 * through {@link http://php.net/sprintf sprintf()} PHP function with the first 894 * string the template directory URI and the second string the stylesheet 895 * directory URI. 871 896 * 872 897 * @since 2.1.0 898 * @uses apply_filters() Calls 'theme_mod_$name' filter on the value. 873 899 * 874 * @param unknown_type $name875 * @param unknown_type$default876 * @return unknown900 * @param string $name Theme modification name. 901 * @param bool|string $default 902 * @return string 877 903 */ 878 904 function get_theme_mod($name, $default = false) { 879 905 $theme = get_current_theme(); … … 887 913 } 888 914 889 915 /** 890 * set_theme_mod() - {@internal Missing Short Description}}916 * Update theme modification value for the current theme. 891 917 * 892 * {@internal Missing Long Description}}893 *894 918 * @since 2.1.0 895 919 * 896 * @param unknown_type $name897 * @param unknown_type $value920 * @param string $name Theme modification name. 921 * @param string $value theme modification value. 898 922 */ 899 923 function set_theme_mod($name, $value) { 900 924 $theme = get_current_theme(); … … 908 932 } 909 933 910 934 /** 911 * remove_theme_mod() - {@internal Missing Short Description}}935 * Remove theme modification name from current theme list. 912 936 * 913 * {@internal Missing Long Description}} 937 * If removing the name also removes all elements, then the entire option will 938 * be removed. 914 939 * 915 940 * @since 2.1.0 916 941 * 917 * @param unknown_type $name918 * @return unknown942 * @param string $name Theme modification name. 943 * @return null 919 944 */ 920 945 function remove_theme_mod( $name ) { 921 946 $theme = get_current_theme(); … … 935 960 } 936 961 937 962 /** 938 * remove_theme_mods() - {@internal Missing Short Description}}963 * Remove theme modifications option for current theme. 939 964 * 940 * {@internal Missing Long Description}}941 *942 965 * @since 2.1.0 943 966 */ 944 967 function remove_theme_mods() { … … 948 971 } 949 972 950 973 /** 951 * get_header_textcolor() - {@internal Missing Short Description}}974 * Retrieve text color for custom header. 952 975 * 953 * {@internal Missing Long Description}}954 *955 976 * @since 2.1.0 977 * @uses HEADER_TEXTCOLOR 956 978 * 957 * @return unknown979 * @return string 958 980 */ 959 981 function get_header_textcolor() { 960 982 return get_theme_mod('header_textcolor', HEADER_TEXTCOLOR); 961 983 } 962 984 963 985 /** 964 * header_textcolor() - {@internal Missing Short Description}}986 * Display text color for custom header. 965 987 * 966 * {@internal Missing Long Description}}967 *968 988 * @since 2.1.0 969 *970 989 */ 971 990 function header_textcolor() { 972 991 echo get_header_textcolor(); 973 992 } 974 993 975 994 /** 976 * get_header_image() - {@internal Missing Short Description}}995 * Retrieve header image for custom header. 977 996 * 978 * {@internal Missing Long Description}}979 *980 997 * @since 2.1.0 998 * @uses HEADER_IMAGE 981 999 * 982 * @return unknown1000 * @return string 983 1001 */ 984 1002 function get_header_image() { 985 1003 return get_theme_mod('header_image', HEADER_IMAGE); 986 1004 } 987 1005 988 1006 /** 989 * header_image() - {@internal Missing Short Description}}1007 * Display header image path. 990 1008 * 991 * {@internal Missing Long Description}}992 *993 1009 * @since 2.1.0 994 1010 */ 995 1011 function header_image() { … … 997 1013 } 998 1014 999 1015 /** 1000 * add_custom_image_header() - {@internal Missing Short Description}}1016 * Add callbacks for image header display. 1001 1017 * 1002 * {@internal Missing Long Description}} 1018 * The parameter $header_callback callback will be required to display the 1019 * content for the 'wp_head' action. The parameter $admin_header_callback 1020 * callback will be added to Custom_Image_Header class and that will be added 1021 * to the 'admin_menu' action. 1003 1022 * 1004 1023 * @since 2.1.0 1024 * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display. 1005 1025 * 1006 * @param unknown_type $header_callback1007 * @param unknown_type $admin_header_callback1026 * @param callback $header_callback Call on 'wp_head' action. 1027 * @param callback $admin_header_callback Call on administration panels. 1008 1028 */ 1009 1029 function add_custom_image_header($header_callback, $admin_header_callback) { 1010 1030 if ( ! empty($header_callback) )