]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/post-formats.php
Wordpress 4.5.3
[autoinstalls/wordpress.git] / wp-includes / post-formats.php
index ac613f396cd9325450c36eaec6e03e453ae5697a..7800ba0bd64c54ead08be926bb5d1802d8b69e6e 100644 (file)
@@ -11,8 +11,8 @@
  *
  * @since 3.1.0
  *
- * @param int|object $post Post ID or post object. Optional, default is the current post from the loop.
- * @return mixed The format if successful. False otherwise.
+ * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop.
+ * @return string|false The format if successful. False otherwise.
  */
 function get_post_format( $post = null ) {
        if ( ! $post = get_post( $post ) )
@@ -26,7 +26,7 @@ function get_post_format( $post = null ) {
        if ( empty( $_format ) )
                return false;
 
-       $format = array_shift( $_format );
+       $format = reset( $_format );
 
        return str_replace('post-format-', '', $format->slug );
 }
@@ -36,8 +36,8 @@ function get_post_format( $post = null ) {
  *
  * @since 3.1.0
  *
- * @param string|array $format Optional. The format or formats to check.
- * @param object|int $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
+ * @param string|array    $format Optional. The format or formats to check.
+ * @param object|int|null $post   Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
  * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
  */
 function has_post_format( $format = array(), $post = null ) {
@@ -57,15 +57,15 @@ function has_post_format( $format = array(), $post = null ) {
  *
  * @since 3.1.0
  *
- * @param int|object $post The post for which to assign a format.
- * @param string $format A format to assign. Use an empty string or array to remove all formats from the post.
- * @return mixed WP_Error on error. Array of affected term IDs on success.
+ * @param int|object $post   The post for which to assign a format.
+ * @param string     $format A format to assign. Use an empty string or array to remove all formats from the post.
+ * @return array|WP_Error|false WP_Error on error. Array of affected term IDs on success.
  */
 function set_post_format( $post, $format ) {
        $post = get_post( $post );
 
        if ( empty( $post ) )
-               return new WP_Error( 'invalid_post', __( 'Invalid post' ) );
+               return new WP_Error( 'invalid_post', __( 'Invalid post.' ) );
 
        if ( ! empty( $format ) ) {
                $format = sanitize_key( $format );
@@ -135,7 +135,7 @@ function get_post_format_string( $slug ) {
  * @since 3.1.0
  *
  * @param string $format The post format slug.
- * @return string The post format term link.
+ * @return string|WP_Error|false The post format term link.
  */
 function get_post_format_link( $format ) {
        $term = get_term_by('slug', 'post-format-' . $format, 'post_format' );
@@ -149,6 +149,9 @@ function get_post_format_link( $format ) {
  *
  * @access private
  * @since 3.1.0
+ *
+ * @param array $qvs
+ * @return array
  */
 function _post_format_request( $qvs ) {
        if ( ! isset( $qvs['post_format'] ) )
@@ -161,18 +164,25 @@ function _post_format_request( $qvs ) {
                $qvs['post_type'] = $tax->object_type;
        return $qvs;
 }
-add_filter( 'request', '_post_format_request' );
 
 /**
  * Filters the post format term link to remove the format prefix.
  *
  * @access private
  * @since 3.1.0
+ *
+ * @global WP_Rewrite $wp_rewrite
+ *
+ * @param string $link
+ * @param object $term
+ * @param string $taxonomy
+ * @return string
  */
 function _post_format_link( $link, $term, $taxonomy ) {
        global $wp_rewrite;
-       if ( 'post_format' != $taxonomy )
+       if ( 'post_format' != $taxonomy ) {
                return $link;
+       }
        if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) {
                return str_replace( "/{$term->slug}", '/' . str_replace( 'post-format-', '', $term->slug ), $link );
        } else {
@@ -180,13 +190,15 @@ function _post_format_link( $link, $term, $taxonomy ) {
                return add_query_arg( 'post_format', str_replace( 'post-format-', '', $term->slug ), $link );
        }
 }
-add_filter( 'term_link', '_post_format_link', 10, 3 );
 
 /**
  * Remove the post format prefix from the name property of the term object created by get_term().
  *
  * @access private
  * @since 3.1.0
+ *
+ * @param object $term
+ * @return object
  */
 function _post_format_get_term( $term ) {
        if ( isset( $term->slug ) ) {
@@ -194,18 +206,22 @@ function _post_format_get_term( $term ) {
        }
        return $term;
 }
-add_filter( 'get_post_format', '_post_format_get_term' );
 
 /**
  * Remove the post format prefix from the name property of the term objects created by get_terms().
  *
  * @access private
  * @since 3.1.0
+ *
+ * @param array        $terms
+ * @param string|array $taxonomies
+ * @param array        $args
+ * @return array
  */
 function _post_format_get_terms( $terms, $taxonomies, $args ) {
        if ( in_array( 'post_format', (array) $taxonomies ) ) {
                if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) {
-                       foreach( $terms as $order => $name ) {
+                       foreach ( $terms as $order => $name ) {
                                $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
                        }
                } else {
@@ -218,13 +234,15 @@ function _post_format_get_terms( $terms, $taxonomies, $args ) {
        }
        return $terms;
 }
-add_filter( 'get_terms', '_post_format_get_terms', 10, 3 );
 
 /**
  * Remove the post format prefix from the name property of the term objects created by wp_get_object_terms().
  *
  * @access private
  * @since 3.1.0
+ *
+ * @param array $terms
+ * @return array
  */
 function _post_format_wp_get_object_terms( $terms ) {
        foreach ( (array) $terms as $order => $term ) {
@@ -234,4 +252,3 @@ function _post_format_wp_get_object_terms( $terms ) {
        }
        return $terms;
 }
-add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );