X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..073c5ed6408e2f00dc1863b463fe205467628905:/wp-includes/post-formats.php diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index cdb9da5d..7800ba0b 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -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,10 +36,8 @@ function get_post_format( $post = null ) { * * @since 3.1.0 * - * @uses has_term() - * - * @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 ) { @@ -59,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 ); @@ -108,8 +106,6 @@ function get_post_format_strings() { * * @since 3.1.0 * - * @uses get_post_format_strings() - * * @return array The array of post format slugs. */ function get_post_format_slugs() { @@ -122,8 +118,6 @@ function get_post_format_slugs() { * * @since 3.1.0 * - * @uses get_post_format_strings() - * * @param string $slug A post format slug. * @return string The translated post format name. */ @@ -141,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' ); @@ -155,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'] ) ) @@ -167,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 { @@ -186,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 ) ) { @@ -200,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 { @@ -224,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 ) { @@ -240,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' );