google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

Insert Into Post after image upload to be more robust against size choices #447

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When I set up CCTM for clients a frequent complaint is the failure of the 
"Insert Into Post" button for the media uploads. It's improved by the new error 
message telling us not to use resized images, but I think it would be better if 
it could just calculate the ID of the attachment directly, rather than failing.

As it happens, I have a function I've been using for ages for just that task 
and it's never broken yet :) If you want it, you can have it.

function get_attachment_id_from_src($image_src) {
    $image_src = preg_replace('/-[\dx]+(?=\.(jpg|jpeg|png|gif|pdf)$)/i', '', $image_src);
    global $wpdb;
    $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
    return $wpdb->get_var($query);
}

NB: It _is_ limited to the specific image types listed... but that could be 
exposed as a setting option somewhere if necessary.

HTH
Alastair

Original issue reported on code.google.com by a...@perchten.co.uk on 23 Jan 2013 at 4:22

GoogleCodeExporter commented 9 years ago
Please, always include your version info.  See #1 here: 
http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Invalid

See Issue #314... there's also another issue that this duplicates.  Try the 
latest version of the code (on the dev branch) because I think there's already 
some improvements there for this issue. Be aware that this selection is always 
going to have problems because the WP code that generates it was never intended 
to be used in other ways.  I've debated removing it entirely.

Original comment by ever...@fireproofsocks.com on 23 Jan 2013 at 5:50