• Resolved Angelina Belle

    (@angelina-belle)


    Thanks for the very useful plugin, and thanks for making your code easy to read and modify.

    A funny thing happened when I viewed a media page in theme twentythirteen.

    In get_attachment_id_by_url, apparently $attachment was returned as an empty array.

    To fix this, I merely replaced
    if ( ! is_array($attachment)
    with
    if ( (! is_array($attachment) )||(! isset($attachment[0])) )

    And all is well again. The pdf file is embedded in the media page.
    I am not sure why auto-embedding worked fine elsewhere, but not on the media page.

    https://wordpress.org/plugins/vanilla-pdf-embed/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mike Doherty

    (@_doherty)

    Thanks for the report. I’ll include this change in the next version.

    Plugin Author Mike Doherty

    (@_doherty)

    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?

    Thread Starter Angelina Belle

    (@angelina-belle)

    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.

    Thread Starter Angelina Belle

    (@angelina-belle)

    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.

    Thread Starter Angelina Belle

    (@angelina-belle)

    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.

    Plugin Author Mike Doherty

    (@_doherty)

    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

    Thread Starter Angelina Belle

    (@angelina-belle)

    Will do!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘offset 0 not found — $attachment’ is closed to new replies.