PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 10.5.3
Jetpack – WP Security, Backup, Speed, & Growth v10.5.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / modules / shortcodes / inline-pdfs.php
inline-pdfs.php
37 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 automattic/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 $filename = basename( wp_parse_url( $url, PHP_URL_PATH ) );
25 $fallback_text = sprintf(
26 /* translators: Placeholder is a file name, for example "file.pdf" */
27 esc_html__( 'Click to access %1$s', 'jetpack' ),
28 $filename
29 );
30
31 return sprintf(
32 '<p><a href="%1$s" target="_blank" rel="noopener noreferrer nofollow">%2$s</a></p>',
33 esc_url( $url ),
34 $fallback_text
35 );
36 }
37