~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-includes/general-template.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:04:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: nick.moffitt@canonical.com-20150115110426-5stm1p14cfnxrtme
New Upstream Version 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *
18
18
 * @since 1.5.0
19
19
 *
20
 
 * @uses locate_template()
21
 
 *
22
20
 * @param string $name The name of the specialised header.
23
21
 */
24
22
function get_header( $name = null ) {
59
57
 *
60
58
 * @since 1.5.0
61
59
 *
62
 
 * @uses locate_template()
63
 
 *
64
60
 * @param string $name The name of the specialised footer.
65
61
 */
66
62
function get_footer( $name = null ) {
101
97
 *
102
98
 * @since 1.5.0
103
99
 *
104
 
 * @uses locate_template()
105
 
 *
106
100
 * @param string $name The name of the specialised sidebar.
107
101
 */
108
102
function get_sidebar( $name = null ) {
150
144
 *
151
145
 * @since 3.0.0
152
146
 *
153
 
 * @uses locate_template()
154
 
 *
155
147
 * @param string $slug The slug name for the generic template.
156
148
 * @param string $name The name of the specialised template.
157
149
 */
159
151
        /**
160
152
         * Fires before the specified template part file is loaded.
161
153
         *
162
 
         * The dynamic portion of the hook name, $slug, refers to the slug name
 
154
         * The dynamic portion of the hook name, `$slug`, refers to the slug name
163
155
         * for the generic template part.
164
156
         *
165
157
         * @since 3.0.0
307
299
 *
308
300
 * @since 2.7.0
309
301
 *
310
 
 * @uses wp_nonce_url() To protect against CSRF.
311
 
 * @uses site_url() To generate the log out URL.
312
 
 *
313
302
 * @param string $redirect Path to redirect to on logout.
314
303
 * @return string A log out URL.
315
304
 */
340
329
 *
341
330
 * @since 2.7.0
342
331
 *
343
 
 * @uses site_url() To generate the log in URL.
344
 
 *
345
332
 * @param string $redirect Path to redirect to on login.
346
333
 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
347
334
 * @return string A log in URL.
373
360
 *
374
361
 * @since 3.6.0
375
362
 *
376
 
 * @uses site_url() To generate the registration URL.
377
 
 *
378
363
 * @return string User registration URL.
379
364
 */
380
365
function wp_registration_url() {
496
481
 *
497
482
 * @since 2.8.0
498
483
 *
499
 
 * @uses site_url() To generate the lost password URL
500
 
 *
501
484
 * @param string $redirect Path to redirect to on login.
502
485
 * @return string Lost password URL.
503
486
 */
528
511
 *
529
512
 * @since 1.5.0
530
513
 *
531
 
 * @param string $before Text to output before the link (defaults to <li>).
532
 
 * @param string $after Text to output after the link (defaults to </li>).
 
514
 * @param string $before Text to output before the link. Default `<li>`.
 
515
 * @param string $after Text to output after the link. Default `</li>`.
533
516
 * @param boolean $echo Default to echo and not return the link.
534
517
 * @return string|null String when retrieving, null when displaying.
535
518
 */
571
554
 *
572
555
 * @since 1.5.0
573
556
 *
574
 
 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
 
557
 * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
575
558
 */
576
559
function wp_meta() {
577
560
        /**
598
581
 * Retrieve information about the blog.
599
582
 *
600
583
 * Some show parameter values are deprecated and will be removed in future
601
 
 * versions. These options will trigger the _deprecated_argument() function.
602
 
 * The deprecated blog info options are listed in the function contents.
 
584
 * versions. These options will trigger the {@see _deprecated_argument()}
 
585
 * function. The deprecated blog info options are listed in the function
 
586
 * contents.
603
587
 *
604
588
 * The possible values for the 'show' parameter are listed below.
605
 
 * <ol>
606
 
 * <li><strong>url</strong> - Blog URI to homepage.</li>
607
 
 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
608
 
 * <li><strong>description</strong> - Secondary title</li>
609
 
 * </ol>
 
589
 *
 
590
 * 1. url - Blog URI to homepage.
 
591
 * 2. wpurl - Blog URI path to WordPress.
 
592
 * 3. description - Secondary title
610
593
 *
611
594
 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
612
595
 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
731
714
}
732
715
 
733
716
/**
 
717
 * Display title tag with contents.
 
718
 *
 
719
 * @since 4.1.0
 
720
 * @access private
 
721
 * @internal
 
722
 *
 
723
 * @see wp_title()
 
724
 */
 
725
function _wp_render_title_tag() {
 
726
        if ( ! current_theme_supports( 'title-tag' ) ) {
 
727
                return;
 
728
        }
 
729
 
 
730
        // This can only work internally on wp_head.
 
731
        if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
 
732
                return;
 
733
        }
 
734
 
 
735
        echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
 
736
}
 
737
 
 
738
/**
734
739
 * Display or retrieve page title for all areas of blog.
735
740
 *
736
741
 * By default, the page title will display the separator before the page title,
753
758
 * @return string|null String on retrieve, null when displaying.
754
759
 */
755
760
function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
756
 
        global $wp_locale;
 
761
        global $wp_locale, $page, $paged;
757
762
 
758
763
        $m = get_query_var('m');
759
764
        $year = get_query_var('year');
853
858
                $title = $prefix . implode( " $sep ", $title_array );
854
859
        }
855
860
 
 
861
        if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
 
862
                $title .= get_bloginfo( 'name', 'display' );
 
863
 
 
864
                $site_description = get_bloginfo( 'description', 'display' );
 
865
                if ( $site_description && ( is_home() || is_front_page() ) ) {
 
866
                        $title .= " $sep $site_description";
 
867
                }
 
868
 
 
869
                if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
 
870
                        $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
 
871
                }
 
872
        }
 
873
 
856
874
        /**
857
875
         * Filter the text of the page title.
858
876
         *
1096
1114
}
1097
1115
 
1098
1116
/**
 
1117
 * Display the archive title based on the queried object.
 
1118
 *
 
1119
 * @since 4.1.0
 
1120
 *
 
1121
 * @see get_the_archive_title()
 
1122
 *
 
1123
 * @param string $before Optional. Content to prepend to the title. Default empty.
 
1124
 * @param string $after  Optional. Content to append to the title. Default empty.
 
1125
 */
 
1126
function the_archive_title( $before = '', $after = '' ) {
 
1127
        $title = get_the_archive_title();
 
1128
 
 
1129
        if ( ! empty( $title ) ) {
 
1130
                echo $before . $title . $after;
 
1131
        }
 
1132
}
 
1133
 
 
1134
/**
 
1135
 * Retrieve the archive title based on the queried object.
 
1136
 *
 
1137
 * @since 4.1.0
 
1138
 *
 
1139
 * @return string Archive title.
 
1140
 */
 
1141
function get_the_archive_title() {
 
1142
        if ( is_category() ) {
 
1143
                $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
 
1144
        } elseif ( is_tag() ) {
 
1145
                $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
 
1146
        } elseif ( is_author() ) {
 
1147
                $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
 
1148
        } elseif ( is_year() ) {
 
1149
                $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
 
1150
        } elseif ( is_month() ) {
 
1151
                $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
 
1152
        } elseif ( is_day() ) {
 
1153
                $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
 
1154
        } elseif ( is_tax( 'post_format' ) ) {
 
1155
                if ( is_tax( 'post_format', 'post-format-aside' ) ) {
 
1156
                        $title = _x( 'Asides', 'post format archive title' );
 
1157
                } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
 
1158
                        $title = _x( 'Galleries', 'post format archive title' );
 
1159
                } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
 
1160
                        $title = _x( 'Images', 'post format archive title' );
 
1161
                } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
 
1162
                        $title = _x( 'Videos', 'post format archive title' );
 
1163
                } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
 
