Changes from branches/3.0/wp-includes/theme.php at r15436 to trunk/wp-includes/theme.php at r17316
- File:
-
- 1 edited
-
trunk/wp-includes/theme.php (modified) (44 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/theme.php
r15436 r17316 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 * … … 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'], __( 'Visit author homepage' ), $theme_data['AuthorName'] );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'] ); 243 243 } 244 244 } … … 267 267 if ( isset($wp_themes) ) 268 268 return $wp_themes; 269 270 /* Register the default root as a theme directory */271 register_theme_directory( get_theme_root() );272 269 273 270 if ( !$theme_files = search_theme_directories() ) … … 389 386 $stylesheet_files = array_unique($stylesheet_files); 390 387 391 $template_dir = dirname($template_files[0]);392 $stylesheet_dir = dirname($stylesheet_files[0]);388 $template_dir = $template_directory; 389 $stylesheet_dir = $theme_root . '/' . $stylesheet; 393 390 394 391 if ( empty($template_dir) ) … … 400 397 // a new theme directory and the theme header is not updated. Whichever 401 398 // theme is first keeps the name. Subsequent themes get a suffix applied. 402 // The Default and Classic themes always trump their pretenders.399 // The Twenty Ten, Default and Classic themes always trump their pretenders. 403 400 if ( isset($wp_themes[$name]) ) { 404 if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) && 405 ('default' == $stylesheet || 'classic' == $stylesheet) ) { 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 ] ) { 406 407 // If another theme has claimed to be one of our default themes, move 407 408 // them aside. … … 467 468 * @since 2.9.0 468 469 * 469 * @return array Theme roots470 * @return array|string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root. 470 471 */ 471 472 function get_theme_roots() { 473 global $wp_theme_directories; 474 475 if ( count($wp_theme_directories) <= 1 ) 476 return '/themes'; 477 472 478 $theme_roots = get_site_transient( 'theme_roots' ); 473 479 if ( false === $theme_roots ) { … … 514 520 $current_template = get_option('template'); 515 521 $current_stylesheet = get_option('stylesheet'); 516 $current_theme = ' WordPress Default';522 $current_theme = 'Twenty Ten'; 517 523 518 524 if ( $themes ) { … … 589 595 while ( ($theme_dir = readdir($themes_dir)) !== false ) { 590 596 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { 591 if ( $theme_dir {0}== '.' || $theme_dir == 'CVS' )597 if ( $theme_dir[0] == '.' || $theme_dir == 'CVS' ) 592 598 continue; 593 599 … … 612 618 while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) { 613 619 if ( is_dir( $subdir . '/' . $theme_subdir) && is_readable($subdir . '/' . $theme_subdir) ) { 614 if ( $theme_subdir {0}== '.' || $theme_subdir == 'CVS' )620 if ( $theme_subdir[0] == '.' || $theme_subdir == 'CVS' ) 615 621 continue; 616 622 … … 646 652 * 647 653 * @since 1.5.0 648 * @param $stylesheet_or_template The stylesheet or template name of the theme649 654 * @uses apply_filters() Calls 'theme_root' filter on path. 650 655 * 656 * @param string $stylesheet_or_template The stylesheet or template name of the theme 651 657 * @return string Theme path. 652 658 */ 653 659 function get_theme_root( $stylesheet_or_template = false ) { 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]; 660 if ( $stylesheet_or_template ) { 661 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) ) 662 $theme_root = WP_CONTENT_DIR . $theme_root; 659 663 else 660 664 $theme_root = WP_CONTENT_DIR . '/themes'; … … 672 676 * 673 677 * @since 1.5.0 674 * @param $stylesheet_or_template The stylesheet or template name of the theme675 * 678 * 679 * @param string $stylesheet_or_template The stylesheet or template name of the theme 676 680 * @return string Themes URI. 677 681 */ 678 682 function get_theme_root_uri( $stylesheet_or_template = false ) { 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 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 { 684 689 $theme_root_uri = content_url( 'themes' ); 690 } 685 691 686 692 return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template ); … … 688 694 689 695 /** 690 * Retrieve path to file without the use of extension. 691 * 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 696 * Get the raw theme root relative to the content directory with no filters applied. 697 * 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 695 734 * without the use of the other get_*_template() functions. 696 735 * 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 with703 * <code>704 * if( '' != get_404_template() )705 * include( get_404_template() );706 * </code>707 *708 736 * @since 1.5.0 709 737 * 710 738 * @param string $type Filename without extension. 739 * @param array $templates An optional list of template candidates 711 740 * @return string Full path to file. 712 741 */ 713 function get_query_template( $type) {742 function get_query_template( $type, $templates = array() ) { 714 743 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 715 return apply_filters("{$type}_template", locate_template(array("{$type}.php"))); 744 745 if ( empty( $templates ) ) 746 $templates = array("{$type}.php"); 747 748 return apply_filters( "{$type}_template", locate_template( $templates ) ); 716 749 } 717 750 … … 746 779 */ 747 780 function get_archive_template() { 748 return get_query_template('archive'); 781 $post_type = get_query_var( 'post_type' ); 782 783 $templates = array(); 784 785 if ( $post_type ) 786 $templates[] = "archive-{$post_type}.php"; 787 $templates[] = 'archive.php'; 788 789 return get_query_template( 'archive', $templates ); 749 790 } 750 791 … … 757 798 */ 758 799 function get_author_template() { 759 $author_id = absint( get_query_var( 'author' ) ); 760 $author = get_user_by( 'id', $author_id ); 761 $author = $author->user_nicename; 800 $author = get_queried_object(); 762 801 763 802 $templates = array(); 764 803 765 if ( $author ) 766 $templates[] = "author-{$author}.php"; 767 if ( $author_id ) 768 $templates[] = "author-{$author_id}.php"; 804 $templates[] = "author-{$author->user_nicename}.php"; 805 $templates[] = "author-{$author->ID}.php"; 769 806 $templates[] = 'author.php'; 770 807 771 $template = locate_template( $templates ); 772 return apply_filters( 'author_template', $template ); 808 return get_query_template( 'author', $templates ); 773 809 } 774 810 … … 786 822 */ 787 823 function get_category_template() { 788 $cat_ID = absint( get_query_var('cat') ); 789 $category = get_category( $cat_ID ); 824 $category = get_queried_object(); 790 825 791 826 $templates = array(); 792 827 793 if ( !is_wp_error($category) ) 794 $templates[] = "category-{$category->slug}.php"; 795 796 $templates[] = "category-$cat_ID.php"; 828 $templates[] = "category-{$category->slug}.php"; 829 $templates[] = "category-{$category->term_id}.php"; 797 830 $templates[] = "category.php"; 798 831 799 $template = locate_template($templates); 800 return apply_filters('category_template', $template); 832 return get_query_template( 'category', $templates ); 801 833 } 802 834 … … 814 846 */ 815 847 function get_tag_template() { 816 $tag_id = absint( get_query_var('tag_id') ); 817 $tag_name = get_query_var('tag'); 848 $tag = get_queried_object(); 818 849 819 850 $templates = array(); 820 851 821 if ( $tag_name ) 822 $templates[] = "tag-$tag_name.php"; 823 if ( $tag_id ) 824 $templates[] = "tag-$tag_id.php"; 852 $templates[] = "tag-{$tag->slug}.php"; 853 $templates[] = "tag-{$tag->term_id}.php"; 825 854 $templates[] = "tag.php"; 826 855 827 $template = locate_template($templates); 828 return apply_filters('tag_template', $template); 856 return get_query_template( 'tag', $templates ); 829 857 } 830 858 … … 841 869 * index.php. 842 870 * 843 * @since unknown (2.6.0 most likely)871 * @since 2.5.0 844 872 * @uses apply_filters() Calls 'taxonomy_template' filter on found path. 845 873 * … … 847 875 */ 848 876 function get_taxonomy_template() { 849 $t axonomy = get_query_var('taxonomy');850 $t erm = get_query_var('term');877 $term = get_queried_object(); 878 $taxonomy = $term->taxonomy; 851 879 852 880 $templates = array(); 853 if ( $taxonomy && $term ) 854 $templates[] = "taxonomy-$taxonomy-$term.php"; 855 if ( $taxonomy ) 856 $templates[] = "taxonomy-$taxonomy.php"; 857 881 882 $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; 883 $templates[] = "taxonomy-$taxonomy.php"; 858 884 $templates[] = "taxonomy.php"; 859 885 860 $template = locate_template($templates); 861 return apply_filters('taxonomy_template', $template); 886 return get_query_template( 'taxonomy', $templates ); 862 887 } 863 888 … … 886 911 */ 887 912 function get_home_template() { 888 $template = locate_template(array('home.php', 'index.php')); 889 return apply_filters('home_template', $template); 913 $templates = array( 'home.php', 'index.php' ); 914 915 return get_query_template( 'home', $templates ); 890 916 } 891 917 … … 901 927 */ 902 928 function get_front_page_template() { 903 return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) ); 929 $templates = array('front-page.php'); 930 931 return get_query_template( 'front_page', $templates ); 904 932 } 905 933 … … 916 944 */ 917 945 function get_page_template() { 918 global $wp_query; 919 920 $id = (int) $wp_query->get_queried_object_id(); 946 $id = get_queried_object_id(); 921 947 $template = get_post_meta($id, '_wp_page_template', true); 922 948 $pagename = get_query_var('pagename'); … … 924 950 if ( !$pagename && $id > 0 ) { 925 951 // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object 926 $post = $wp_query->get_queried_object();952 $post = get_queried_object(); 927 953 $pagename = $post->post_name; 928 954 } … … 940 966 $templates[] = "page.php"; 941 967 942 return apply_filters('page_template', locate_template($templates));968 return get_query_template( 'page', $templates ); 943 969 } 944 970 … … 973 999 */ 974 1000 function get_single_template() { 975 global $wp_query; 976 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)); 1001 $object = get_queried_object(); 1002 1003 $templates = array(); 1004 1005 $templates[] = "single-{$object->post_type}.php"; 1006 $templates[] = "single.php"; 1007 1008 return get_query_template( 'single', $templates ); 980 1009 } 981 1010 … … 1020 1049 */ 1021 1050 function get_comments_popup_template() { 1022 $template = locate_template(array("comments-popup.php"));1051 $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) ); 1023 1052 1024 1053 // Backward compat code will be removed in a future release … … 1026 1055 $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; 1027 1056 1028 return apply_filters('comments_popup_template', $template);1057 return $template; 1029 1058 } 1030 1059 … … 1037 1066 * @since 2.7.0 1038 1067 * 1039 * @param array $template_names Array of template files to search for in priorityorder.1068 * @param string|array $template_names Template file(s) to search for, in order. 1040 1069 * @param bool $load If true the template file will be loaded if it is found. 1041 1070 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. … … 1043 1072 */ 1044 1073 function locate_template($template_names, $load = false, $require_once = true ) { 1045 if ( !is_array($template_names) )1046 return '';1047 1048 1074 $located = ''; 1049 foreach ( $template_names as $template_name ) {1075 foreach ( (array) $template_names as $template_name ) { 1050 1076 if ( !$template_name ) 1051 1077 continue; … … 1115 1141 if ( !current_user_can( 'switch_themes' ) ) 1116 1142 return; 1143 1144 // Admin Thickbox requests 1145 if ( isset( $_GET['preview_iframe'] ) ) 1146 show_admin_bar( false ); 1117 1147 1118 1148 $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']); … … 1208 1238 * Switches current theme to new template and stylesheet names. 1209 1239 * 1210 * @since unknown1240 * @since 2.5.0 1211 1241 * @uses do_action() Calls 'switch_theme' action on updated theme display name. 1212 1242 * … … 1215 1245 */ 1216 1246 function switch_theme($template, $stylesheet) { 1247 global $wp_theme_directories; 1248 1217 1249 update_option('template', $template); 1218 1250 update_option('stylesheet', $stylesheet); 1251 if ( count($wp_theme_directories) > 1 ) { 1252 update_option('template_root', get_raw_theme_root($template, true)); 1253 update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); 1254 } 1219 1255 delete_option('current_theme'); 1220 1256 $theme = get_current_theme(); 1257 if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) { 1258 $default_theme_mods = (array) get_option( "mods_$theme" ); 1259 add_option( "theme_mods_$stylesheet", $default_theme_mods ); 1260 } 1221 1261 do_action('switch_theme', $theme); 1222 1262 } … … 1250 1290 } 1251 1291 1292 if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) { 1293 switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); 1294 return false; 1295 } 1296 1252 1297 return true; 1298 } 1299 1300 /** 1301 * Retrieve all theme modifications. 1302 * 1303 * @since 3.1.0 1304 * 1305 * @return array Theme modifications. 1306 */ 1307 function get_theme_mods() { 1308 $theme_slug = get_option( 'stylesheet' ); 1309 if ( false === ( $mods = get_option( "theme_mods_$theme_slug" ) ) ) { 1310 $theme_name = get_current_theme(); 1311 $mods = get_option( "mods_$theme_name" ); // Deprecated location. 1312 if ( is_admin() && false !== $mods ) { 1313 update_option( "theme_mods_$theme_slug", $mods ); 1314 delete_option( "mods_$theme_name" ); 1315 } 1316 } 1317 return $mods; 1253 1318 } 1254 1319 … … 1268 1333 * @return string 1269 1334 */ 1270 function get_theme_mod($name, $default = false) { 1271 $theme = get_current_theme(); 1272 1273 $mods = get_option( "mods_$theme" ); 1274 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()) ); 1335 function get_theme_mod( $name, $default = false ) { 1336 $mods = get_theme_mods(); 1337 1338 if ( isset( $mods[ $name ] ) ) 1339 return apply_filters( "theme_mod_$name", $mods[ $name ] ); 1340 1341 return apply_filters( "theme_mod_$name", sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ) ); 1279 1342 } 1280 1343 … … 1287 1350 * @param string $value theme modification value. 1288 1351 */ 1289 function set_theme_mod($name, $value) { 1290 $theme = get_current_theme(); 1291 1292 $mods = get_option("mods_$theme"); 1293 1294 $mods[$name] = $value; 1295 1296 update_option("mods_$theme", $mods); 1297 wp_cache_delete("mods_$theme", 'options'); 1352 function set_theme_mod( $name, $value ) { 1353 $mods = get_theme_mods(); 1354 1355 $mods[ $name ] = $value; 1356 1357 $theme = get_option( 'stylesheet' ); 1358 update_option( "theme_mods_$theme", $mods ); 1298 1359 } 1299 1360 … … 1310 1371 */ 1311 1372 function remove_theme_mod( $name ) { 1312 $theme = get_current_theme(); 1313 1314 $mods = get_option("mods_$theme"); 1315 1316 if ( !isset($mods[$name]) ) 1373 $mods = get_theme_mods(); 1374 1375 if ( ! isset( $mods[ $name ] ) ) 1317 1376 return; 1318 1377 1319 unset( $mods[$name]);1320 1321 if ( empty( $mods) )1378 unset( $mods[ $name ] ); 1379 1380 if ( empty( $mods ) ) 1322 1381 return remove_theme_mods(); 1323 1382 1324 update_option("mods_$theme", $mods);1325 wp_cache_delete("mods_$theme", 'options');1383 $theme = get_option( 'stylesheet' ); 1384 update_option( "theme_mods_$theme", $mods ); 1326 1385 } 1327 1386 … … 1332 1391 */ 1333 1392 function remove_theme_mods() { 1334 $theme = get_current_theme(); 1335 1336 delete_option("mods_$theme"); 1393 delete_option( 'theme_mods_' . get_option( 'stylesheet' ) ); 1394 delete_option( 'mods_' . get_current_theme() ); 1337 1395 } 1338 1396 … … 1369 1427 */ 1370 1428 function get_header_image() { 1371 $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : ''; 1372 1373 return get_theme_mod('header_image', $default); 1429 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1430 1431 $url = get_theme_mod( 'header_image', $default ); 1432 1433 if ( is_ssl() ) 1434 $url = str_replace( 'http://', 'https://', $url ); 1435 else 1436 $url = str_replace( 'https://', 'http://', $url ); 1437 1438 return $url; 1374 1439 } 1375 1440 … … 1398 1463 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional. 1399 1464 */ 1400 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '') {1401 if ( ! empty( $header_callback) )1465 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '' ) { 1466 if ( ! empty( $header_callback ) ) 1402 1467 add_action('wp_head', $header_callback); 1403 1468 1404 add_theme_support( 'custom-header' ); 1469 add_theme_support( 'custom-header', array( 'callback' => $header_callback ) ); 1470 add_theme_support( 'custom-header-uploads' ); 1405 1471 1406 1472 if ( ! is_admin() ) 1407 1473 return; 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')); 1474 1475 global $custom_image_header; 1476 1477 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 1478 $custom_image_header = new Custom_Image_Header( $admin_header_callback, $admin_image_div_callback ); 1479 add_action( 'admin_menu', array( &$custom_image_header, 'init' ) ); 1480 } 1481 1482 /** 1483 * Remove image header support. 1484 * 1485 * @since 3.1.0 1486 * @see add_custom_image_header() 1487 * 1488 * @return bool Whether support was removed. 1489 */ 1490 function remove_custom_image_header() { 1491 if ( ! current_theme_supports( 'custom-header' ) ) 1492 return false; 1493 1494 $callback = get_theme_support( 'custom-header' ); 1495 remove_action( 'wp_head', $callback[0]['callback'] ); 1496 _remove_theme_support( 'custom-header' ); 1497 remove_theme_support( 'custom-header-uploads' ); 1498 1499 if ( is_admin() ) { 1500 remove_action( 'admin_menu', array( &$GLOBALS['custom_image_header'], 'init' ) ); 1501 unset( $GLOBALS['custom_image_header'] ); 1502 } 1503 1504 return true; 1411 1505 } 1412 1506 … … 1433 1527 * @since 3.0.0 1434 1528 * 1435 * @param string|array The header string id (key of array) to remove, or an array thereof.1529 * @param string|array $header The header string id (key of array) to remove, or an array thereof. 1436 1530 * @return True on success, false on failure. 1437 1531 */ … … 1508 1602 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional. 1509 1603 */ 1510 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {1511 if ( isset( $GLOBALS['custom_background']) )1604 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) { 1605 if ( isset( $GLOBALS['custom_background'] ) ) 1512 1606 return; 1513 1607 1514 if ( empty( $header_callback) )1608 if ( empty( $header_callback ) ) 1515 1609 $header_callback = '_custom_background_cb'; 1516 1610 1517 add_action( 'wp_head', $header_callback);1518 1519 add_theme_support( 'custom-background' );1611 add_action( 'wp_head', $header_callback ); 1612 1613 add_theme_support( 'custom-background', array( 'callback' => $header_callback ) ); 1520 1614 1521 1615 if ( ! is_admin() ) 1522 1616 return; 1523 require_once(ABSPATH . 'wp-admin/custom-background.php'); 1524 $GLOBALS['custom_background'] =& new Custom_Background($admin_header_callback, $admin_image_div_callback); 1525 add_action('admin_menu', array(&$GLOBALS['custom_background'], 'init')); 1617 require_once( ABSPATH . 'wp-admin/custom-background.php' ); 1618 $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback ); 1619 add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) ); 1620 } 1621 1622 /** 1623 * Remove custom background support. 1624 * 1625 * @since 3.1.0 1626 * @see add_custom_background() 1627 * 1628 * @return bool Whether support was removed. 1629 */ 1630 function remove_custom_background() { 1631 if ( ! current_theme_supports( 'custom-background' ) ) 1632 return false; 1633 1634 $callback = get_theme_support( 'custom-background' ); 1635 remove_action( 'wp_head', $callback[0]['callback'] ); 1636 _remove_theme_support( 'custom-background' ); 1637 1638 if ( is_admin() ) { 1639 remove_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) ); 1640 unset( $GLOBALS['custom_background'] ); 1641 } 1642 1643 return true; 1526 1644 } 1527 1645 … … 1574 1692 * the theme root. It also accepts an array of stylesheets. 1575 1693 * It is optional and defaults to 'editor-style.css'. 1694 * 1695 * Supports RTL stylesheets automatically by searching for the -rtl prefix, e.g. 1696 * editor-style-rtl.css. If an array of stylesheets is passed to add_editor_style(), 1697 * RTL is only added for the first stylesheet. 1576 1698 * 1577 1699 * @since 3.0.0 … … 1599 1721 1600 1722 /** 1723 * Removes all visual editor stylesheets. 1724 * 1725 * @since 3.1.0 1726 * 1727 * @return bool True on success, false if there were no stylesheets to remove. 1728 */ 1729 function remove_editor_styles() { 1730 if ( ! current_theme_supports( 'editor-style' ) ) 1731 return false; 1732 _remove_theme_support( 'editor-style' ); 1733 if ( is_admin() ) 1734 $GLOBALS['editor_styles'] = array(); 1735 return true; 1736 } 1737 1738 /** 1601 1739 * Allows a theme to register its support of a certain feature 1602 1740 * … … 1615 1753 else 1616 1754 $_wp_theme_features[$feature] = array_slice( func_get_args(), 1 ); 1755 1756 if ( $feature == 'post-formats' && is_array( $_wp_theme_features[$feature][0] ) ) 1757 $_wp_theme_features[$feature][0] = array_intersect( $_wp_theme_features[$feature][0], array_keys( get_post_format_slugs() ) ); 1758 } 1759 1760 /** 1761 * Gets the theme support arguments passed when registering that support 1762 * 1763 * @since 3.1 1764 * @param string $feature the feature to check 1765 * @return array The array of extra arguments 1766 */ 1767 function get_theme_support( $feature ) { 1768 global $_wp_theme_features; 1769 if ( !isset( $_wp_theme_features[$feature] ) ) 1770 return false; 1771 else 1772 return $_wp_theme_features[$feature]; 1617 1773 } 1618 1774 … … 1632 1788 if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) ) 1633 1789 return false; 1634 1790 return _remove_theme_support( $feature ); 1791 } 1792 1793 /** 1794 * Do not use. Removes theme support internally, ignorant of the blacklist. 1795 * 1796 * @access private 1797 * @since 3.1.0 1798 */ 1799 function _remove_theme_support( $feature ) { 1635 1800 global $_wp_theme_features; 1636 1801
Note: See TracChangeset
for help on using the changeset viewer.