css
10 months ago
images
2 years ago
img
2 years ago
js
9 months ago
archiveorg-book.php
1 year ago
archiveorg.php
1 year ago
archives.php
1 year ago
bandcamp.php
11 months ago
brightcove.php
1 year ago
cartodb.php
1 year ago
class.filter-embedded-html-objects.php
1 year ago
codepen.php
1 year ago
crowdsignal.php
9 months ago
dailymotion.php
1 year ago
descript.php
1 year ago
facebook.php
1 year ago
flatio.php
1 year ago
flickr.php
11 months ago
getty.php
1 year ago
gist.php
1 year ago
googleapps.php
1 year ago
googlemaps.php
1 year ago
googleplus.php
1 year ago
gravatar.php
1 year ago
houzz.php
1 year ago
inline-pdfs.php
1 year ago
instagram.php
1 year ago
kickstarter.php
1 year ago
mailchimp.php
1 year ago
medium.php
1 year ago
mixcloud.php
1 year ago
others.php
1 year ago
pinterest.php
1 year ago
presentations.php
1 year ago
quiz.php
1 year ago
recipe.php
11 months ago
scribd.php
1 year ago
shortcode-utils.php
1 year ago
sitemap.php
1 year ago
slideshare.php
9 months ago
slideshow.php
11 months ago
smartframe.php
1 year ago
soundcloud.php
1 year ago
spotify.php
1 year ago
ted.php
11 months ago
tweet.php
1 year ago
twitchtv.php
1 year ago
twitter-timeline.php
1 year ago
twitter.php
1 year ago
unavailable.php
1 year ago
untappd-menu.php
1 year ago
upcoming-events.php
1 year ago
ustream.php
1 year ago
videopress.php
1 year ago
vimeo.php
1 year ago
vine.php
1 year ago
vr.php
1 year ago
wufoo.php
1 year ago
youtube.php
1 year ago
inline-pdfs.php
41 lines
| 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 | } |
| 41 |