]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/post-template.php
WordPress 4.2
[autoinstalls/wordpress.git] / wp-includes / post-template.php
index f13a458b566c3839472ebd03b59b1e6f4f1f8fc3..2a6569f29812c4422acd518e9d9ee5fb0d8f7ab1 100644 (file)
@@ -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.
@@ -172,7 +172,16 @@ function get_the_title( $post = 0 ) {
  * @param int|WP_Post $id Optional. Post ID or post object.
  */
 function the_guid( $id = 0 ) {
-       echo esc_url( get_the_guid( $id ) );
+       /**
+        * Filter the escaped Global Unique Identifier (guid) of the post.
+        *
+        * @since 4.2.0
+        *
+        * @see get_the_guid()
+        *
+        * @param string $post_guid Escaped Global Unique Identifier (guid) of the post.
+        */
+       echo apply_filters( 'the_guid', get_the_guid( $id ) );
 }
 
 /**
@@ -389,26 +398,35 @@ 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 );
+       }
+
+       if ( ! $post ) {
                return $classes;
+       }
 
        $classes[] = 'post-' . $post->ID;
        if ( ! is_admin() )
@@ -446,31 +464,31 @@ 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.
@@ -566,7 +584,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 +595,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,7 +668,7 @@ 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';
 
        $page = $wp_query->get( 'page' );
@@ -940,8 +973,26 @@ 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.
  *
- * @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.
+ *                                               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 = '' ) {
@@ -950,7 +1001,8 @@ function wp_dropdown_pages( $args = '' ) {
                'selected' => 0, 'echo' => 1,
                'name' => 'page_id', 'id' => '',
                'show_option_none' => '', 'show_option_no_change' => '',
-               'option_none_value' => ''
+               'option_none_value' => '',
+               'value_field' => 'ID',
        );
 
        $r = wp_parse_args( $args, $defaults );
@@ -1108,18 +1160,17 @@ function wp_list_pages( $args = '' ) {
  * @since 2.7.0
  *
  * @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_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|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'.
  * }
  * @return string html menu
  */
@@ -1404,15 +1455,20 @@ class Walker_PageDropdown extends Walker {
         * @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 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. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
         * @param int $id
         */
        public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
                $pad = str_repeat(' ', $depth * 3);
 
-               $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
+               if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
+                       $args['value_field'] = 'ID';
+               }
+
+               $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
                if ( $page->ID == $args['selected'] )
                        $output .= ' selected="selected"';
                $output .= '>';
@@ -1523,7 +1579,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 +1590,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">';
@@ -1595,12 +1651,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,6 +1672,14 @@ function is_page_template( $template = '' ) {
        if ( $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;
+               }
+       }
+
        if ( 'default' == $template && ! $page_template )
                return true;
 
@@ -1657,7 +1722,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 */
@@ -1693,7 +1758,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 );