Completed
Push — add/inline-pdf-embed ( f25daf...54134e )
by
unknown
10:58 queued 04:30
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
 * Embed support for Inline PDFs
4
 *
5
 * Takes a plain-text PDF URL (*.pdf), and attempts to embed it directly
6
 * in the post instead of leaving it as a bare link.
7
 *
8
 * @package Jetpack
9
 */
10
11
wp_embed_register_handler( 'inline-pdfs', '#https?://[^<]*\.pdf$#i', 'jetpack_inline_pdf_embed_handler' );
12
13
/**
14
 * Callback to modify the output of embedded PDF files.
15
 *
16
 * @param array $matches Regex partial matches against the URL passed.
17
 * @param array $attr    Attributes received in embed response.
18
 * @param array $url     Requested URL to be embedded.
19
 */
20
function jetpack_inline_pdf_embed_handler( $matches, $attr, $url ) {
21
	/** This action is documented in modules/widgets/social-media-icons.php */
22
	do_action( 'jetpack_bump_stats_extras', 'embeds', 'inline-pdf' );
23
24
	return sprintf(
25
		'<object data="%1$s" type="application/pdf" width="100%%" height="800">
26
		  <p><a href="%1$s">%1$s</a></p>
27
		</object>',
28
		esc_attr( $url )
29
	);
30
}
31