1164
                        $title = _x( 'Quotes', 'post format archive title' );
 
1165
                } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
 
1166
                        $title = _x( 'Links', 'post format archive title' );
 
1167
                } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
 
1168
                        $title = _x( 'Statuses', 'post format archive title' );
 
1169
                } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
 
1170
                        $title = _x( 'Audio', 'post format archive title' );
 
1171
                } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
 
1172
                        $title = _x( 'Chats', 'post format archive title' );
 
1173
                }
 
1174
        } elseif ( is_post_type_archive() ) {
 
1175
                $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
 
1176
        } elseif ( is_tax() ) {
 
1177
                $tax = get_taxonomy( get_queried_object()->taxonomy );
 
1178
                /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
 
1179
                $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
 
1180
        } else {
 
1181
                $title = __( 'Archives' );
 
1182
        }
 
1183
 
 
1184
        /**
 
1185
         * Filter the archive title.
 
1186
         *
 
1187
         * @since 4.1.0
 
1188
         *
 
1189
         * @param string $title Archive title to be displayed.
 
1190
         */
 
1191
        return apply_filters( 'get_the_archive_title', $title );
 
1192
}
 
1193
 
 
1194
/**
 
1195
 * Display category, tag, or term description.
 
1196
 *
 
1197
 * @since 4.1.0
 
1198
 *
 
1199
 * @see get_the_archive_description()
 
1200
 *
 
1201
 * @param string $before Optional. Content to prepend to the description. Default empty.
 
1202
 * @param string $after  Optional. Content to append to the description. Default empty.
 
1203
 */
 
