update get_image_id

This commit is contained in:
Robin Cornett
2015-03-23 10:10:32 -04:00
parent fd5f03e6b7
commit 64bfa88ca4
@@ -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 );