]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/post-template.php
WordPress 4.5.1
[autoinstalls/wordpress.git] / wp-includes / post-template.php
index f13a458b566c3839472ebd03b59b1e6f4f1f8fc3..3da42457c8c74cdaea5435909bc1b9345a9d58c9 100644 (file)
@@ -22,7 +22,7 @@ function the_ID() {
  *
  * @since 2.1.0
  *
- * @return int|bool The ID of the current item in the WordPress Loop. False if $post is not set.
+ * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
  */
 function get_the_ID() {
        $post = get_post();
@@ -35,11 +35,11 @@ function get_the_ID() {
  * @since 0.71
  *
  * @param string $before Optional. Content to prepend to the title.
- * @param string $after Optional. Content to append to the title.
- * @param bool $echo Optional, default to true.Whether to display or return.
- * @return null|string Null on no title. String if $echo parameter is false.
+ * @param string $after  Optional. Content to append to the title.
+ * @param bool   $echo   Optional, default to true.Whether to display or return.
+ * @return string|void String if $echo parameter is false.
  */
-function the_title($before = '', $after = '', $echo = true) {
+function the_title( $before = '', $after = '', $echo = true ) {
        $title = get_the_title();
 
        if ( strlen($title) == 0 )
@@ -73,7 +73,7 @@ function the_title($before = '', $after = '', $echo = true) {
  *     @type bool    $echo   Whether to echo or return the title. Default true for echo.
  *     @type WP_Post $post   Current post object to retrieve the title for.
  * }
- * @return string|null Null on failure or display. String when echo is false.
+ * @return string|void String when echo is false.
  */
 function the_title_attribute( $args = '' ) {
        $defaults = array( 'before' => '', 'after' =>  '', 'echo' => true, 'post' => get_post() );
@@ -129,7 +129,7 @@ function get_the_title( $post = 0 ) {
                         */
                        $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
                        $title = sprintf( $protected_title_format, $title );
-               } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) {
+               } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
 
                        /**
                         * Filter the text prepended to the post title of private posts.
@@ -161,18 +161,33 @@ 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 ) {
-       echo esc_url( get_the_guid( $id ) );
+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.
+        *
+        * @since 4.2.0
+        *
+        * @see get_the_guid()
+        *
+        * @param string $guid Escaped Global Unique Identifier (guid) of the post.
+        * @param int    $id   The post ID.
+        */
+       echo apply_filters( 'the_guid', $guid, $id );
 }
 
 /**
@@ -184,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 );
 }
 
 /**
@@ -228,8 +247,14 @@ function the_content( $more_link_text = null, $strip_teaser = false) {
  *
  * @since 0.71
  *
+ * @global int   $page
+ * @global int   $more
+ * @global bool  $preview
+ * @global array $pages
+ * @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 ) {
@@ -301,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 ) {
@@ -328,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.' );
        }
 
@@ -352,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 );
 }
 
 /**
@@ -376,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
@@ -389,26 +419,38 @@ function post_class( $class = '', $post_id = null ) {
  *
  * The class names are many. If the post is a sticky, then the 'sticky'
  * class name. The class 'hentry' is always added to each post. If the post has a
- * post thumbnail, 'has-post-thumbnail' is added as a class. For each
- * category, the class will be added with 'category-' with category slug is
- * added. The tags are the same way as the categories with 'tag-' before the tag
- * slug. All classes are passed through the filter, 'post_class' with the list
- * of classes, followed by $class parameter value, with the post ID as the last
- * parameter.
+ * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
+ * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
+ * eg 'category-foo' or 'my_custom_taxonomy-bar'. The 'post_tag' taxonomy is a special
+ * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
+ * passed through the filter, 'post_class' with the list of classes, followed by
+ * $class parameter value, with the post ID as the last parameter.
  *
  * @since 2.7.0
+ * @since 4.2.0 Custom taxonomy classes were added.
  *
- * @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.
  * @return array Array of classes.
  */
 function get_post_class( $class = '', $post_id = null ) {
-       $post = get_post($post_id);
+       $post = get_post( $post_id );
 
        $classes = array();
 
-       if ( empty($post) )
+       if ( $class ) {
+               if ( ! is_array( $class ) ) {
+                       $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 ) {
                return $classes;
+       }
 
        $classes[] = 'post-' . $post->ID;
        if ( ! is_admin() )
@@ -426,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';
        }
 
@@ -446,40 +494,40 @@ function get_post_class( $class = '', $post_id = null ) {
        // hentry for hAtom compliance
        $classes[] = 'hentry';
 
-       // Categories
-       if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
-               foreach ( (array) get_the_category($post->ID) as $cat ) {
-                       if ( empty($cat->slug ) )
-                               continue;
-                       $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
-               }
-       }
+       // All public taxonomies
+       $taxonomies = get_taxonomies( array( 'public' => true ) );
+       foreach ( (array) $taxonomies as $taxonomy ) {
+               if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
+                       foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
+                               if ( empty( $term->slug ) ) {
+                                       continue;
+                               }
 
-       // Tags
-       if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
-               foreach ( (array) get_the_tags($post->ID) as $tag ) {
-                       if ( empty($tag->slug ) )
-                               continue;
-                       $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
-               }
-       }
+                               $term_class = sanitize_html_class( $term->slug, $term->term_id );
+                               if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
+                                       $term_class = $term->term_id;
+                               }
 
-       if ( !empty($class) ) {
-               if ( !is_array( $class ) )
-                       $class = preg_split('#\s+#', $class);
-               $classes = array_merge($classes, $class);
+                               // 'post_tag' uses the 'tag' prefix for backward compatibility.
+                               if ( 'post_tag' == $taxonomy ) {
+                                       $classes[] = 'tag-' . $term_class;
+                               } else {
+                                       $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
+                               }
+                       }
+               }
        }
 
-       $classes = array_map('esc_attr', $classes);
+       $classes = array_map( 'esc_attr', $classes );
 
        /**
         * Filter the list of CSS classes for the current post.
         *
         * @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 );
 
@@ -503,11 +551,13 @@ function body_class( $class = '' ) {
  *
  * @since 2.8.0
  *
+ * @global WP_Query $wp_query
+ *
  * @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();
 
@@ -566,7 +616,7 @@ function get_body_class( $class = '' ) {
                        if ( is_array( $post_type ) )
                                $post_type = reset( $post_type );
                        $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
-               } else if ( is_author() ) {
+               } elseif ( is_author() ) {
                        $author = $wp_query->get_queried_object();
                        $classes[] = 'author';
                        if ( isset( $author->user_nicename ) ) {
@@ -577,21 +627,36 @@ function get_body_class( $class = '' ) {
                        $cat = $wp_query->get_queried_object();
                        $classes[] = 'category';
                        if ( isset( $cat->term_id ) ) {
-                               $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
+                               $cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
+                               if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
+                                       $cat_class = $cat->term_id;
+                               }
+
+                               $classes[] = 'category-' . $cat_class;
                                $classes[] = 'category-' . $cat->term_id;
                        }
                } elseif ( is_tag() ) {
-                       $tags = $wp_query->get_queried_object();
+                       $tag = $wp_query->get_queried_object();
                        $classes[] = 'tag';
-                       if ( isset( $tags->term_id ) ) {
-                               $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
-                               $classes[] = 'tag-' . $tags->term_id;
+                       if ( isset( $tag->term_id ) ) {
+                               $tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
+                               if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
+                                       $tag_class = $tag->term_id;
+                               }
+
+                               $classes[] = 'tag-' . $tag_class;
+                               $classes[] = 'tag-' . $tag->term_id;
                        }
                } elseif ( is_tax() ) {
                        $term = $wp_query->get_queried_object();
                        if ( isset( $term->term_id ) ) {
+                               $term_class = sanitize_html_class( $term->slug, $term->term_id );
+                               if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
+                                       $term_class = $term->term_id;
+                               }
+
                                $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
-                               $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
+                               $classes[] = 'term-' . $term_class;
                                $classes[] = 'term-' . $term->term_id;
                        }
                }
@@ -635,9 +700,13 @@ function get_body_class( $class = '' ) {
                $classes[] = 'no-customize-support';
        }
 
-       if ( get_theme_mod( 'background_color' ) || get_background_image() )
+       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 )
@@ -680,8 +749,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 );
 
@@ -693,7 +762,7 @@ function get_body_class( $class = '' ) {
  *
  * @since 2.7.0
  *
- * @param int|WP_Post $post An optional post. Global $post used if not provided.
+ * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
  */
 function post_password_required( $post = null ) {
@@ -727,6 +796,11 @@ function post_password_required( $post = null ) {
  *
  * @since 1.2.0
  *
+ * @global int $page
+ * @global int $numpages
+ * @global int $multipage
+ * @global int $more
+ *
  * @param string|array $args {
  *     Optional. Array or string of default arguments.
  *
@@ -749,6 +823,8 @@ function post_password_required( $post = null ) {
  * @return string Formatted output in HTML.
  */
 function wp_link_pages( $args = '' ) {
+       global $page, $numpages, $multipage, $more;
+
        $defaults = array(
                'before'           => '<p>' . __( 'Pages:' ),
                'after'            => '</p>',
@@ -773,8 +849,6 @@ function wp_link_pages( $args = '' ) {
         */
        $r = apply_filters( 'wp_link_pages_args', $params );
 
-       global $page, $numpages, $multipage, $more;
-
        $output = '';
        if ( $multipage ) {
                if ( 'number' == $r['next_or_number'] ) {
@@ -802,7 +876,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'] . '</a>';
 
                                /** This filter is documented in wp-includes/post-template.php */
@@ -844,12 +918,15 @@ function wp_link_pages( $args = '' ) {
  * @since 3.1.0
  * @access private
  *
+ * @global WP_Rewrite $wp_rewrite
+ *
  * @param int $i Page number.
  * @return string Link.
  */
 function _wp_link_page( $i ) {
        global $wp_rewrite;
        $post = get_post();
+       $query_args = array();
 
        if ( 1 == $i ) {
                $url = get_permalink();
@@ -863,16 +940,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 '<a href="' . esc_url( $url ) . '">';
@@ -888,7 +962,7 @@ function _wp_link_page( $i ) {
  * @since 1.5.0
  *
  * @param string $key Meta data key name.
- * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
+ * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
  */
 function post_custom( $key = '' ) {
        $custom = get_post_custom();
@@ -904,8 +978,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() ) {
@@ -940,8 +1016,28 @@ function the_meta() {
  * Retrieve or display list of pages as a dropdown (select list).
  *
  * @since 2.1.0
+ * @since 4.2.0 The `$value_field` argument was added.
+ * @since 4.3.0 The `$class` argument was added.
  *
- * @param array|string $args Optional. Override default arguments.
+ * @param array|string $args {
+ *     Optional. Array or string of arguments to generate a pages drop-down element.
+ *
+ *     @type int          $depth                 Maximum depth. Default 0.
+ *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
+ *     @type int|string   $selected              Value of the option that should be selected. Default 0.
+ *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
+ *                                               or their bool equivalents. Default 1.
+ *     @type string       $name                  Value for the 'name' attribute of the select element.
+ *                                               Default 'page_id'.
+ *     @type string       $id                    Value for the 'id' attribute of the select element.
+ *     @type string       $class                 Value for the 'class' attribute of the select element. Default: none.
+ *                                               Defaults to the value of `$name`.
+ *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
+ *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
+ *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
+ *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
+ *                                               elements. Accepts any valid post field. Default 'ID'.
+ * }
  * @return string HTML content, if not displaying.
  */
 function wp_dropdown_pages( $args = '' ) {
@@ -949,8 +1045,10 @@ function wp_dropdown_pages( $args = '' ) {
                'depth' => 0, 'child_of' => 0,
                'selected' => 0, 'echo' => 1,
                'name' => 'page_id', 'id' => '',
+               'class' => '',
                'show_option_none' => '', 'show_option_no_change' => '',
-               'option_none_value' => ''
+               'option_none_value' => '',
+               'value_field' => 'ID',
        );
 
        $r = wp_parse_args( $args, $defaults );
@@ -963,7 +1061,12 @@ function wp_dropdown_pages( $args = '' ) {
        }
 
        if ( ! empty( $pages ) ) {
-               $output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n";
+               $class = '';
+               if ( ! empty( $r['class'] ) ) {
+                       $class = " class='" . esc_attr( $r['class'] ) . "'";
+               }
+
+               $output = "<select name='" . esc_attr( $r['name'] ) . "'" . $class . " id='" . esc_attr( $r['id'] ) . "'>\n";
                if ( $r['show_option_no_change'] ) {
                        $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
                }
@@ -978,10 +1081,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;
@@ -996,6 +1102,8 @@ function wp_dropdown_pages( $args = '' ) {
  *
  * @see get_pages()
  *
+ * @global WP_Query $wp_query
+ *
  * @param array|string $args {
  *     Array or string of arguments. Optional.
  *
@@ -1022,7 +1130,7 @@ function wp_dropdown_pages( $args = '' ) {
  *                                will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
  *     @type Walker $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  * }
- * @return string HTML list of pages.
+ * @return string|void HTML list of pages.
  */
 function wp_list_pages( $args = '' ) {
        $defaults = array(
@@ -1083,13 +1191,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;
@@ -1106,25 +1216,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 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|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'.
+ *     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_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 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 '<ul>'.
+ *     @type string          $after       The HTML or text to append to the menu. Default is '</ul>'.
+ *     @type Walker          $walker      Walker instance to use for listing pages. Default empty (Walker_Page).
  * }
- * @return string html menu
+ * @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'      => '<ul>',
+               'after'       => '</ul>',
+               'walker'      => '',
+       );
        $args = wp_parse_args( $args, $defaults );
 
        /**
@@ -1167,10 +1293,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 = '<ul>' . $menu . '</ul>';
+       $container = sanitize_text_field( $args['container'] );
+
+       // 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'] = '<ul>';
+                       $args['after'] = '</ul>';
+               }
+
+               $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 = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
+       $menu = "<{$container}{$attrs}>" . $menu . "</{$container}>\n";
 
        /**
         * Filter the HTML output of a page-based menu.
@@ -1198,9 +1350,14 @@ function wp_page_menu( $args = array() ) {
  *
  * @uses Walker_Page to create HTML list content.
  * @since 2.1.0
- * @see Walker_Page::walk() for parameters and return description.
+ *
+ * @param array $pages
+ * @param int   $depth
+ * @param int   $current_page
+ * @param array $r
+ * @return string
  */
-function walk_page_tree($pages, $depth, $current_page, $r) {
+function walk_page_tree( $pages, $depth, $current_page, $r ) {
        if ( empty($r['walker']) )
                $walker = new Walker_Page;
        else
@@ -1221,6 +1378,8 @@ function walk_page_tree($pages, $depth, $current_page, $r) {
  * @uses Walker_PageDropdown to create HTML dropdown content.
  * @since 2.1.0
  * @see Walker_PageDropdown::walk() for parameters and return description.
+ *
+ * @return string
  */
 function walk_page_dropdown_tree() {
        $args = func_get_args();
@@ -1232,210 +1391,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<ul class='children'>\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</ul>\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 ) {
-                       $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(
-                       '<li class="%s"><a href="%s">%s%s%s</a>',
-                       $css_classes,
-                       get_permalink( $page->ID ),
-                       $args['link_before'],
-                       apply_filters( 'the_title', $page->post_title, $page->ID ),
-                       $args['link_after']
-               );
-
-               if ( ! empty( $args['show_date'] ) ) {
-                       if ( 'modified' == $args['show_date'] ) {
-                               $time = $page->post_modified;
-                       } else {
-                               $time = $page->post_date;
-                       }
-
-                       $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
-                       $output .= " " . mysql2date( $date_format, $time );
-               }
-       }
-
-       /**
-        * @see Walker::end_el()
-        * @since 2.1.0
-        *
-        * @param string $output Passed by reference. Used to append additional content.
-        * @param object $page Page data object. Not used.
-        * @param int $depth Depth of page. Not Used.
-        * @param array $args
-        */
-       public function end_el( &$output, $page, $depth = 0, $args = array() ) {
-               $output .= "</li>\n";
-       }
-
-}
-
-/**
- * Create HTML dropdown list of pages.
- *
- * @since 2.1.0
- * @uses Walker
- */
-class Walker_PageDropdown 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_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 in reference to parent pages. Used for padding.
-        * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
-        * @param int $id
-        */
-       public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
-               $pad = str_repeat('&nbsp;', $depth * 3);
-
-               $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
-               if ( $page->ID == $args['selected'] )
-                       $output .= ' selected="selected"';
-               $output .= '>';
-
-               $title = $page->post_title;
-               if ( '' === $title ) {
-                       $title = sprintf( __( '#%d (no title)' ), $page->ID );
-               }
-
-               /**
-                * Filter the page title when creating an HTML drop-down list of pages.
-                *
-                * @since 3.1.0
-                *
-                * @param string $title Page title.
-                * @param object $page  Page data object.
-                */
-               $title = apply_filters( 'list_pages', $title, $page );
-               $output .= $pad . esc_html( $title );
-               $output .= "</option>\n";
-       }
-}
-
 //
 // Attachments
 //
@@ -1464,17 +1419,20 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $
  * Retrieve an attachment page link using an image or icon, if possible.
  *
  * @since 2.5.0
+ * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
  *
  * @param int|WP_Post  $id        Optional. Post ID or post object.
- * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
- * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
- * @param bool         $icon      Optional, default is false. Whether to include icon.
- * @param string|bool  $text      Optional, default is false. If string, then will be link text.
- * @param array|string $attr      Optional. Array or string of attributes.
+ * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
+ *                                of width and height values in pixels (in that order).
+ *                                Default 'thumbnail'.
+ * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
+ * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
+ * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
+ *                                Default false.
+ * @param array|string $attr      Optional. Array or string of attributes. Default empty.
  * @return string HTML content.
  */
 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
-       $id = intval( $id );
        $_post = get_post( $id );
 
        if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
@@ -1486,7 +1444,7 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals
        if ( $text ) {
                $link_text = $text;
        } elseif ( $size && 'none' != $size ) {
-               $link_text = wp_get_attachment_image( $id, $size, $icon, $attr );
+               $link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
        } else {
                $link_text = '';
        }
@@ -1499,12 +1457,13 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals
         *
         * @since 2.7.0
         *
-        * @param string      $link_html The page link HTML output.
-        * @param int         $id        Post ID.
-        * @param string      $size      Image size. Default 'thumbnail'.
-        * @param bool        $permalink Whether to add permalink to image. Default false.
-        * @param bool        $icon      Whether to include an icon. Default false.
-        * @param string|bool $text      If string, will be link text. Default false.
+        * @param string       $link_html The page link HTML output.
+        * @param int          $id        Post ID.
+        * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
+        *                                Default 'thumbnail'.
+        * @param bool         $permalink Whether to add permalink to image. Default false.
+        * @param bool         $icon      Whether to include an icon. Default false.
+        * @param string|bool  $text      If string, will be link text. Default false.
         */
        return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text );
 }
@@ -1523,7 +1482,7 @@ function prepend_attachment($content) {
        if ( empty($post->post_type) || $post->post_type != 'attachment' )
                return $content;
 
-       if ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
+       if ( wp_attachment_is( 'video', $post ) ) {
                $meta = wp_get_attachment_metadata( get_the_ID() );
                $atts = array( 'src' => wp_get_attachment_url() );
                if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
@@ -1534,7 +1493,7 @@ function prepend_attachment($content) {
                        $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
                }
                $p = wp_video_shortcode( $atts );
-       } elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
+       } elseif ( wp_attachment_is( 'audio', $post ) ) {
                $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
        } else {
                $p = '<p class="attachment">';
@@ -1574,7 +1533,7 @@ function get_the_password_form( $post = 0 ) {
        $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
        <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
-       <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__( 'Submit' ) . '" /></p></form>
+       <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
        ';
 
        /**
@@ -1595,12 +1554,13 @@ function get_the_password_form( $post = 0 ) {
  * Whether currently in a page template.
  *
  * This template tag allows you to determine if you are in a page template.
- * You can optionally provide a template name and then the check will be
- * specific to that template.
+ * You can optionally provide a template name or array of template names
+ * and then the check will be specific to that template.
  *
  * @since 2.5.0
+ * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
  *
- * @param string $template The specific template name if specific matching is required.
+ * @param string|array $template The specific template name or array of templates to match.
  * @return bool True on success, false on failure.
  */
 function is_page_template( $template = '' ) {
@@ -1615,10 +1575,15 @@ function is_page_template( $template = '' ) {
        if ( $template == $page_template )
                return true;
 
-       if ( 'default' == $template && ! $page_template )
-               return true;
+       if ( is_array( $template ) ) {
+               if ( ( in_array( 'default', $template, true ) && ! $page_template )
+                       || in_array( $page_template, $template, true )
+               ) {
+                       return true;
+               }
+       }
 
-       return false;
+       return ( 'default' === $template && ! $page_template );
 }
 
 /**
@@ -1627,7 +1592,7 @@ function is_page_template( $template = '' ) {
  * @since 3.4.0
  *
  * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
- * @return string|bool Page template filename. Returns an empty string when the default page template
+ * @return string|false Page template filename. Returns an empty string when the default page template
  *     is in use. Returns false if the post is not a page.
  */
 function get_page_template_slug( $post_id = null ) {
@@ -1646,8 +1611,8 @@ function get_page_template_slug( $post_id = null ) {
  * @since 2.6.0
  *
  * @param int|object $revision Revision ID or revision object.
- * @param bool $link Optional, default is true. Link to revisions's page?
- * @return string i18n formatted datetimestamp or localized 'Current Revision'.
+ * @param bool       $link     Optional, default is true. Link to revisions's page?
+ * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
  */
 function wp_post_revision_title( $revision, $link = true ) {
        if ( !$revision = get_post( $revision ) )
@@ -1657,7 +1622,7 @@ function wp_post_revision_title( $revision, $link = true ) {
                return false;
 
        /* translators: revision date format, see http://php.net/date */
-       $datef = _x( 'j F, Y @ G:i', 'revision date format');
+       $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
        /* translators: 1: date */
        $autosavef = _x( '%1$s [Autosave]', 'post revision title extra' );
        /* translators: 1: date */
@@ -1681,8 +1646,8 @@ function wp_post_revision_title( $revision, $link = true ) {
  * @since 3.6.0
  *
  * @param int|object $revision Revision ID or revision object.
- * @param bool $link Optional, default is true. Link to revisions's page?
- * @return string gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
+ * @param bool       $link     Optional, default is true. Link to revisions's page?
+ * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
  */
 function wp_post_revision_title_expanded( $revision, $link = true ) {
        if ( !$revision = get_post( $revision ) )
@@ -1693,7 +1658,7 @@ function wp_post_revision_title_expanded( $revision, $link = true ) {
 
        $author = get_the_author_meta( 'display_name', $revision->post_author );
        /* translators: revision date format, see http://php.net/date */
-       $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
+       $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
 
        $gravatar = get_avatar( $revision->post_author, 24 );
 
@@ -1718,7 +1683,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 );
 }
 
 /**
@@ -1731,7 +1706,6 @@ function wp_post_revision_title_expanded( $revision, $link = true ) {
  *
  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  * @param string      $type    'all' (default), 'revision' or 'autosave'
- * @return null
  */
 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
        if ( ! $post = get_post( $post_id ) )