From de589f8ebee38c766d7261b41b939235ffb97a21 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 14 May 2013 13:57:59 +0000 Subject: [PATCH] Remove redundant post ID validation. Props SergeyBiryukov fixes #24199 git-svn-id: https://develop.svn.wordpress.org/trunk@24249 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/media.php | 21 +++++++++++++-------- wp-includes/post-formats.php | 21 +++++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 7e7cff4591..368c7f2cac 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1850,8 +1850,7 @@ function wp_enqueue_media( $args = array() ) { * @return array Found attachments */ function get_attached_media( $type, $post_id = 0 ) { - $post = empty( $post_id ) ? get_post() : get_post( $post_id ); - if ( empty( $post ) ) + if ( ! $post = get_post( $post_id ) ) return; $args = array( @@ -2340,8 +2339,10 @@ function get_content_galleries( &$content, $html = true, $remove = false, $limit * from the expanded shortcode */ function get_post_galleries( $post_id = 0, $html = true ) { - $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); - if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) + if ( ! $post = get_post( $post_id ) ) + return array(); + + if ( ! has_shortcode( $post->post_content, 'gallery' ) ) return array(); return get_content_galleries( $post->post_content, $html ); @@ -2357,8 +2358,10 @@ function get_post_galleries( $post_id = 0, $html = true ) { * from an expanded shortcode */ function get_post_galleries_images( $post_id = 0 ) { - $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); - if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) + if ( ! $post = get_post( $post_id ) ) + return array(); + + if ( ! has_shortcode( $post->post_content, 'gallery' ) ) return array(); $data = get_content_galleries( $post->post_content, false ); @@ -2375,8 +2378,10 @@ function get_post_galleries_images( $post_id = 0 ) { * @return array Gallery data and srcs parsed from the expanded shortcode */ function get_post_gallery( $post_id = 0, $html = true ) { - $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); - if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) + if ( ! $post = get_post( $post_id ) ) + return array(); + + if ( ! has_shortcode( $post->post_content, 'gallery' ) ) return array(); $data = get_content_galleries( $post->post_content, $html, false, 1 ); diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 6f5797989a..6ef2aaa0cc 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -316,12 +316,11 @@ function post_format_content_class( $format ) { * @uses get_post_format_meta() * * @param string $content The post content. - * @param int $id (optional) The post ID. + * @param int $post_id (optional) The post ID. * @return string Formatted output based on associated post format. */ -function post_formats_compat( $content, $id = 0 ) { - $post = empty( $id ) ? get_post() : get_post( $id ); - if ( empty( $post ) ) +function post_formats_compat( $content, $post_id = 0 ) { + if ( ! $post = get_post( $post_id ) ) return $content; $format = get_post_format( $post ); @@ -639,12 +638,11 @@ function get_content_chat( &$content, $remove = false ) { * * @since 3.6.0 * - * @param int $id (optional) The post ID. + * @param int $post_id (optional) The post ID. * @return array The chat content. */ -function get_the_post_format_chat( $id = 0 ) { - $post = empty( $id ) ? clone get_post() : get_post( $id ); - if ( empty( $post ) ) +function get_the_post_format_chat( $post_id = 0 ) { + if ( ! $post = get_post( $post_id ) ) return array(); $data = get_content_chat( get_paged_content( $post->post_content ) ); @@ -814,12 +812,11 @@ function get_content_url( &$content, $remove = false ) { * * @since 3.6.0 * - * @param int $id (optional) The post ID. + * @param int $post_id (optional) The post ID. * @return string A URL, if found. */ -function get_the_post_format_url( $id = 0 ) { - $post = empty( $id ) ? get_post() : get_post( $id ); - if ( empty( $post ) ) +function get_the_post_format_url( $post_id = 0 ) { + if ( ! $post = get_post( $post_id ) ) return ''; $format = get_post_format( $post->ID );