1204
function the_archive_description( $before = '', $after = '' ) {
 
1205
        $description = get_the_archive_description();
 
1206
        if ( $description ) {
 
1207
                echo $before . $description . $after;
 
1208
        }
 
1209
}
 
1210
 
 
1211
/**
 
1212
 * Retrieve category, tag, or term description.
 
1213
 *
 
1214
 * @since 4.1.0
 
1215
 *
 
1216
 * @return string Archive description.
 
1217
 */
 
1218
function get_the_archive_description() {
 
1219
        /**
 
1220
         * Filter the archive description.
 
1221
         *
 
1222
         * @since 4.1.0
 
1223
         *
 
1224
         * @see term_description()
 
1225
         *
 
1226
         * @param string $description Archive description to be displayed.
 
1227
         */
 
1228
        return apply_filters( 'get_the_archive_description', term_description() );
 
1229
}
 
1230
 
 
1231
/**
1099
1232
 * Retrieve archive link content based on predefined or custom code.
1100
1233
 *
1101
1234
 * The format can be one of four styles. The 'link' for head element, 'option'
1103
1236
 * elements). Custom content is also supported using the before and after
1104
1237
 * parameters.
1105
1238
 *
1106
 
 * The 'link' format uses the link HTML element with the <em>archives</em>
 
1239
 * The 'link' format uses the `<link>` HTML element with the **archives**
1107
1240
 * relationship. The before and after parameters are not used. The text
1108
1241
 * parameter is used to describe the link.
1109
1242
 *
1121
1254
 *
1122
1255
 * @since 1.0.0
1123
1256
 *
 
1257
 * @todo Properly document optional arguments as such
 
1258
 *
1124
1259
 * @param string $url URL to archive.
1125
1260
 * @param string $text Archive text description.
1126
1261
 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1397
1532
 * no posts for the month, then it will not be displayed.
1398
1533
 *
1399
1534
 * @since 1.0.0
1400
 
 * @uses calendar_week_mod()
1401
1535
 *
1402
1536
 * @param bool $initial Optional, default is true. Use initial calendar names.
1403
1537
 * @param bool $echo Optional, default is true. Set to false for return.
1679
1813
 *
1680
1814
 * @since 0.71
1681
1815
 *
1682
 
 * @uses get_the_date()
1683
1816
 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1684
1817
 * @param string $before Optional. Output before the date.
1685
1818
 * @param string $after Optional. Output after the date.
1725
1858
 *
1726
1859
 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
1727
1860
 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
1728
 
 * @return string|bool Date the current post was written. False on failure.
 
1861
 * @return false|string Date the current post was written. False on failure.
1729
1862
 */
1730
1863
function get_the_date( $d = '', $post = null ) {
1731
1864
        $post = get_post( $post );
1843
1976
 *                          was written. Either 'G', 'U', or php date format defaults
1844
1977
 *                          to the value specified in the time_format option. Default empty.
1845
1978
 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
1846
 
 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
 
1979
 * @return false|string Formatted date string or Unix timestamp. False on failure.
1847
1980
 */
1848
1981
function get_the_time( $d = '', $post = null ) {
1849
1982
        $post = get_post($post);
1881
2014
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
1882
2015
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
1883
2016
 * @param bool        $translate Whether to translate the time string. Default false.
1884
 
 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
 
2017
 * @return false|string|int Formatted date string or Unix timestamp. False on failure.
1885
2018
 */
1886
2019
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1887
2020
        $post = get_post($post);
1968
2101
 * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
1969
2102
 * @param int|WP_Post $post      WP_Post object or ID. Default is global $post object.
1970
2103
 * @param bool        $translate Whether to translate the time string. Default false.
1971
 
 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
 
2104
 * @return false|string Formatted date string or Unix timestamp. False on failure.
1972
2105
 */
1973
2106
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1974
2107
        $post = get_post($post);
2000
2133
 *
2001
2134
 * @since 0.71
2002
2135
 * @uses $wp_locale
2003
 
 * @uses $post
2004
2136
 */
2005
2137
function the_weekday() {
2006
2138
        global $wp_locale;
2297
2429
 * Renders an editor.
2298
2430
 *
2299
2431
 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2300
 
 * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
 
2432
 * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
2301
2433
 *
2302
2434
 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2303
2435
 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
2304
2436
 * On the post edit screen several actions can be used to include additional editors
2305
2437
 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2306
 
 * See http://core.trac.wordpress.org/ticket/19173 for more information.
 
2438
 * See https://core.trac.wordpress.org/ticket/19173 for more information.
2307
2439
 *
2308
2440
 * @see wp-includes/class-wp-editor.php
2309
2441
 * @since 3.3.0
2326
2458
 * to ensure that it is safe for placing in an html attribute.
2327
2459
 *
2328
2460
 * @since 2.3.0
2329
 
 * @uses esc_attr()
2330
2461
 *
2331
2462
 * @param bool $escaped Whether the result is escaped. Default true.
2332
2463
 *      Only use when you are later escaping it. Do not use unescaped.
2353
2484
 * The search query string is passed through {@link esc_attr()}
2354
2485
 * to ensure that it is safe for placing in an html attribute.
2355
2486
 *
2356
 
 * @uses esc_attr()
2357
2487
 * @since 2.1.0
2358
2488
 */
2359
2489
function the_search_query() {
2465
2595
 
2466
2596
        if ( isset( $url_parts[1] ) ) {
2467
2597
                wp_parse_str( $url_parts[1], $query_args );
 
2598
                $query_args = urlencode_deep( $query_args );
2468
2599
        }
2469
2600
 
2470
2601
        $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
2485
2616
                'end_size' => 1,
2486
2617
                'mid_size' => 2,
2487
2618
                'type' => 'plain',
2488
 
                'add_args' => false, // array of query args to add
 
2619
                'add_args' => $query_args, // array of query args to add
2489
2620
                'add_fragment' => '',
2490
2621
                'before_page_number' => '',
2491
2622
                'after_page_number' => ''
2580
2711
 * Registers an admin colour scheme css file.
2581
2712
 *
2582
2713
 * Allows a plugin to register a new admin colour scheme. For example:
2583
 
 * <code>
2584
 
 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
2585
 
 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
2586
 
 * </code>
 
2714
 *
 
2715
 *     wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
 
2716
 *         '#07273E', '#14568A', '#D54E21', '#2683AE'
 
2717
 *     ) );
2587
2718
 *
2588
2719
 * @since 2.5.0
2589
2720
 *
 
2721
 * @todo Properly document optional arguments as such
 
2722
 *
2590
2723
 * @param string $key The unique key for this theme.
2591
2724
 * @param string $name The name of the theme.
2592
2725
 * @param string $url The url of the css file containing the colour scheme.
2876
3009
        /**
2877
3010
         * Filter the HTML for the retrieved generator type.
2878
3011
         *
2879
 
         * The dynamic portion of the hook name, $type, refers to the generator type.
 
3012
         * The dynamic portion of the hook name, `$type`, refers to the generator type.
2880
3013
         *
2881
3014
         * @since 2.5.0
2882
3015
         *
2883
 
         * @param string $gen  The HTML markup output to 'wp_head()'.
 
3016
         * @param string $gen  The HTML markup output to {@see wp_head()}.
2884
3017
         * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
2885
3018
         *                     'rss2', 'rdf', 'comment', 'export'.
2886
3019
         */