PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.2-beta
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 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / pinterest.php

pinterest.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2-beta, at modules/shortcodes/pinterest.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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