From 64bfa88ca43199fed18f0dd795d3e0c0594dc1cb Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 23 Mar 2015 10:10:32 -0400 Subject: [PATCH] update get_image_id --- includes/class-displayfeaturedimagegenesis-common.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index ec28179..18c2daa 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -200,10 +200,15 @@ class Display_Featured_Image_Genesis_Common { * @author Philip Newcomer * @link http://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/ */ - public static function get_image_id( $attachment_url ) { + public static function get_image_id( $attachment_url = '' ) { global $wpdb; $attachment_id = false; + // If there is no url, return. + if ( '' == $attachment_url ) { + return; + } + // Get the upload directory paths $upload_dir_paths = wp_upload_dir(); @@ -211,7 +216,7 @@ class Display_Featured_Image_Genesis_Common { if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) { // If this is the URL of an auto-generated thumbnail, get the URL of the original image - $attachment_url = preg_replace( '(-\d{3,4}x\d{3,4}.)', '.', $attachment_url ); + $attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url ); // Remove the upload path base directory from the attachment URL $attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );