Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-includes/theme.php

    r17316 r15436  
    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'], esc_attr__( 'Visit author homepage' ), $theme_data['AuthorName'] );
     242            $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], __( 'Visit author homepage' ), $theme_data['AuthorName'] );
    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() );
    269272
    270273    if ( !$theme_files = search_theme_directories() )
     
    386389        $stylesheet_files = array_unique($stylesheet_files);
    387390
    388         $template_dir = $template_directory;
    389         $stylesheet_dir = $theme_root . '/' . $stylesheet;
     391        $template_dir = dirname($template_files[0]);
     392        $stylesheet_dir = dirname($stylesheet_files[0]);
    390393
    391394        if ( empty($template_dir) )
     
    397400        // a new theme directory and the theme header is not updated.  Whichever
    398401        // theme is first keeps the name.  Subsequent themes get a suffix applied.
    399         // The Twenty Ten, Default and Classic themes always trump their pretenders.
     402        // The Default and Classic themes always trump their pretenders.
    400403        if ( isset($wp_themes[$name]) ) {
    401             $trump_cards = array(
    402                 'classic'   => 'WordPress Classic',
    403                 'default'   => 'WordPress Default',
    404                 'twentyten' => 'Twenty Ten',
    405             );
    406             if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) {
     404            if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
     405                     ('default' == $stylesheet || 'classic' == $stylesheet) ) {
    407406                // If another theme has claimed to be one of our default themes, move
    408407                // them aside.
     
    468467 * @since 2.9.0
    469468 *
    470  * @return array|string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
     469 * @return array Theme roots
    471470 */
    472471function get_theme_roots() {
    473     global $wp_theme_directories;
    474 
    475     if ( count($wp_theme_directories) <= 1 )
    476         return '/themes';
    477 
    478472    $theme_roots = get_site_transient( 'theme_roots' );
    479473    if ( false === $theme_roots ) {
     
    520514    $current_template = get_option('template');
    521515    $current_stylesheet = get_option('stylesheet');
    522     $current_theme = 'Twenty Ten';
     516    $current_theme = 'WordPress Default';
    523517
    524518    if ( $themes ) {
     
    595589        while ( ($theme_dir = readdir($themes_dir)) !== false ) {
    596590            if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
    597                 if ( $theme_dir[0] == '.' || $theme_dir == 'CVS' )
     591                if ( $theme_dir{0} == '.' || $theme_dir == 'CVS' )
    598592                    continue;
    599593
     
    618612                    while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) {
    619613                        if ( is_dir( $subdir . '/' . $theme_subdir) && is_readable($subdir . '/' . $theme_subdir) ) {
    620                             if ( $theme_subdir[0] == '.' || $theme_subdir == 'CVS' )
     614                            if ( $theme_subdir{0} == '.' || $theme_subdir == 'CVS' )
    621615                                continue;
    622616
     
    652646 *
    653647 * @since 1.5.0
     648 * @param $stylesheet_or_template The stylesheet or template name of the theme
    654649 * @uses apply_filters() Calls 'theme_root' filter on path.
    655650 *
    656  * @param string $stylesheet_or_template The stylesheet or template name of the theme
    657651 * @return string Theme path.
    658652 */
    659653function get_theme_root( $stylesheet_or_template = false ) {
    660     if ( $stylesheet_or_template ) {
    661         if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
    662             $theme_root = WP_CONTENT_DIR . $theme_root;
     654    if ($stylesheet_or_template) {
     655        $theme_roots = get_theme_roots();
     656
     657        if ( ! empty( $theme_roots[$stylesheet_or_template] ) )
     658            $theme_root = WP_CONTENT_DIR . $theme_roots[$stylesheet_or_template];
    663659        else
    664660            $theme_root = WP_CONTENT_DIR . '/themes';
     
    676672 *
    677673 * @since 1.5.0
    678  *
    679  * @param string $stylesheet_or_template The stylesheet or template name of the theme
     674 * @param $stylesheet_or_template The stylesheet or template name of the theme
     675 *
    680676 * @return string Themes URI.
    681677 */
    682678function get_theme_root_uri( $stylesheet_or_template = false ) {
    683     if ( $stylesheet_or_template ) {
    684         if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
    685             $theme_root_uri = content_url( $theme_root );
    686         else
    687             $theme_root_uri = content_url( 'themes' );
    688     } else {
     679    $theme_roots = get_theme_roots();
     680
     681    if ( isset( $theme_roots[$stylesheet_or_template] ) && $theme_roots[$stylesheet_or_template] )
     682        $theme_root_uri = content_url( $theme_roots[$stylesheet_or_template] );
     683    else
    689684        $theme_root_uri = content_url( 'themes' );
    690     }
    691685
    692686    return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template );
     
    694688
    695689/**
    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
     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
    734695 * without the use of the other get_*_template() functions.
    735696 *
     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 *
    736708 * @since 1.5.0
    737709 *
    738710 * @param string $type Filename without extension.
    739  * @param array $templates An optional list of template candidates
    740711 * @return string Full path to file.
    741712 */
    742 function get_query_template( $type, $templates = array() ) {
     713function get_query_template($type) {
    743714    $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
    744 
    745     if ( empty( $templates ) )
    746         $templates = array("{$type}.php");
    747 
    748     return apply_filters( "{$type}_template", locate_template( $templates ) );
     715    return apply_filters("{$type}_template", locate_template(array("{$type}.php")));
    749716}
    750717
     
    779746 */
    780747function get_archive_template() {
    781     $post_type = get_query_var( 'post_type' );
     748    return get_query_template('archive');
     749}
     750
     751/**
     752 * Retrieve path of author template in current or parent template.
     753 *
     754 * @since 1.5.0
     755 *
     756 * @return string
     757 */
     758function get_author_template() {
     759    $author_id = absint( get_query_var( 'author' ) );
     760    $author = get_user_by( 'id', $author_id );
     761    $author = $author->user_nicename;
    782762
    783763    $templates = array();
    784764
    785     if ( $post_type )
    786         $templates[] = "archive-{$post_type}.php";
    787     $templates[] = 'archive.php';
    788 
    789     return get_query_template( 'archive', $templates );
    790 }
    791 
    792 /**
    793  * Retrieve path of author template in current or parent template.
    794  *
    795  * @since 1.5.0
    796  *
    797  * @return string
    798  */
    799 function get_author_template() {
    800     $author = get_queried_object();
    801 
    802     $templates = array();
    803 
    804     $templates[] = "author-{$author->user_nicename}.php";
    805     $templates[] = "author-{$author->ID}.php";
     765    if ( $author )
     766        $templates[] = "author-{$author}.php";
     767    if ( $author_id )
     768        $templates[] = "author-{$author_id}.php";
    806769    $templates[] = 'author.php';
    807770
    808     return get_query_template( 'author', $templates );
     771    $template = locate_template( $templates );
     772    return apply_filters( 'author_template', $template );
    809773}
    810774
     
    822786 */
    823787function get_category_template() {
    824     $category = get_queried_object();
     788    $cat_ID = absint( get_query_var('cat') );
     789    $category = get_category( $cat_ID );
    825790
    826791    $templates = array();
    827792
    828     $templates[] = "category-{$category->slug}.php";
    829     $templates[] = "category-{$category->term_id}.php";
     793    if ( !is_wp_error($category) )
     794        $templates[] = "category-{$category->slug}.php";
     795
     796    $templates[] = "category-$cat_ID.php";
    830797    $templates[] = "category.php";
    831798
    832     return get_query_template( 'category', $templates );
     799    $template = locate_template($templates);
     800    return apply_filters('category_template', $template);
    833801}
    834802
     
    846814 */
    847815function get_tag_template() {
    848     $tag = get_queried_object();
     816    $tag_id = absint( get_query_var('tag_id') );
     817    $tag_name = get_query_var('tag');
    849818
    850819    $templates = array();
    851820
    852     $templates[] = "tag-{$tag->slug}.php";
    853     $templates[] = "tag-{$tag->term_id}.php";
     821    if ( $tag_name )
     822        $templates[] = "tag-$tag_name.php";
     823    if ( $tag_id )
     824        $templates[] = "tag-$tag_id.php";
    854825    $templates[] = "tag.php";
    855826
    856     return get_query_template( 'tag', $templates );
     827    $template = locate_template($templates);
     828    return apply_filters('tag_template', $template);
    857829}
    858830
     
    869841 * index.php.
    870842 *
    871  * @since 2.5.0
     843 * @since unknown (2.6.0 most likely)
    872844 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
    873845 *
     
    875847 */
    876848function get_taxonomy_template() {
    877     $term = get_queried_object();
    878     $taxonomy = $term->taxonomy;
     849    $taxonomy = get_query_var('taxonomy');
     850    $term = get_query_var('term');
    879851
    880852    $templates = array();
    881 
    882     $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
    883     $templates[] = "taxonomy-$taxonomy.php";
     853    if ( $taxonomy && $term )
     854        $templates[] = "taxonomy-$taxonomy-$term.php";
     855    if ( $taxonomy )
     856        $templates[] = "taxonomy-$taxonomy.php";
     857
    884858    $templates[] = "taxonomy.php";
    885859
    886     return get_query_template( 'taxonomy', $templates );
     860    $template = locate_template($templates);
     861    return apply_filters('taxonomy_template', $template);
    887862}
    888863
     
    911886 */
    912887function get_home_template() {
    913     $templates = array( 'home.php', 'index.php' );
    914 
    915     return get_query_template( 'home', $templates );
     888    $template = locate_template(array('home.php', 'index.php'));
     889    return apply_filters('home_template', $template);
    916890}
    917891
     
    927901 */
    928902function get_front_page_template() {
    929     $templates = array('front-page.php');
    930 
    931     return get_query_template( 'front_page', $templates );
     903    return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) );
    932904}
    933905
     
    944916 */
    945917function get_page_template() {
    946     $id = get_queried_object_id();
     918    global $wp_query;
     919
     920    $id = (int) $wp_query->get_queried_object_id();
    947921    $template = get_post_meta($id, '_wp_page_template', true);
    948922    $pagename = get_query_var('pagename');
     
    950924    if ( !$pagename && $id > 0 ) {
    951925        // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
    952         $post = get_queried_object();
     926        $post = $wp_query->get_queried_object();
    953927        $pagename = $post->post_name;
    954928    }
     
    966940    $templates[] = "page.php";
    967941
    968     return get_query_template( 'page', $templates );
     942    return apply_filters('page_template', locate_template($templates));
    969943}
    970944
     
    999973 */
    1000974function get_single_template() {
    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 );
     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));
    1009980}
    1010981
     
    10491020 */
    10501021function get_comments_popup_template() {
    1051     $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
     1022    $template = locate_template(array("comments-popup.php"));
    10521023
    10531024    // Backward compat code will be removed in a future release
     
    10551026        $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
    10561027
    1057     return $template;
     1028    return apply_filters('comments_popup_template', $template);
    10581029}
    10591030
     
    10661037 * @since 2.7.0
    10671038 *
    1068  * @param string|array $template_names Template file(s) to search for, in order.
     1039 * @param array $template_names Array of template files to search for in priority order.
    10691040 * @param bool $load If true the template file will be loaded if it is found.
    10701041 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
     
    10721043 */
    10731044function locate_template($template_names, $load = false, $require_once = true ) {
     1045    if ( !is_array($template_names) )
     1046        return '';
     1047
    10741048    $located = '';
    1075     foreach ( (array) $template_names as $template_name ) {
     1049    foreach ( $template_names as $template_name ) {
    10761050        if ( !$template_name )
    10771051            continue;
     
    11411115    if ( !current_user_can( 'switch_themes' ) )
    11421116        return;
    1143 
    1144     // Admin Thickbox requests
    1145     if ( isset( $_GET['preview_iframe'] ) )
    1146         show_admin_bar( false );
    11471117
    11481118    $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']);
     
    12381208 * Switches current theme to new template and stylesheet names.
    12391209 *
    1240  * @since 2.5.0
     1210 * @since unknown
    12411211 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
    12421212 *
     
    12451215 */
    12461216function switch_theme($template, $stylesheet) {
    1247     global $wp_theme_directories;
    1248 
    12491217    update_option('template', $template);
    12501218    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     }
    12551219    delete_option('current_theme');
    12561220    $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     }
    12611221    do_action('switch_theme', $theme);
    12621222}
     
    12901250    }
    12911251
    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 
    12971252    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;
    13181253}
    13191254
     
    13331268 * @return string
    13341269 */
    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() ) );
     1270function 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()) );
    13421279}
    13431280
     
    13501287 * @param string $value theme modification value.
    13511288 */
    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 );
     1289function 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');
    13591298}
    13601299
     
    13711310 */
    13721311function remove_theme_mod( $name ) {
    1373     $mods = get_theme_mods();
    1374 
    1375     if ( ! isset( $mods[ $name ] ) )
     1312    $theme = get_current_theme();
     1313
     1314    $mods = get_option("mods_$theme");
     1315
     1316    if ( !isset($mods[$name]) )
    13761317        return;
    13771318
    1378     unset( $mods[ $name ] );
    1379 
    1380     if ( empty( $mods ) )
     1319    unset($mods[$name]);
     1320
     1321    if ( empty($mods) )
    13811322        return remove_theme_mods();
    13821323
    1383     $theme = get_option( 'stylesheet' );
    1384     update_option( "theme_mods_$theme", $mods );
     1324    update_option("mods_$theme", $mods);
     1325    wp_cache_delete("mods_$theme", 'options');
    13851326}
    13861327
     
    13911332 */
    13921333function remove_theme_mods() {
    1393     delete_option( 'theme_mods_' . get_option( 'stylesheet' ) );
    1394     delete_option( 'mods_' . get_current_theme() );
     1334    $theme = get_current_theme();
     1335
     1336    delete_option("mods_$theme");
    13951337}
    13961338
     
    14271369 */
    14281370function get_header_image() {
    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;
     1371    $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : '';
     1372
     1373    return get_theme_mod('header_image', $default);
    14391374}
    14401375
     
    14631398 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional.
    14641399 */
    1465 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '' ) {
    1466     if ( ! empty( $header_callback ) )
     1400function add_custom_image_header($header_callback, $admin_header_callback, $admin_image_div_callback = '') {
     1401    if ( ! empty($header_callback) )
    14671402        add_action('wp_head', $header_callback);
    14681403
    1469     add_theme_support( 'custom-header', array( 'callback' => $header_callback ) );
    1470     add_theme_support( 'custom-header-uploads' );
     1404    add_theme_support( 'custom-header' );
    14711405
    14721406    if ( ! is_admin() )
    14731407        return;
    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;
     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'));
    15051411}
    15061412
     
    15271433 * @since 3.0.0
    15281434 *
    1529  * @param string|array $header The header string id (key of array) to remove, or an array thereof.
     1435 * @param string|array The header string id (key of array) to remove, or an array thereof.
    15301436 * @return True on success, false on failure.
    15311437 */
     
    16021508 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional.
    16031509 */
    1604 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) {
    1605     if ( isset( $GLOBALS['custom_background'] ) )
     1510function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {
     1511    if ( isset($GLOBALS['custom_background']) )
    16061512        return;
    16071513
    1608     if ( empty( $header_callback ) )
     1514    if ( empty($header_callback) )
    16091515        $header_callback = '_custom_background_cb';
    16101516
    1611     add_action( 'wp_head', $header_callback );
    1612 
    1613     add_theme_support( 'custom-background', array( 'callback' => $header_callback ) );
     1517    add_action('wp_head', $header_callback);
     1518
     1519    add_theme_support( 'custom-background' );
    16141520
    16151521    if ( ! is_admin() )
    16161522        return;
    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;
     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'));
    16441526}
    16451527
     
    16931575 * It is optional and defaults to 'editor-style.css'.
    16941576 *
    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.
    1698  *
    16991577 * @since 3.0.0
    17001578 *
     
    17211599
    17221600/**
    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 /**
    17391601 * Allows a theme to register its support of a certain feature
    17401602 *
     
    17531615    else
    17541616        $_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];
    17731617}
    17741618
     
    17881632    if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) )
    17891633        return false;
    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 ) {
     1634
    18001635    global $_wp_theme_features;
    18011636
Note: See TracChangeset for help on using the changeset viewer.