Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r15436 r17316  
    167167 * whitelisted. The <b>'a'</b> element with the <em>href</em> and <em>title</em>
    168168 * 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. The
     169 * <b>acronym</b> element with the <em>title</em> attribute allowed. The
    170170 * <b>code</b>, <b>em</b>, and <b>strong</b> elements also allowed.
    171171 *
     
    240240                        $theme_data['Author'] = $theme_data['AuthorName'];
    241241                } 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'] );
    243243                }
    244244        }
     
    267267        if ( isset($wp_themes) )
    268268                return $wp_themes;
    269 
    270         /* Register the default root as a theme directory */
    271         register_theme_directory( get_theme_root() );
    272269
    273270        if ( !$theme_files = search_theme_directories() )
     
    389386                $stylesheet_files = array_unique($stylesheet_files);
    390387
    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;
    393390
    394391                if ( empty($template_dir) )
     
    400397                // a new theme directory and the theme header is not updated.  Whichever
    401398                // 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.
    403400                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 ] ) {
    406407                                // If another theme has claimed to be one of our default themes, move
    407408                                // them aside.
     
    467468 * @since 2.9.0
    468469 *
    469  * @return array Theme roots
     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.
    470471 */
    471472function get_theme_roots() {
     473        global $wp_theme_directories;
     474
     475        if ( count($wp_theme_directories) <= 1 )
     476                return '/themes';
     477
    472478        $theme_roots = get_site_transient( 'theme_roots' );
    473479        if ( false === $theme_roots ) {
     
    514520        $current_template = get_option('template');
    515521        $current_stylesheet = get_option('stylesheet');
    516         $current_theme = 'WordPress Default';
     522        $current_theme = 'Twenty Ten';
    517523
    518524        if ( $themes ) {
     
    589595                while ( ($theme_dir = readdir($themes_dir)) !== false ) {
    590596                        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' )
    592598                                        continue;
    593599
     
    612618                                        while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) {
    613619                                                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' )
    615621                                                                continue;
    616622
     
    646652 *
    647653 * @since 1.5.0
    648  * @param $stylesheet_or_template The stylesheet or template name of the theme
    649654 * @uses apply_filters() Calls 'theme_root' filter on path.
    650655 *
     656 * @param string $stylesheet_or_template The stylesheet or template name of the theme
    651657 * @return string Theme path.
    652658 */
    653659function 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;
    659663                else
    660664                        $theme_root = WP_CONTENT_DIR . '/themes';
     
    672676 *
    673677 * @since 1.5.0
    674  * @param $stylesheet_or_template The stylesheet or template name of the theme
    675  *
     678 *
     679 * @param string $stylesheet_or_template The stylesheet or template name of the theme
    676680 * @return string Themes URI.
    677681 */
    678682function 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 {
    684689                $theme_root_uri = content_url( 'themes' );
     690        }
    685691
    686692        return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template );
     
    688694
    689695/**
    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 */
     703function 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
    695734 * without the use of the other get_*_template() functions.
    696735 *
    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  *
    708736 * @since 1.5.0
    709737 *
    710738 * @param string $type Filename without extension.
     739 * @param array $templates An optional list of template candidates
    711740 * @return string Full path to file.
    712741 */
    713 function get_query_template($type) {
     742function get_query_template( $type, $templates = array() ) {
    714743        $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 ) );
    716749}
    717750
     
    746779 */
    747780function 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 );
    749790}
    750791
     
    757798 */
    758799function 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();
    762801
    763802        $templates = array();
    764803
    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";
    769806        $templates[] = 'author.php';
    770807
    771         $template = locate_template( $templates );
    772         return apply_filters( 'author_template', $template );
     808        return get_query_template( 'author', $templates );
    773809}
    774810
     
    786822 */
    787823function get_category_template() {
    788         $cat_ID = absint( get_query_var('cat') );
    789         $category = get_category( $cat_ID );
     824        $category = get_queried_object();
    790825
    791826        $templates = array();
    792827
    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";
    797830        $templates[] = "category.php";
    798831
    799         $template = locate_template($templates);
    800         return apply_filters('category_template', $template);
     832        return get_query_template( 'category', $templates );
    801833}
    802834
     
    814846 */
    815847function get_tag_template() {
    816         $tag_id = absint( get_query_var('tag_id') );
    817         $tag_name = get_query_var('tag');
     848        $tag = get_queried_object();
    818849
    819850        $templates = array();
    820851
    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";
    825854        $templates[] = "tag.php";
    826855
    827         $template = locate_template($templates);
    828         return apply_filters('tag_template', $template);
     856        return get_query_template( 'tag', $templates );
    829857}
    830858
     
    841869 * index.php.
    842870 *
    843  * @since unknown (2.6.0 most likely)
     871 * @since 2.5.0
    844872 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
    845873 *
     
    847875 */
    848876function get_taxonomy_template() {
    849         $taxonomy = get_query_var('taxonomy');
    850         $term = get_query_var('term');
     877        $term = get_queried_object();
     878        $taxonomy = $term->taxonomy;
    851879
    852880        $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";
    858884        $templates[] = "taxonomy.php";
    859885
    860         $template = locate_template($templates);
    861         return apply_filters('taxonomy_template', $template);
     886        return get_query_template( 'taxonomy', $templates );
    862887}
    863888
     
    886911 */
    887912function 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 );
    890916}
    891917
     
    901927 */
    902928function 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 );
    904932}
    905933
     
    916944 */
    917945function get_page_template() {
    918         global $wp_query;
    919 
    920         $id = (int) $wp_query->get_queried_object_id();
     946        $id = get_queried_object_id();
    921947        $template = get_post_meta($id, '_wp_page_template', true);
    922948        $pagename = get_query_var('pagename');
     
    924950        if ( !$pagename && $id > 0 ) {
    925951                // 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();
    927953                $pagename = $post->post_name;
    928954        }
     
    940966        $templates[] = "page.php";
    941967
    942         return apply_filters('page_template', locate_template($templates));
     968        return get_query_template( 'page', $templates );
    943969}
    944970
     
    973999 */
    9741000function 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 );
    9801009}
    9811010
     
    10201049 */
    10211050function get_comments_popup_template() {
    1022         $template = locate_template(array("comments-popup.php"));
     1051        $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
    10231052
    10241053        // Backward compat code will be removed in a future release
     
    10261055                $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
    10271056
    1028         return apply_filters('comments_popup_template', $template);
     1057        return $template;
    10291058}
    10301059
     
    10371066 * @since 2.7.0
    10381067 *
    1039  * @param array $template_names Array of template files to search for in priority order.
     1068 * @param string|array $template_names Template file(s) to search for, in order.
    10401069 * @param bool $load If true the template file will be loaded if it is found.
    10411070 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
     
    10431072 */
    10441073function locate_template($template_names, $load = false, $require_once = true ) {
    1045         if ( !is_array($template_names) )
    1046                 return '';
    1047 
    10481074        $located = '';
    1049         foreach ( $template_names as $template_name ) {
     1075        foreach ( (array) $template_names as $template_name ) {
    10501076                if ( !$template_name )
    10511077                        continue;
     
    11151141        if ( !current_user_can( 'switch_themes' ) )
    11161142                return;
     1143
     1144        // Admin Thickbox requests
     1145        if ( isset( $_GET['preview_iframe'] ) )
     1146                show_admin_bar( false );
    11171147
    11181148        $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']);
     
    12081238 * Switches current theme to new template and stylesheet names.
    12091239 *
    1210  * @since unknown
     1240 * @since 2.5.0
    12111241 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
    12121242 *
     
    12151245 */
    12161246function switch_theme($template, $stylesheet) {
     1247        global $wp_theme_directories;
     1248
    12171249        update_option('template', $template);
    12181250        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        }
    12191255        delete_option('current_theme');
    12201256        $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        }
    12211261        do_action('switch_theme', $theme);
    12221262}
     
    12501290        }
    12511291
     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
    12521297        return true;
     1298}
     1299
     1300/**
     1301 * Retrieve all theme modifications.
     1302 *
     1303 * @since 3.1.0
     1304 *
     1305 * @return array Theme modifications.
     1306 */
     1307function 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;
    12531318}
    12541319
     
    12681333 * @return string
    12691334 */
    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()) );
     1335function 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() ) );
    12791342}
    12801343
     
    12871350 * @param string $value theme modification value.
    12881351 */
    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');
     1352function 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 );
    12981359}
    12991360
     
    13101371 */
    13111372function 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 ] ) )
    13171376                return;
    13181377
    1319         unset($mods[$name]);
    1320 
    1321         if ( empty($mods) )
     1378        unset( $mods[ $name ] );
     1379
     1380        if ( empty( $mods ) )
    13221381                return remove_theme_mods();
    13231382
    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 );
    13261385}
    13271386
     
    13321391 */
    13331392function 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() );
    13371395}
    13381396
     
    13691427 */
    13701428function 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;
    13741439}
    13751440
     
    13981463 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional.
    13991464 */
    1400 function add_custom_image_header($header_callback, $admin_header_callback, $admin_image_div_callback = '') {
    1401         if ( ! empty($header_callback) )
     1465function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '' ) {
     1466        if ( ! empty( $header_callback ) )
    14021467                add_action('wp_head', $header_callback);
    14031468
    1404         add_theme_support( 'custom-header' );
     1469        add_theme_support( 'custom-header', array( 'callback' => $header_callback ) );
     1470        add_theme_support( 'custom-header-uploads' );
    14051471
    14061472        if ( ! is_admin() )
    14071473                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 */
     1490function 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;
    14111505}
    14121506
     
    14331527 * @since 3.0.0
    14341528 *
    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.
    14361530 * @return True on success, false on failure.
    14371531 */
     
    15081602 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional.
    15091603 */
    1510 function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {
    1511         if ( isset($GLOBALS['custom_background']) )
     1604function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) {
     1605        if ( isset( $GLOBALS['custom_background'] ) )
    15121606                return;
    15131607
    1514         if ( empty($header_callback) )
     1608        if ( empty( $header_callback ) )
    15151609                $header_callback = '_custom_background_cb';
    15161610
    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 ) );
    15201614
    15211615        if ( ! is_admin() )
    15221616                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 */
     1630function 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;
    15261644}
    15271645
     
    15741692 * the theme root. It also accepts an array of stylesheets.
    15751693 * 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.
    15761698 *
    15771699 * @since 3.0.0
     
    15991721
    16001722/**
     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 */
     1729function 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/**
    16011739 * Allows a theme to register its support of a certain feature
    16021740 *
     
    16151753        else
    16161754                $_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 */
     1767function 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];
    16171773}
    16181774
     
    16321788        if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) )
    16331789                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 */
     1799function _remove_theme_support( $feature ) {
    16351800        global $_wp_theme_features;
    16361801
Note: See TracChangeset for help on using the changeset viewer.