Created
March 22, 2019 04:09
-
-
Save msaari/8ff5cc1de25e512a5b9189b6bad89c6d to your computer and use it in GitHub Desktop.
Index PDFs embedded with pdfjs-viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'relevanssi_content_to_index', 'rlv_pdfjs_content', 10, 2 ); | |
| function rlv_pdfjs_content( $content, $post ) { | |
| $m = preg_match_all( '/\[pdfjs-viewer url="(.*)"/', $post->post_content, $matches ); | |
| if ( $m ) { | |
| global $wpdb; | |
| $upload_dir = wp_upload_dir(); | |
| foreach ( $matches[1] as $pdf ) { | |
| $pdf_url = ltrim( str_replace( $upload_dir['baseurl'], '', urldecode( $pdf ) ), '/' ); | |
| $pdf_content = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_relevanssi_pdf_content' AND post_id IN ( SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s )", $pdf_url ) ); | |
| $content .= $pdf_content; | |
| } | |
| } | |
| return $content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment