Thanks for the report. I’ll include this change in the next version.
After a bit of thought, it seems like the only way this can happen is if there was an error executing the query, or if the row in question has no ID. Can you check if either of those is the case?
I have not searched the database yet.
Don’t have phpMySQL access to this database, and still learning WordPress, but I will look into it later.
So far, I see:
* When I embedded the pdf in a post, I used …/?attachment_id=491
* When the media page is embedded, in twenty thirteen, the url is …/wp-content/uploads/2014/04/Calendar+Of+Events+2013.pdf
I will get back to you with more after I practice doing database calls from wordpress.
Here’s the issue I’m having:
The file is stored in _posts with its full URL.
The query could not match it.
I came up with:
$wpdb->prepare(
"SELECT ID FROM " . $prefix . "posts WHERE guid LIKE %s;",
'%' . $parse_url[1]
) ;
which comes out to
get_attachment_id_by_url query SELECT ID FROM wptest_posts WHERE guid LIKE '%/uploads/2014/04/Calendar+Of+Events+2013.pdf';
And this seems to work. Now, I match one record. After I remove all the debug echo statements, I am almost certain I’ll have it working again.
I like your plugin very much. I am new to wordpress, and it would have taken me weeks to learn enough to write something like this myself. I hope my comments are helpful.
In addition to the get_col array return fix above,
1) In the SQL, you need to use RLIKE with a pre-processed pattern (\\ for special chars and $ at the end), or else use ‘… LIKE %%%1$s’ (File names can contain regexp special characters)
2)Your autoembedder will autoembed even /zoom.jpg in a pdf object. Perhaps the embed handler regexp should be something more like ‘#^’ . home_url() .’.*\.pdf$#i’
3) In fact, why not make it ‘#^’ . home_url() .’/.*\.pdf$#i’
to prevent autoembedding http://mywebsite.org.badwebsite.com/MaliciousFile.pdf
It never hurts to be careful.
4) Of course, you can still autoembed http://mywebsite.org/NotInUploadDirectory.pdf, which is a nice feature you could mention in your extended description.
Why don’t we move this conversation to github? You can open issues or pull requests as you see fit there — https://github.com/doherty/WP-vanilla-pdf-embed