WordPress.org

Forums

vanilla-pdf-embed
False positive on jpgs in gallery (4 posts)

  1. lenasterg
    Member
    Posted 1 year ago #

    Hi.
    Thanks for the great plugin.

    I use it in an installation with various other shorttags and plugins.
    I noticed thata for jps's in a gallery it gave false positive and replaces the src of jpgs with the <object .. template.
    In order to solve this I added the following check about the extention of the $src in vpdfe_pdf_embed_html() function.

    function vpdfe_pdf_embed_html( $src , $title = '' , $w = '100%' , $h = '500em' ) {
        // if $content is a URL pointing to an attachment page on this WordPress
        // site then get the PDF's actual URL
    
        if ( $id = vpdfe_extract_id_from_wp_url( $src ) ) {
            $wp_post = get_post( $id ) ;
            if ( $wp_post->post_type != 'attachment' || $wp_post->post_mime_type != 'application/pdf' ) {
                return ;
            }
            $src = wp_get_attachment_url( $wp_post->ID ) ;
    
            if ( ! isset( $title ) ) {
                $title = $wp_post->post_title ;
            }
        }
    //Check if it is really a pdf
        if ( substr( $src , '-3' ) != 'pdf' ) {
            return ;
        }
        // FitH will fit the page width in the embed window
        $template = '<object class="vanilla-pdf-embed" data="%1$s#page=1&view=FitH" type="application/pdf" %3$s %4$s>
        <p><a href="%1$s">Download the PDF file%2$s.</a></p>
    </object>' ;
    
        return sprintf( $template , esc_url( $src ) , esc_attr( " $title" ) , ($w ? 'width="' . esc_attr( $w ) . '"' : '' ) , ($h ? 'height="' . esc_attr( $h ) . '"' : '' )
                ) ;
    }

    Do you think it will create other problems?

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

  2. Mike Doherty
    Member
    Plugin Author

    Posted 1 year ago #

    That seems like it shouldn't be necessary. A couple lines up, we check for post_mime_type being application/pdf. I'll do some testing and get back to you.

  3. Mike Doherty
    Member
    Plugin Author

    Posted 1 year ago #

    What "gallery" are you talking about? If you're using a plugin, I'll need to test with the same one as you.

  4. Mike Doherty
    Member
    Plugin Author

    Posted 1 year ago #

    If you do [pdf]http://not a PDF and hosted on some other domain[/pdf] then we assume you know what you're doing, and embed it as a PDF... But I think you're talking about something different.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • vanilla-pdf-embed
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic