css
2 weeks ago
images
1 year ago
img
4 weeks ago
js
6 months ago
archiveorg-book.php
6 months ago
archiveorg.php
6 months ago
archives.php
2 weeks ago
bandcamp.php
6 months ago
brightcove.php
5 months ago
cartodb.php
6 months ago
class.filter-embedded-html-objects.php
6 months ago
codepen.php
6 months ago
crowdsignal.php
5 months ago
dailymotion.php
6 months ago
descript.php
6 months ago
facebook.php
6 months ago
flatio.php
6 months ago
flickr.php
5 months ago
getty.php
6 months ago
gist.php
6 months ago
googleapps.php
6 months ago
googlemaps.php
3 weeks ago
googleplus.php
6 months ago
gravatar.php
6 months ago
houzz.php
6 months ago
inline-pdfs.php
6 months ago
instagram.php
6 months ago
kickstarter.php
6 months ago
mailchimp.php
5 months ago
medium.php
6 months ago
mixcloud.php
6 months ago
others.php
6 months ago
pinterest.php
6 months ago
presentations.php
6 months ago
quiz.php
6 months ago
recipe.php
6 months ago
scribd.php
6 months ago
shortcode-utils.php
6 months ago
sitemap.php
6 months ago
slideshare.php
6 months ago
slideshow.php
4 weeks ago
smartframe.php
6 months ago
soundcloud.php
6 months ago
spotify.php
6 months ago
ted.php
6 months ago
tweet.php
6 months ago
twitchtv.php
6 months ago
twitter-timeline.php
6 months ago
twitter.php
6 months ago
unavailable.php
6 months ago
untappd-menu.php
6 months ago
upcoming-events.php
6 months ago
ustream.php
6 months ago
videopress.php
6 months ago
vimeo.php
1 week ago
vine.php
6 months ago
vr.php
1 week ago
wufoo.php
6 months ago
youtube.php
3 months ago
pinterest.php
69 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Pinterest embeds |
| 4 | * |
| 5 | * Based on "Board Widget" example here: http://business.pinterest.com/widget-builder/#code |
| 6 | * |
| 7 | * Example URL: https://pinterest.com/pin/129056345550241149/ |
| 8 | * Second Example URL: https://uk.pinterest.com/annsawesomepins/travel/ |
| 9 | * |
| 10 | * @package automattic/jetpack |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit( 0 ); |
| 15 | } |
| 16 | |
| 17 | wp_embed_register_handler( |
| 18 | 'pinterest', |
| 19 | '#' |
| 20 | . 'https?://' |
| 21 | . '(?:www\.)?' |
| 22 | . '(?:[a-z]{2}\.)?' |
| 23 | . 'pinterest\.[a-z.]+/' |
| 24 | . '([^/]+)' |
| 25 | . '(/[^/]+)?' |
| 26 | . '#', |
| 27 | 'pinterest_embed_handler' |
| 28 | ); |
| 29 | |
| 30 | /** |
| 31 | * Callback to modify output of embedded Pinterest posts. |
| 32 | * |
| 33 | * @param array $matches Regex partial matches against the URL passed. |
| 34 | * @param array $attr Attributes received in embed response. |
| 35 | * @param array $url Requested URL to be embedded. |
| 36 | */ |
| 37 | function pinterest_embed_handler( $matches, $attr, $url ) { |
| 38 | // Pinterest's JS handles making the embed. |
| 39 | $script_src = '//assets.pinterest.com/js/pinit.js'; |
| 40 | |
| 41 | wp_enqueue_script( 'pinterest-embed', $script_src, array(), JETPACK__VERSION, true ); |
| 42 | |
| 43 | $path = wp_parse_url( $url, PHP_URL_PATH ); |
| 44 | if ( str_starts_with( $path, '/pin/' ) ) { |
| 45 | $embed_type = 'embedPin'; |
| 46 | } elseif ( preg_match( '#^/([^/]+)/?$#', $path ) ) { |
| 47 | $embed_type = 'embedUser'; |
| 48 | } elseif ( preg_match( '#^/([^/]+)/([^/]+)/?$#', $path ) ) { |
| 49 | $embed_type = 'embedBoard'; |
| 50 | } else { |
| 51 | if ( current_user_can( 'edit_posts' ) ) { |
| 52 | return __( 'Sorry, that Pinterest URL was not recognized.', 'jetpack' ); |
| 53 | } |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | $return = sprintf( '<a data-pin-do="%s" href="%s"></a>', esc_attr( $embed_type ), esc_url( $url ) ); |
| 58 | |
| 59 | // If we're generating an embed view for the WordPress Admin via ajax. |
| 60 | if ( doing_action( 'wp_ajax_parse-embed' ) ) { |
| 61 | $return .= sprintf( |
| 62 | '<script src="%s"></script>', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 63 | esc_url( $script_src ) |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | return $return; |
| 68 | } |
| 69 |