[Bug] attachment_url_to_postid is not handled correctly
-
The URL used to search is the BLOB url, which is contained within _wp_attachment_metadata’ instead of ‘_wp_attached_file’.
I’m not sure if there is a better way around this, but this filter searches _wp_attachment_metadata instead. Perhaps ‘windows_azure_storage_info’ would be more appropriate?
add_filter('attachment_url_to_postid','azure_fix_attachment_url_to_image',99,2); function azure_fix_attachment_url_to_image( $post_id, $url ) { global $wpdb; $dir = wp_upload_dir(); $path = $url; $site_url = parse_url( $dir['url'] ); $image_path = parse_url( $path ); //force the protocols to match if needed if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) { $path = str_replace( $image_path['scheme'], $site_url['scheme'], $path ); } if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) { $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); } $sql = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%%%s%%'", $path ); $post_id = $wpdb->get_var( $sql ); return (int) $post_id; }
- The topic ‘[Bug] attachment_url_to_postid is not handled correctly’ is closed to new replies.