Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r15461 r17187  
    152152        do_action( 'get_search_form' );
    153153
    154         $search_form_template = locate_template(array('searchform.php'));
     154        $search_form_template = locate_template('searchform.php');
    155155        if ( '' != $search_form_template ) {
    156156                require($search_form_template);
    … …  
    200200 * Returns the URL that allows the user to log out of the site
    201201 *
    202  * @since 2.7
     202 * @since 2.7.0
    203203 * @uses wp_nonce_url() To protect against CSRF
    204204 * @uses site_url() To generate the log in URL
    … …  
    224224 * Returns the URL that allows the user to log in to the site
    225225 *
    226  * @since 2.7
     226 * @since 2.7.0
    227227 * @uses site_url() To generate the log in URL
    228228 * @uses apply_filters() calls 'login_url' hook on final login url
    … …  
    272272        $form = '
    273273                <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . site_url( 'wp-login.php', 'login' ) . '" method="post">
    274                         ' . apply_filters( 'login_form_top', '' ) . '
     274                        ' . apply_filters( 'login_form_top', '', $args ) . '
    275275                        <p class="login-username">
    276276                                <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
    … …  
    281281                                <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" tabindex="20" />
    282282                        </p>
    283                         ' . apply_filters( 'login_form_middle', '' ) . '
     283                        ' . apply_filters( 'login_form_middle', '', $args ) . '
    284284                        ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever" tabindex="90"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
    285285                        <p class="login-submit">
    … …  
    287287                                <input type="hidden" name="redirect_to" value="' . esc_attr( $args['redirect'] ) . '" />
    288288                        </p>
    289                         ' . apply_filters( 'login_form_bottom', '' ) . '
     289                        ' . apply_filters( 'login_form_bottom', '', $args ) . '
    290290                </form>';
    291291
    … …  
    382382 * The possible values for the 'show' parameter are listed below.
    383383 * <ol>
    384  * <li><strong>url<strong> - Blog URI to homepage.</li>
     384 * <li><strong>url</strong> - Blog URI to homepage.</li>
    385385 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
    386386 * <li><strong>description</strong> - Secondary title</li>
    … …  
    493493
    494494/**
     495 * Retrieve the current blog id
     496 *
     497 * @since 3.1.0
     498 *
     499 * @return int Blog id
     500 */
     501function get_current_blog_id() {
     502        global $blog_id;
     503        return absint($blog_id);
     504}
     505
     506/**
    495507 * Display or retrieve page title for all areas of blog.
    496508 *
    … …  
    515527 */
    516528function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
    517         global $wpdb, $wp_locale, $wp_query;
    518 
    519         $cat = get_query_var('cat');
    520         $tag = get_query_var('tag_id');
    521         $category_name = get_query_var('category_name');
    522         $author = get_query_var('author');
    523         $author_name = get_query_var('author_name');
     529        global $wpdb, $wp_locale;
     530
    524531        $m = get_query_var('m');
    525532        $year = get_query_var('year');
    … …  
    531538        $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
    532539
    533         // If there's a category
    534         if ( !empty($cat) ) {
    535                         // category exclusion
    536                         if ( !stristr($cat,'-') )
    537                                 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
    538         } elseif ( !empty($category_name) ) {
    539                 if ( stristr($category_name,'/') ) {
    540                                 $category_name = explode('/',$category_name);
    541                                 if ( $category_name[count($category_name)-1] )
    542                                         $category_name = $category_name[count($category_name)-1]; // no trailing slash
    543                                 else
    544                                         $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
    545                 }
    546                 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
    547                 if ( $cat )
    548                         $title = apply_filters('single_cat_title', $cat->name);
    549         }
    550 
    551         if ( !empty($tag) ) {
    552                 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
    553                 if ( is_wp_error( $tag ) )
    554                         return $tag;
    555                 if ( ! empty($tag->name) )
    556                         $title = apply_filters('single_tag_title', $tag->name);
     540        // If there is a post
     541        if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
     542                $title = single_post_title( '', false );
     543        }
     544
     545        // If there's a category or tag
     546        if ( is_category() || is_tag() ) {
     547                $title = single_term_title( '', false );
     548        }
     549
     550        // If there's a taxonomy
     551        if ( is_tax() ) {
     552                $term = get_queried_object();
     553                $tax = get_taxonomy( $term->taxonomy );
     554                $title = single_term_title( $tax->labels->name . $t_sep, false );
    557555        }
    558556
    559557        // If there's an author
    560         if ( !empty($author) ) {
    561                 $title = get_userdata($author);
    562                 $title = $title->display_name;
    563         }
    564         if ( !empty($author_name) ) {
    565                 // We do a direct query here because we don't cache by nicename.
    566                 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
    567         }
     558        if ( is_author() ) {
     559                $author = get_queried_object();
     560                $title = $author->display_name;
     561        }
     562
     563        // If there's a post type archive
     564        if ( is_post_type_archive() )
     565                $title = post_type_archive_title( '', false );
    568566
    569567        // If there's a month
    570         if ( !empty($m) ) {
     568        if ( is_archive() && !empty($m) ) {
    571569                $my_year = substr($m, 0, 4);
    572570                $my_month = $wp_locale->get_month(substr($m, 4, 2));
    … …  
    575573        }
    576574
    577         if ( !empty($year) ) {
     575        // If there's a year
     576        if ( is_archive() && !empty($year) ) {
    578577                $title = $year;
    579578                if ( !empty($monthnum) )
    … …  
    583582        }
    584583
    585         // If there is a post
    586         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
    587                 $post = $wp_query->get_queried_object();
    588                 $title = apply_filters( 'single_post_title', $post->post_title );
    589         }
    590 
    591         // If there's a taxonomy
    592         if ( is_tax() ) {
    593                 $taxonomy = get_query_var( 'taxonomy' );
    594                 $tax = get_taxonomy( $taxonomy );
    595                 $term = $wp_query->get_queried_object();
    596                 $term = $term->name;
    597                 $title = $tax->labels->name . $t_sep . $term;
    598         }
    599 
    600         //If it's a search
     584        // If it's a search
    601585        if ( is_search() ) {
    602586                /* translators: 1: separator, 2: search phrase */
    … …  
    604588        }
    605589
     590        // If it's a 404 page
    606591        if ( is_404() ) {
    607592                $title = __('Page not found');
    … …  
    636621 *
    637622 * This is optimized for single.php template file for displaying the post title.
    638  * Only useful for posts, does not support pages for example.
    639623 *
    640624 * It does not support placing the separator after the title, but by leaving the
    … …  
    644628 *
    645629 * @since 0.71
    646  * @uses $wpdb
    647630 *
    648631 * @param string $prefix Optional. What to display before the title.
    … …  
    651634 */
    652635function single_post_title($prefix = '', $display = true) {
    653         global $wp_query, $post;
    654 
    655         if ( ! $post )
    656                 $_post = $wp_query->get_queried_object();
    657         else
    658                 $_post = $post;
     636        $_post = get_queried_object();
    659637
    660638        if ( !isset($_post->post_title) )
    … …  
    669647
    670648/**
     649 * Display or retrieve title for a post type archive.
     650 *
     651 * This is optimized for archive.php and archive-{$post_type}.php template files
     652 * for displaying the title of the post type.
     653 *
     654 * @since 3.1.0
     655 *
     656 * @param string $prefix Optional. What to display before the title.
     657 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     658 * @return string|null Title when retrieving, null when displaying or failure.
     659 */
     660function post_type_archive_title( $prefix = '', $display = true ) {
     661        if ( ! is_post_type_archive() )
     662                return;
     663
     664        $post_type_obj = get_queried_object();
     665        $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
     666
     667        if ( $display )
     668                echo $prefix . $title;
     669        else
     670                return $title;
     671}
     672
     673/**
    671674 * Display or retrieve page title for category archive.
    672675 *
    … …  
    685688 * @return string|null Title when retrieving, null when displaying or failure.
    686689 */
    687 function single_cat_title($prefix = '', $display = true ) {
    688         global $wp_query;
    689 
    690         if ( is_tag() )
    691                 return single_tag_title($prefix, $display);
    692 
    693         if ( !is_category() )
    694                 return;
    695 
    696         $cat = $wp_query->get_queried_object();
    697         $my_cat_name = apply_filters('single_cat_title', $cat->name);
    698         if ( !empty($my_cat_name) ) {
    699                 if ( $display )
    700                         echo $prefix . $my_cat_name;
    701                 else
    702                         return $my_cat_name;
    703         }
     690function single_cat_title( $prefix = '', $display = true ) {
     691        return single_term_title( $prefix, $display );
    704692}
    705693
    … …  
    721709 * @return string|null Title when retrieving, null when displaying or failure.
    722710 */
    723 function single_tag_title($prefix = '', $display = true ) {
    724         global $wp_query;
    725         if ( !is_tag() )
     711function single_tag_title( $prefix = '', $display = true ) {
     712        return single_term_title( $prefix, $display );
     713}
     714
     715/**
     716 * Display or retrieve page title for taxonomy term archive.
     717 *
     718 * Useful for taxonomy term template files for displaying the taxonomy term page title.
     719 * It has less overhead than {@link wp_title()}, because of its limited implementation.
     720 *
     721 * It does not support placing the separator after the title, but by leaving the
     722 * prefix parameter empty, you can set the title separator manually. The prefix
     723 * does not automatically place a space between the prefix, so if there should
     724 * be a space, the parameter value will need to have it at the end.
     725 *
     726 * @since 3.1.0
     727 *
     728 * @param string $prefix Optional. What to display before the title.
     729 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     730 * @return string|null Title when retrieving, null when displaying or failure.
     731 */
     732function single_term_title( $prefix = '', $display = true ) {
     733        $term = get_queried_object();
     734
     735        if ( !$term )
    726736                return;
    727737
    728         $tag = $wp_query->get_queried_object();
    729 
    730         if ( ! $tag )
     738        if ( is_category() )
     739                $term_name = apply_filters( 'single_cat_title', $term->name );
     740        elseif ( is_tag() )
     741                $term_name = apply_filters( 'single_tag_title', $term->name );
     742        elseif ( is_tax() )
     743                $term_name = apply_filters( 'single_term_title', $term->name );
     744        else
    731745                return;
    732746
    733         $my_tag_name = apply_filters('single_tag_title', $tag->name);
    734         if ( !empty($my_tag_name) ) {
    735                 if ( $display )
    736                         echo $prefix . $my_tag_name;
    737                 else
    738                         return $my_tag_name;
    739         }
     747        if ( empty( $term_name ) )
     748                return;
     749
     750        if ( $display )
     751                echo $prefix . $term_name;
     752        else
     753                return $term_name;
    740754}
    741755
    … …  
    11021116                $thisyear = ''.intval(substr($m, 0, 4));
    11031117                $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
    1104                 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
     1118                $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
    11051119        } elseif ( !empty($m) ) {
    11061120                $thisyear = ''.intval(substr($m, 0, 4));
    … …  
    11151129
    11161130        $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
     1131        $last_day = date('t', $unixmonth);
    11171132
    11181133        // Get the next and previous month and year with at least one post
    1119         $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
     1134        $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    11201135                FROM $wpdb->posts
    11211136                WHERE post_date < '$thisyear-$thismonth-01'
    … …  
    11231138                        ORDER BY post_date DESC
    11241139                        LIMIT 1");
    1125         $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
     1140        $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    11261141                FROM $wpdb->posts
    1127                 WHERE post_date >       '$thisyear-$thismonth-01'
    1128                 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
     1142                WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    11291143                AND post_type = 'post' AND post_status = 'publish'
    1130                         ORDER   BY post_date ASC
     1144                        ORDER BY post_date ASC
    11311145                        LIMIT 1");
    11321146
    … …  
    11581172
    11591173        if ( $previous ) {
    1160                 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
     1174                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    11611175        } else {
    11621176                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    … …  
    11801194        // Get days with posts
    11811195        $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    1182                 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
    1183                 AND YEAR(post_date) = '$thisyear'
     1196                FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    11841197                AND post_type = 'post' AND post_status = 'publish'
    1185                 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
     1198                AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    11861199        if ( $dayswithposts ) {
    11871200                foreach ( (array) $dayswithposts as $daywith ) {
    … …  
    12001213        $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
    12011214                ."FROM $wpdb->posts "
    1202                 ."WHERE YEAR(post_date) = '$thisyear' "
    1203                 ."AND MONTH(post_date) = '$thismonth' "
    1204                 ."AND post_date < '".current_time('mysql')."' "
     1215                ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
     1216                ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
    12051217                ."AND post_type = 'post' AND post_status = 'publish'"
    12061218        );
    … …  
    13191331 * Will only output the date if the current post's date is different from the
    13201332 * previous one output.
    1321 
     1333 *
    13221334 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
    13231335 * function is called several times for each post.
    … …  
    13351347 */
    13361348function the_date( $d = '', $before = '', $after = '', $echo = true ) {
    1337         global $day, $previousday;
     1349        global $currentday, $previousday;
    13381350        $the_date = '';
    1339         if ( $day != $previousday ) {
     1351        if ( $currentday != $previousday ) {
    13401352                $the_date .= $before;
    13411353                $the_date .= get_the_date( $d );
    13421354                $the_date .= $after;
    1343                 $previousday = $day;
     1355                $previousday = $currentday;
    13441356
    13451357                $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
    … …  
    15431555 * @param string $before Optional Output before the date.
    15441556 * @param string $after Optional Output after the date.
    1545   */
     1557 */
    15461558function the_weekday_date($before='',$after='') {
    15471559        global $wp_locale, $post, $day, $previousweekday;
    15481560        $the_weekday_date = '';
    1549         if ( $day != $previousweekday ) {
     1561        if ( $currentday != $previousweekday ) {
    15501562                $the_weekday_date .= $before;
    15511563                $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
    15521564                $the_weekday_date .= $after;
    1553                 $previousweekday = $day;
     1565                $previousweekday = $currentday;
    15541566        }
    15551567        $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
    … …  
    16361648                }
    16371649        } elseif ( is_category() ) {
    1638                 $cat_id = intval( get_query_var('cat') );
    1639 
    1640                 $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], get_cat_name( $cat_id ) ));
    1641                 $href = get_category_feed_link( $cat_id );
     1650                $term = get_queried_object();
     1651
     1652                $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name ));
     1653                $href = get_category_feed_link( $term->term_id );
    16421654        } elseif ( is_tag() ) {
    1643                 $tag_id = intval( get_query_var('tag_id') );
    1644                 $tag = get_tag( $tag_id );
    1645 
    1646                 $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $tag->name ));
    1647                 $href = get_tag_feed_link( $tag_id );
     1655                $term = get_queried_object();
     1656
     1657                $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name ));
     1658                $href = get_tag_feed_link( $term->term_id );
    16481659        } elseif ( is_author() ) {
    16491660                $author_id = intval( get_query_var('author') );
    … …  
    20402051 * @param string $name The name of the theme.
    20412052 * @param string $url The url of the css file containing the colour scheme.
    2042  * @param array @colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
     2053 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
    20432054 */
    20442055function wp_admin_css_color($key, $name, $url, $colors = array()) {
    … …  
    20572068 */
    20582069function register_admin_color_schemes() {
    2059         wp_admin_css_color('classic', __('Blue'), admin_url("css/colors-classic.css"), array('#073447', '#21759B', '#EAF3FA', '#BBD8E7'));
    2060         wp_admin_css_color('fresh', __('Gray'), admin_url("css/colors-fresh.css"), array('#464646', '#6D6D6D', '#F1F1F1', '#DFDFDF'));}
     2070        wp_admin_css_color( 'classic', __( 'Blue' ), admin_url( 'css/colors-classic.css' ),
     2071                array( '#5589aa', '#cfdfe9', '#d1e5ee', '#eff8ff' ) );
     2072        wp_admin_css_color( 'fresh', __( 'Gray' ), admin_url( 'css/colors-fresh.css' ),
     2073                array( '#7c7976', '#c6c6c6', '#e0e0e0', '#f1f1f1' ) );
     2074}
    20612075
    20622076/**
    … …  
    20982112 * @uses $wp_styles WordPress Styles Object
    20992113 *
    2100  * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
     2114 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
     2115 *       to wp-admin/. Defaults to 'wp-admin'.
    21012116 * @param bool $force_echo Optional.  Force the stylesheet link to be printed rather than enqueued.
    21022117 */
    … …  
    21342149        wp_enqueue_script( 'thickbox' );
    21352150        wp_enqueue_style( 'thickbox' );
     2151
     2152        if ( is_network_admin() )
     2153                add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
    21362154}
    21372155
    … …  
    22202238                        break;
    22212239                case 'export':
    2222                         $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
     2240                        $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
    22232241                        break;
    22242242        }
    … …  
    22312249 * Compares the first two arguments and if identical marks as checked
    22322250 *
    2233  * @since 1.0
     2251 * @since 1.0.0
    22342252 *
    22352253 * @param mixed $checked One of the values to compare
    … …  
    22472265 * Compares the first two arguments and if identical marks as selected
    22482266 *
    2249  * @since 1.0
    2250  *
    2251  * @param mixed selected One of the values to compare
     2267 * @since 1.0.0
     2268 *
     2269 * @param mixed $selected One of the values to compare
    22522270 * @param mixed $current (true) The other value to compare if not just true
    22532271 * @param bool $echo Whether to echo or just return the string
    … …  
    22792297 * Compares the first two arguments and if identical marks as $type
    22802298 *
    2281  * @since 2.8
     2299 * @since 2.8.0
    22822300 * @access private
    22832301 *
Note: See TracChangeset for help on using the changeset viewer.