PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
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 13.7.2 13.8.3 All 506 releases
← All changes | extensions/blocks/pinterest/pinterest.php +10 -4 13.3.3 → 16.3-a.5 View file →
@@ -13,10 +13,15 @@
13 13
14 14 namespace Automattic\Jetpack\Extensions\Pinterest;
15 15
16 16 use Automattic\Jetpack\Blocks;
17 +use Automattic\Jetpack\Status\Request;
17 18 use WP_Error;
18 19
20 +if ( ! defined( 'ABSPATH' ) ) {
21 + exit( 0 );
22 +}
23 +
19 24 const URL_PATTERN = '#^https?://(?:www\.)?(?:[a-z]{2}\.)?pinterest\.[a-z.]+/pin/(?P<pin_id>[^/]+)/?#i'; // Taken from AMP plugin, originally from Jetpack.
20 25 // This is the validate Pinterest URLs, converted from URL_REGEX in extensions/blocks/pinterest/index.js.
21 26 const PINTEREST_URL_REGEX = '/^https?:\/\/(?:www\.)?(?:[a-z]{2}\.)?(?:pinterest\.[a-z.]+|pin\.it)\/([^\/]+)(\/[^\/]+)?/i';
22 27 // This looks for matches in /foo/ of https://www.pinterest.ca/foo/.
@@ -27,9 +32,9 @@
27 32 /**
28 33 * Determines the Pinterest embed type from the URL.
29 34 *
30 35 * @param string $url the URL to check.
31 - * @returns {string} The pin type. Empty string if it isn't a valid Pinterest URL.
36 + * @return string The pin type. Empty string if it isn't a valid Pinterest URL.
32 37 */
33 38 function pin_type( $url ) {
34 39 if ( null === $url || ! preg_match( PINTEREST_URL_REGEX, $url ) ) {
35 40 return '';
@@ -141,10 +146,10 @@
141 146 }
142 147
143 148 if ( is_array( $info ) ) {
144 149 $image = $info['images']['237x'];
145 - $title = isset( $info['rich_metadata']['title'] ) ? $info['rich_metadata']['title'] : null;
146 - $description = isset( $info['rich_metadata']['description'] ) ? $info['rich_metadata']['description'] : null;
150 + $title = $info['rich_metadata']['title'] ?? null;
151 + $description = $info['rich_metadata']['description'] ?? null;
147 152
148 153 // This placeholder will appear while waiting for the amp-pinterest component to initialize (or if it fails to initialize due to JS being disabled).
149 154 $placeholder = sprintf(
150 155 // The AMP_Img_Sanitizer will convert his to <amp-img> while also supplying `noscript > img` as fallback when JS is disabled.
@@ -219,11 +224,12 @@
219 224 *
220 225 * @return string
221 226 */
222 227 function load_assets( $attr, $content ) {
223 - if ( ! jetpack_is_frontend() ) {
228 + if ( ! Request::is_frontend() ) {
224 229 return $content;
225 230 }
231 + $attr['url'] ??= '';
226 232 if ( Blocks::is_amp_request() ) {
227 233 return render_amp_pin( $attr );
228 234 } else {
229 235 $url = $attr['url'];