Ticket #7657: 7657.r8786.diff
File 7657.r8786.diff, 13.4 KB (added by , 16 years ago) |
---|
-
theme.php
1 1 <?php 2 2 /** 3 * Theme, template, and stylesheet functions. 4 * 3 5 * @package WordPress 4 * @subpackage Themes 5 * @since 0.0 6 * Theme/template/stylesheet functions. 6 * @subpackage Template 7 7 */ 8 9 /** 10 * Get current theme name. 11 * 12 * The theme name that the administrator has currently set the frontend theme 13 * as. 14 * 15 * @since 1.5.0 16 * @uses apply_filters() Calls 'stylesheet' filter 17 * 18 * @return string 19 */ 8 20 function get_stylesheet() { 9 21 return apply_filters('stylesheet', get_option('stylesheet')); 10 22 } 11 23 24 /** 25 * get_stylesheet_directory() - {@internal Missing Short Description}} 26 * 27 * {@internal Missing Long Description}} 28 * 29 * @since 1.5.0 30 * 31 * @return unknown 32 */ 12 33 function get_stylesheet_directory() { 13 34 $stylesheet = get_stylesheet(); 14 35 $stylesheet_dir = get_theme_root() . "/$stylesheet"; 15 36 return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet); 16 37 } 17 38 39 /** 40 * get_stylesheet_directory_uri() - {@internal Missing Short Description}} 41 * 42 * {@internal Missing Long Description}} 43 * 44 * @since 1.5.0 45 * 46 * @return unknown 47 */ 18 48 function get_stylesheet_directory_uri() { 19 49 $stylesheet = get_stylesheet(); 20 50 $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet"; 21 51 return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet); 22 52 } 23 53 54 /** 55 * get_stylesheet_uri() - {@internal Missing Short Description}} 56 * 57 * {@internal Missing Long Description}} 58 * 59 * @since 1.5.0 60 * 61 * @return unknown 62 */ 24 63 function get_stylesheet_uri() { 25 64 $stylesheet_dir_uri = get_stylesheet_directory_uri(); 26 65 $stylesheet_uri = $stylesheet_dir_uri . "/style.css"; 27 66 return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri); 28 67 } 29 68 69 /** 70 * get_locale_stylesheet_uri() - {@internal Missing Short Description}} 71 * 72 * {@internal Missing Long Description}} 73 * 74 * @since 2.1.0 75 * 76 * @return unknown 77 */ 30 78 function get_locale_stylesheet_uri() { 31 79 global $wp_locale; 32 80 $stylesheet_dir_uri = get_stylesheet_directory_uri(); … … 41 89 return apply_filters('locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri); 42 90 } 43 91 92 /** 93 * get_template() - {@internal Missing Short Description}} 94 * 95 * {@internal Missing Long Description}} 96 * 97 * @since 1.5.0 98 * 99 * @return unknown 100 */ 44 101 function get_template() { 45 102 return apply_filters('template', get_option('template')); 46 103 } 47 104 105 /** 106 * get_template_directory() - {@internal Missing Short Description}} 107 * 108 * {@internal Missing Long Description}} 109 * 110 * @since 1.5.0 111 * 112 * @return unknown 113 */ 48 114 function get_template_directory() { 49 115 $template = get_template(); 50 116 $template_dir = get_theme_root() . "/$template"; 51 117 return apply_filters('template_directory', $template_dir, $template); 52 118 } 53 119 120 /** 121 * get_template_directory_uri() - {@internal Missing Short Description}} 122 * 123 * {@internal Missing Long Description}} 124 * 125 * @since 1.5.0 126 * 127 * @return unknown 128 */ 54 129 function get_template_directory_uri() { 55 130 $template = get_template(); 56 131 $template_dir_uri = get_theme_root_uri() . "/$template"; 57 132 return apply_filters('template_directory_uri', $template_dir_uri, $template); 58 133 } 59 134 135 /** 136 * get_theme_data() - {@internal Missing Short Description}} 137 * 138 * {@internal Missing Long Description}} 139 * 140 * @since 1.5.0 141 * 142 * @param unknown_type $theme_file 143 * @return unknown 144 */ 60 145 function get_theme_data( $theme_file ) { 61 146 $themes_allowed_tags = array( 62 147 'a' => array( … … 121 206 return array( 'Name' => $name, 'Title' => $theme, 'URI' => $theme_uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status, 'Tags' => $tags ); 122 207 } 123 208 209 /** 210 * get_themes() - {@internal Missing Short Description}} 211 * 212 * {@internal Missing Long Description}} 213 * 214 * @since 1.5.0 215 * 216 * @return unknown 217 */ 124 218 function get_themes() { 125 219 global $wp_themes, $wp_broken_themes; 126 220 … … 305 399 return $themes; 306 400 } 307 401 402 /** 403 * get_theme() - {@internal Missing Short Description}} 404 * 405 * {@internal Missing Long Description}} 406 * 407 * @since 1.5.0 408 * 409 * @param unknown_type $theme 410 * @return unknown 411 */ 308 412 function get_theme($theme) { 309 413 $themes = get_themes(); 310 414 … … 314 418 return NULL; 315 419 } 316 420 421 /** 422 * get_current_theme() - {@internal Missing Short Description}} 423 * 424 * {@internal Missing Long Description}} 425 * 426 * @since 1.5.0 427 * 428 * @return unknown 429 */ 317 430 function get_current_theme() { 318 431 if ( $theme = get_option('current_theme') ) 319 432 return $theme; … … 339 452 return $current_theme; 340 453 } 341 454 455 /** 456 * get_theme_root() - {@internal Missing Short Description}} 457 * 458 * {@internal Missing Long Description}} 459 * 460 * @since 1.5.0 461 * 462 * @return unknown 463 */ 342 464 function get_theme_root() { 343 465 return apply_filters('theme_root', WP_CONTENT_DIR . "/themes"); 344 466 } 345 467 468 /** 469 * get_theme_root_uri() - {@internal Missing Short Description}} 470 * 471 * {@internal Missing Long Description}} 472 * 473 * @since 1.5.0 474 * 475 * @return unknown 476 */ 346 477 function get_theme_root_uri() { 347 478 return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl')); 348 479 } 349 480 481 /** 482 * get_query_template() - {@internal Missing Short Description}} 483 * 484 * {@internal Missing Long Description}} 485 * 486 * @since 1.5.0 487 * 488 * @param unknown_type $type 489 * @return unknown 490 */ 350 491 function get_query_template($type) { 351 492 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 352 493 return apply_filters("{$type}_template", locate_template(array("{$type}.php"))); 353 494 } 354 495 496 /** 497 * get_404_template() - {@internal Missing Short Description}} 498 * 499 * {@internal Missing Long Description}} 500 * 501 * @since 1.5.0 502 * 503 * @return unknown 504 */ 355 505 function get_404_template() { 356 506 return get_query_template('404'); 357 507 } 358 508 509 /** 510 * get_archive_template() - {@internal Missing Short Description}} 511 * 512 * {@internal Missing Long Description}} 513 * 514 * @since 1.5.0 515 * 516 * @return unknown 517 */ 359 518 function get_archive_template() { 360 519 return get_query_template('archive'); 361 520 } 362 521 522 /** 523 * get_author_template() - {@internal Missing Short Description}} 524 * 525 * {@internal Missing Long Description}} 526 * 527 * @since 1.5.0 528 * 529 * @return unknown 530 */ 363 531 function get_author_template() { 364 532 return get_query_template('author'); 365 533 } 366 534 535 /** 536 * get_category_template() - {@internal Missing Short Description}} 537 * 538 * {@internal Missing Long Description}} 539 * 540 * @since 1.5.0 541 * 542 * @return unknown 543 */ 367 544 function get_category_template() { 368 545 $template =locate_template(array("category-" . absint( get_query_var('cat') ) . '.php',"category.php")); 369 546 return apply_filters('category_template', $template); 370 547 } 371 548 549 /** 550 * get_tag_template() - {@internal Missing Short Description}} 551 * 552 * {@internal Missing Long Description}} 553 * 554 * @since 2.3.0 555 * 556 * @return unknown 557 */ 372 558 function get_tag_template() { 373 559 $template = locate_template(array("tag-" . absint( get_query_var('tag') ) . '.php',"tag.php")); 374 560 return apply_filters('tag_template', $template); 375 561 } 376 562 563 /** 564 * get_date_template() - {@internal Missing Short Description}} 565 * 566 * {@internal Missing Long Description}} 567 * 568 * @since 1.5.0 569 * 570 * @return unknown 571 */ 377 572 function get_taxonomy_template() { 378 573 $taxonomy = get_query_var('taxonomy'); 379 574 $term = get_query_var('term'); … … 394 589 return get_query_template('date'); 395 590 } 396 591 592 /** 593 * get_home_template() - {@internal Missing Short Description}} 594 * 595 * {@internal Missing Long Description}} 596 * 597 * @since 1.5.0 598 * 599 * @return unknown 600 */ 397 601 function get_home_template() { 398 602 $template = locate_template(array('home.php','index.php')); 399 603 return apply_filters('home_template', $template); 400 604 } 401 605 606 /** 607 * get_page_template() - {@internal Missing Short Description}} 608 * 609 * {@internal Missing Long Description}} 610 * 611 * @since 1.5.0 612 * 613 * @return unknown 614 */ 402 615 function get_page_template() { 403 616 global $wp_query; 404 617 … … 417 630 return apply_filters('page_template', locate_template($templates)); 418 631 } 419 632 633 /** 634 * get_paged_template() - {@internal Missing Short Description}} 635 * 636 * {@internal Missing Long Description}} 637 * 638 * @since 1.5.0 639 * 640 * @return unknown 641 */ 420 642 function get_paged_template() { 421 643 return get_query_template('paged'); 422 644 } 423 645 646 /** 647 * get_search_template() - {@internal Missing Short Description}} 648 * 649 * {@internal Missing Long Description}} 650 * 651 * @since 1.5.0 652 * 653 * @return unknown 654 */ 424 655 function get_search_template() { 425 656 return get_query_template('search'); 426 657 } 427 658 659 /** 660 * get_single_template() - {@internal Missing Short Description}} 661 * 662 * {@internal Missing Long Description}} 663 * 664 * @since 1.5.0 665 * 666 * @return unknown 667 */ 428 668 function get_single_template() { 429 669 return get_query_template('single'); 430 670 } 431 671 672 /** 673 * get_attachment_template() - {@internal Missing Short Description}} 674 * 675 * {@internal Missing Long Description}} 676 * 677 * @since 2.0.0 678 * 679 * @return unknown 680 */ 432 681 function get_attachment_template() { 433 682 global $posts; 434 683 $type = explode('/', $posts[0]->post_mime_type); … … 442 691 return get_query_template('attachment'); 443 692 } 444 693 694 /** 695 * get_comments_popup_template() - {@internal Missing Short Description}} 696 * 697 * {@internal Missing Long Description}} 698 * 699 * @since 1.5.0 700 * 701 * @return unknown 702 */ 445 703 function get_comments_popup_template() { 446 704 $template = locate_template(array("comments-popup.php")); 447 705 if ('' == $template) … … 482 740 return $located; 483 741 } 484 742 743 /** 744 * load_template() - {@internal Missing Short Description}} 745 * 746 * {@internal Missing Long Description}} 747 * 748 * @since 1.5.0 749 * 750 * @param unknown_type $_template_file 751 */ 485 752 function load_template($_template_file) { 486 753 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 487 754 … … 491 758 require_once($_template_file); 492 759 } 493 760 761 /** 762 * locale_stylesheet() - {@internal Missing Short Description}} 763 * 764 * {@internal Missing Long Description}} 765 * 766 * @since 2.1.0 767 */ 494 768 function locale_stylesheet() { 495 769 $stylesheet = get_locale_stylesheet_uri(); 496 770 if ( empty($stylesheet) ) … … 498 772 echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; 499 773 } 500 774 775 /** 776 * switch_theme() - {@internal Missing Short Description}} 777 * 778 * {@internal Missing Long Description}} 779 * 780 * @since 2.5.0 781 * 782 * @param unknown_type $template 783 * @param unknown_type $stylesheet 784 */ 501 785 function preview_theme() { 502 786 if ( ! (isset($_GET['template']) && isset($_GET['preview'])) ) 503 787 return; … … 553 837 do_action('switch_theme', $theme); 554 838 } 555 839 840 /** 841 * validate_current_theme() - {@internal Missing Short Description}} 842 * 843 * {@internal Missing Long Description}} 844 * 845 * @since 1.5.0 846 * 847 * @return unknown 848 */ 556 849 function validate_current_theme() { 557 850 // Don't validate during an install/upgrade. 558 851 if ( defined('WP_INSTALLING') ) … … 571 864 return true; 572 865 } 573 866 867 /** 868 * get_theme_mod() - {@internal Missing Short Description}} 869 * 870 * {@internal Missing Long Description}} 871 * 872 * @since 2.1.0 873 * 874 * @param unknown_type $name 875 * @param unknown_type $default 876 * @return unknown 877 */ 574 878 function get_theme_mod($name, $default = false) { 575 879 $theme = get_current_theme(); 576 880 … … 582 886 return apply_filters( "theme_mod_$name", sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()) ); 583 887 } 584 888 889 /** 890 * set_theme_mod() - {@internal Missing Short Description}} 891 * 892 * {@internal Missing Long Description}} 893 * 894 * @since 2.1.0 895 * 896 * @param unknown_type $name 897 * @param unknown_type $value 898 */ 585 899 function set_theme_mod($name, $value) { 586 900 $theme = get_current_theme(); 587 901 … … 593 907 wp_cache_delete("mods_$theme", 'options'); 594 908 } 595 909 910 /** 911 * remove_theme_mod() - {@internal Missing Short Description}} 912 * 913 * {@internal Missing Long Description}} 914 * 915 * @since 2.1.0 916 * 917 * @param unknown_type $name 918 * @return unknown 919 */ 596 920 function remove_theme_mod( $name ) { 597 921 $theme = get_current_theme(); 598 922 … … 610 934 wp_cache_delete("mods_$theme", 'options'); 611 935 } 612 936 937 /** 938 * remove_theme_mods() - {@internal Missing Short Description}} 939 * 940 * {@internal Missing Long Description}} 941 * 942 * @since 2.1.0 943 */ 613 944 function remove_theme_mods() { 614 945 $theme = get_current_theme(); 615 946 616 947 delete_option("mods_$theme"); 617 948 } 618 949 950 /** 951 * get_header_textcolor() - {@internal Missing Short Description}} 952 * 953 * {@internal Missing Long Description}} 954 * 955 * @since 2.1.0 956 * 957 * @return unknown 958 */ 619 959 function get_header_textcolor() { 620 960 return get_theme_mod('header_textcolor', HEADER_TEXTCOLOR); 621 961 } 622 962 963 /** 964 * header_textcolor() - {@internal Missing Short Description}} 965 * 966 * {@internal Missing Long Description}} 967 * 968 * @since 2.1.0 969 * 970 */ 623 971 function header_textcolor() { 624 972 echo get_header_textcolor(); 625 973 } 626 974 975 /** 976 * get_header_image() - {@internal Missing Short Description}} 977 * 978 * {@internal Missing Long Description}} 979 * 980 * @since 2.1.0 981 * 982 * @return unknown 983 */ 627 984 function get_header_image() { 628 985 return get_theme_mod('header_image', HEADER_IMAGE); 629 986 } 630 987 988 /** 989 * header_image() - {@internal Missing Short Description}} 990 * 991 * {@internal Missing Long Description}} 992 * 993 * @since 2.1.0 994 */ 631 995 function header_image() { 632 996 echo get_header_image(); 633 997 } 634 998 999 /** 1000 * add_custom_image_header() - {@internal Missing Short Description}} 1001 * 1002 * {@internal Missing Long Description}} 1003 * 1004 * @since 2.1.0 1005 * 1006 * @param unknown_type $header_callback 1007 * @param unknown_type $admin_header_callback 1008 */ 635 1009 function add_custom_image_header($header_callback, $admin_header_callback) { 636 1010 if ( ! empty($header_callback) ) 637 1011 add_action('wp_head', $header_callback);