Completed
Push — add/inline-pdf-embed ( bdc34e )
by
unknown
09:17 queued 02:56
created

inline-pdfs.php ➔ inline_pdf_embed_handler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Inline PDFs
5
 * Takes one-line embeds of a PDF URL (*.pdf), and attempts to embed it directly in the post instead of leaving it as a link.
6
 */
7
wp_embed_register_handler( 'inline-pdfs', '#https?://[^<]*\.pdf$#i', 'inline_pdf_embed_handler' );
8
9
function inline_pdf_embed_handler( $matches, $attr, $url ) {
10
	return sprintf(
11
		'<object data="%1$s" type="application/pdf" width="100%%" height="800">
12
		  <p><a href="%1$s">%2$s</a></p>
13
		</object>',
14
		esc_attr( $url )
15
	);
16
}
17