X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/e0feb3b2e5b436a06bbb04fbc838d1cd6ec95399..d3947bc013df7edd54b46deed8230d2eeafc5ecb:/wp-includes/post-template.php
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index 1b4901cc..a441d742 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -161,17 +161,22 @@ function get_the_title( $post = 0 ) {
/**
* Display the Post Global Unique Identifier (guid).
*
- * The guid will appear to be a link, but should not be used as an link to the
+ * The guid will appear to be a link, but should not be used as a link to the
* post. The reason you should not use it as a link, is because of moving the
* blog across domains.
*
- * Url is escaped to make it xml safe
+ * URL is escaped to make it XML-safe.
*
* @since 1.5.0
*
- * @param int|WP_Post $id Optional. Post ID or post object.
+ * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
*/
-function the_guid( $id = 0 ) {
+function the_guid( $post = 0 ) {
+ $post = get_post( $post );
+
+ $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
+ $id = isset( $post->ID ) ? $post->ID : 0;
+
/**
* Filter the escaped Global Unique Identifier (guid) of the post.
*
@@ -179,9 +184,10 @@ function the_guid( $id = 0 ) {
*
* @see get_the_guid()
*
- * @param string $post_guid Escaped Global Unique Identifier (guid) of the post.
+ * @param string $guid Escaped Global Unique Identifier (guid) of the post.
+ * @param int $id The post ID.
*/
- echo apply_filters( 'the_guid', get_the_guid( $id ) );
+ echo apply_filters( 'the_guid', $guid, $id );
}
/**
@@ -193,20 +199,24 @@ function the_guid( $id = 0 ) {
*
* @since 1.5.0
*
- * @param int|WP_Post $id Optional. Post ID or post object.
+ * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
* @return string
*/
-function get_the_guid( $id = 0 ) {
- $post = get_post($id);
+function get_the_guid( $post = 0 ) {
+ $post = get_post( $post );
+
+ $guid = isset( $post->guid ) ? $post->guid : '';
+ $id = isset( $post->ID ) ? $post->ID : 0;
/**
* Filter the Global Unique Identifier (guid) of the post.
*
* @since 1.5.0
*
- * @param string $post_guid Global Unique Identifier (guid) of the post.
+ * @param string $guid Global Unique Identifier (guid) of the post.
+ * @param int $id The post ID.
*/
- return apply_filters( 'get_the_guid', $post->guid );
+ return apply_filters( 'get_the_guid', $guid, $id );
}
/**
@@ -244,7 +254,7 @@ function the_content( $more_link_text = null, $strip_teaser = false) {
* @global int $multipage
*
* @param string $more_link_text Optional. Content for when there is more text.
- * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
* @return string
*/
function get_the_content( $more_link_text = null, $strip_teaser = false ) {
@@ -316,7 +326,8 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
*
* @since 3.1.0
* @access private
- * @param array $match Match array from preg_replace_callback
+ *
+ * @param array $match Match array from preg_replace_callback.
* @return string
*/
function _convert_urlencoded_to_entities( $match ) {
@@ -343,23 +354,25 @@ function the_excerpt() {
}
/**
- * Retrieve the post excerpt.
+ * Retrieves the post excerpt.
*
* @since 0.71
+ * @since 4.5.0 Introduced the `$post` parameter.
*
- * @param mixed $deprecated Not used.
- * @return string
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
+ * @return string Post excerpt.
*/
-function get_the_excerpt( $deprecated = '' ) {
- if ( !empty( $deprecated ) )
+function get_the_excerpt( $post = null ) {
+ if ( is_bool( $post ) ) {
_deprecated_argument( __FUNCTION__, '2.3' );
+ }
- $post = get_post();
+ $post = get_post( $post );
if ( empty( $post ) ) {
return '';
}
- if ( post_password_required() ) {
+ if ( post_password_required( $post ) ) {
return __( 'There is no excerpt because this is a protected post.' );
}
@@ -367,10 +380,12 @@ function get_the_excerpt( $deprecated = '' ) {
* Filter the retrieved post excerpt.
*
* @since 1.2.0
+ * @since 4.5.0 Introduced the `$post` parameter.
*
* @param string $post_excerpt The post excerpt.
+ * @param WP_Post $post Post object.
*/
- return apply_filters( 'get_the_excerpt', $post->post_excerpt );
+ return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
}
/**
@@ -391,8 +406,8 @@ function has_excerpt( $id = 0 ) {
*
* @since 2.7.0
*
- * @param string|array $class One or more classes to add to the class list.
- * @param int|WP_Post $post_id Optional. Post ID or post object.
+ * @param string|array $class One or more classes to add to the class list.
+ * @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`.
*/
function post_class( $class = '', $post_id = null ) {
// Separates classes with a single space, collates classes for post DIV
@@ -428,6 +443,9 @@ function get_post_class( $class = '', $post_id = null ) {
$class = preg_split( '#\s+#', $class );
}
$classes = array_map( 'esc_attr', $class );
+ } else {
+ // Ensure that we always coerce class to being an array.
+ $class = array();
}
if ( ! $post ) {
@@ -450,11 +468,17 @@ function get_post_class( $class = '', $post_id = null ) {
$classes[] = 'format-standard';
}
- // Post requires password
- if ( post_password_required( $post->ID ) ) {
+ $post_password_required = post_password_required( $post->ID );
+
+ // Post requires password.
+ if ( $post_password_required ) {
$classes[] = 'post-password-required';
- // Post thumbnails
- } elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) {
+ } elseif ( ! empty( $post->post_password ) ) {
+ $classes[] = 'post-password-protected';
+ }
+
+ // Post thumbnails.
+ if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
$classes[] = 'has-post-thumbnail';
}
@@ -501,9 +525,9 @@ function get_post_class( $class = '', $post_id = null ) {
*
* @since 2.7.0
*
- * @param array $classes An array of post classes.
- * @param string $class A comma-separated list of additional classes added to the post.
- * @param int $post_id The post ID.
+ * @param array $classes An array of post classes.
+ * @param array $class An array of additional classes added to the post.
+ * @param int $post_id The post ID.
*/
$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
@@ -528,13 +552,12 @@ function body_class( $class = '' ) {
* @since 2.8.0
*
* @global WP_Query $wp_query
- * @global wpdb $wpdb
*
* @param string|array $class One or more classes to add to the class list.
* @return array Array of classes.
*/
function get_body_class( $class = '' ) {
- global $wp_query, $wpdb;
+ global $wp_query;
$classes = array();
@@ -559,6 +582,9 @@ function get_body_class( $class = '' ) {
$classes[] = 'attachment';
if ( is_404() )
$classes[] = 'error404';
+ if ( is_singular() ) {
+ $classes[] = 'singular';
+ }
if ( is_single() ) {
$post_id = $wp_query->get_queried_object_id();
@@ -680,6 +706,10 @@ function get_body_class( $class = '' ) {
if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
$classes[] = 'custom-background';
+ if ( has_custom_logo() ) {
+ $classes[] = 'wp-custom-logo';
+ }
+
$page = $wp_query->get( 'page' );
if ( ! $page || $page < 2 )
@@ -722,8 +752,8 @@ function get_body_class( $class = '' ) {
*
* @since 2.8.0
*
- * @param array $classes An array of body classes.
- * @param string $class A comma-separated list of additional classes added to the body.
+ * @param array $classes An array of body classes.
+ * @param array $class An array of additional classes added to the body.
*/
$classes = apply_filters( 'body_class', $classes, $class );
@@ -849,7 +879,7 @@ function wp_link_pages( $args = '' ) {
} elseif ( $more ) {
$output .= $r['before'];
$prev = $page - 1;
- if ( $prev ) {
+ if ( $prev > 0 ) {
$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '';
/** This filter is documented in wp-includes/post-template.php */
@@ -899,6 +929,7 @@ function wp_link_pages( $args = '' ) {
function _wp_link_page( $i ) {
global $wp_rewrite;
$post = get_post();
+ $query_args = array();
if ( 1 == $i ) {
$url = get_permalink();
@@ -912,16 +943,13 @@ function _wp_link_page( $i ) {
}
if ( is_preview() ) {
- $url = add_query_arg( array(
- 'preview' => 'true'
- ), $url );
if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
- $url = add_query_arg( array(
- 'preview_id' => wp_unslash( $_GET['preview_id'] ),
- 'preview_nonce' => wp_unslash( $_GET['preview_nonce'] )
- ), $url );
+ $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
+ $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
}
+
+ $url = get_preview_post_link( $post, $query_args, $url );
}
return '';
@@ -953,8 +981,10 @@ function post_custom( $key = '' ) {
/**
* Display list of post custom fields.
*
- * @internal This will probably change at some point...
* @since 1.2.0
+ *
+ * @internal This will probably change at some point...
+ *
*/
function the_meta() {
if ( $keys = get_post_custom_keys() ) {
@@ -1054,10 +1084,13 @@ function wp_dropdown_pages( $args = '' ) {
* Filter the HTML output of a list of pages as a drop down.
*
* @since 2.1.0
+ * @since 4.4.0 `$r` and `$pages` added as arguments.
*
* @param string $output HTML output for drop down list of pages.
- */
- $html = apply_filters( 'wp_dropdown_pages', $output );
+ * @param array $r The parsed arguments array.
+ * @param array $pages List of WP_Post objects returned by `get_pages()`
+ */
+ $html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
if ( $r['echo'] ) {
echo $html;
@@ -1161,13 +1194,15 @@ function wp_list_pages( $args = '' ) {
* Filter the HTML output of the pages to list.
*
* @since 1.5.1
+ * @since 4.4.0 `$pages` added as arguments.
*
* @see wp_list_pages()
*
* @param string $output HTML output of the pages list.
* @param array $r An array of page-listing arguments.
+ * @param array $pages List of WP_Post objects returned by `get_pages()`
*/
- $html = apply_filters( 'wp_list_pages', $output, $r );
+ $html = apply_filters( 'wp_list_pages', $output, $r, $pages );
if ( $r['echo'] ) {
echo $html;
@@ -1184,24 +1219,41 @@ function wp_list_pages( $args = '' ) {
* arguments.
*
* @since 2.7.0
+ * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
*
* @param array|string $args {
* Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments.
*
* @type string $sort_column How to short the list of pages. Accepts post column names.
* Default 'menu_order, post_title'.
- * @type string $menu_class Class to use for the div ID containing the page list. Default 'menu'.
+ * @type string $menu_id ID for the div containing the page list. Default is empty string.
+ * @type string $menu_class Class to use for the element containing the page list. Default 'menu'.
+ * @type string $container Element to use for the element containing the page list. Default 'div'.
* @type bool $echo Whether to echo the list or return it. Accepts true (echo) or false (return).
* Default true.
- * @type string $link_before The HTML or text to prepend to $show_home text. Default empty.
- * @type string $link_after The HTML or text to append to $show_home text. Default empty.
* @type int|bool|string $show_home Whether to display the link to the home page. Can just enter the text
* you'd like shown for the home link. 1|true defaults to 'Home'.
+ * @type string $link_before The HTML or text to prepend to $show_home text. Default empty.
+ * @type string $link_after The HTML or text to append to $show_home text. Default empty.
+ * @type string $before The HTML or text to prepend to the menu. Default is ''.
+ * @type string $after The HTML or text to append to the menu. Default is '
'.
+ * @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page).
* }
* @return string|void HTML menu
*/
function wp_page_menu( $args = array() ) {
- $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
+ $defaults = array(
+ 'sort_column' => 'menu_order, post_title',
+ 'menu_id' => '',
+ 'menu_class' => 'menu',
+ 'container' => 'div',
+ 'echo' => true,
+ 'link_before' => '',
+ 'link_after' => '',
+ 'before' => '',
+ 'after' => '
',
+ 'walker' => '',
+ );
$args = wp_parse_args( $args, $defaults );
/**
@@ -1244,10 +1296,36 @@ function wp_page_menu( $args = array() ) {
$list_args['title_li'] = '';
$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
- if ( $menu )
- $menu = '' . $menu . '
';
+ $container = sanitize_text_field( $args['container'] );
- $menu = ' \n";
+ // Fallback in case `wp_nav_menu()` was called without a container.
+ if ( empty( $container ) ) {
+ $container = 'div';
+ }
+
+ if ( $menu ) {
+
+ // wp_nav_menu doesn't set before and after
+ if ( isset( $args['fallback_cb'] ) &&
+ 'wp_page_menu' === $args['fallback_cb'] &&
+ 'ul' !== $container ) {
+ $args['before'] = '';
+ $args['after'] = '
';
+ }
+
+ $menu = $args['before'] . $menu . $args['after'];
+ }
+
+ $attrs = '';
+ if ( ! empty( $args['menu_id'] ) ) {
+ $attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"';
+ }
+
+ if ( ! empty( $args['menu_class'] ) ) {
+ $attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"';
+ }
+
+ $menu = "<{$container}{$attrs}>" . $menu . "{$container}>\n";
/**
* Filter the HTML output of a page-based menu.
@@ -1316,217 +1394,6 @@ function walk_page_dropdown_tree() {
return call_user_func_array(array($walker, 'walk'), $args);
}
-/**
- * Create HTML list of pages.
- *
- * @since 2.1.0
- * @uses Walker
- */
-class Walker_Page extends Walker {
- /**
- * @see Walker::$tree_type
- * @since 2.1.0
- * @var string
- */
- public $tree_type = 'page';
-
- /**
- * @see Walker::$db_fields
- * @since 2.1.0
- * @todo Decouple this.
- * @var array
- */
- public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
-
- /**
- * @see Walker::start_lvl()
- * @since 2.1.0
- *
- * @param string $output Passed by reference. Used to append additional content.
- * @param int $depth Depth of page. Used for padding.
- * @param array $args
- */
- public function start_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat("\t", $depth);
- $output .= "\n$indent\n";
- }
-
- /**
- * @see Walker::end_lvl()
- * @since 2.1.0
- *
- * @param string $output Passed by reference. Used to append additional content.
- * @param int $depth Depth of page. Used for padding.
- * @param array $args
- */
- public function end_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat("\t", $depth);
- $output .= "$indent
\n";
- }
-
- /**
- * @see Walker::start_el()
- * @since 2.1.0
- *
- * @param string $output Passed by reference. Used to append additional content.
- * @param object $page Page data object.
- * @param int $depth Depth of page. Used for padding.
- * @param int $current_page Page ID.
- * @param array $args
- */
- public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
- if ( $depth ) {
- $indent = str_repeat( "\t", $depth );
- } else {
- $indent = '';
- }
-
- $css_class = array( 'page_item', 'page-item-' . $page->ID );
-
- if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
- $css_class[] = 'page_item_has_children';
- }
-
- if ( ! empty( $current_page ) ) {
- $_current_page = get_post( $current_page );
- if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
- $css_class[] = 'current_page_ancestor';
- }
- if ( $page->ID == $current_page ) {
- $css_class[] = 'current_page_item';
- } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
- $css_class[] = 'current_page_parent';
- }
- } elseif ( $page->ID == get_option('page_for_posts') ) {
- $css_class[] = 'current_page_parent';
- }
-
- /**
- * Filter the list of CSS classes to include with each page item in the list.
- *
- * @since 2.8.0
- *
- * @see wp_list_pages()
- *
- * @param array $css_class An array of CSS classes to be applied
- * to each list item.
- * @param WP_Post $page Page data object.
- * @param int $depth Depth of page, used for padding.
- * @param array $args An array of arguments.
- * @param int $current_page ID of the current page.
- */
- $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
-
- if ( '' === $page->post_title ) {
- /* translators: %d: ID of a post */
- $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
- }
-
- $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
- $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
-
- /** This filter is documented in wp-includes/post-template.php */
- $output .= $indent . sprintf(
- '
'; /** @@ -1815,7 +1686,17 @@ function wp_post_revision_title_expanded( $revision, $link = true ) { elseif ( wp_is_post_autosave( $revision ) ) $revision_date_author = sprintf( $autosavef, $revision_date_author ); - return $revision_date_author; + /** + * Filter the formatted author and date for a revision. + * + * @since 4.4.0 + * + * @param string $revision_date_author The formatted string. + * @param WP_Post $revision The revision object. + * @param bool $link Whether to link to the revisions page, as passed into + * wp_post_revision_title_expanded(). + */ + return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link ); } /**