PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 508 releases
← All changes | modules/shortcodes/inline-pdfs.php +40 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,40 @@
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 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit( 0 );
13 +}
14 +
15 +wp_embed_register_handler( 'inline-pdfs', '#https?://[^<]*\.pdf$#i', 'jetpack_inline_pdf_embed_handler' );
16 +
17 +/**
18 + * Callback to modify the output of embedded PDF files.
19 + *
20 + * @param array $matches Regex partial matches against the URL passed.
21 + * @param array $attr Attributes received in embed response.
22 + * @param array $url Requested URL to be embedded.
23 + */
24 +function jetpack_inline_pdf_embed_handler( $matches, $attr, $url ) {
25 + /** This action is documented in modules/widgets/social-media-icons.php */
26 + do_action( 'jetpack_bump_stats_extras', 'embeds', 'inline-pdf' );
27 +
28 + $filename = basename( wp_parse_url( $url, PHP_URL_PATH ) );
29 + $fallback_text = sprintf(
30 + /* translators: Placeholder is a file name, for example "file.pdf" */
31 + esc_html__( 'Click to access %1$s', 'jetpack' ),
32 + $filename
33 + );
34 +
35 + return sprintf(
36 + '<p><a href="%1$s" target="_blank" rel="noopener noreferrer nofollow">%2$s</a></p>',
37 + esc_url( $url ),
38 + $fallback_text
39 + );
40 +}