PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
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/gif/gif.php +9 -46 12.1.3 → 16.3-a.7 View file →
@@ -9,12 +9,12 @@
9 9
10 10 namespace Automattic\Jetpack\Extensions\Gif;
11 11
12 12 use Automattic\Jetpack\Blocks;
13 -use Jetpack_Gutenberg;
14 13
15 -const FEATURE_NAME = 'gif';
16 -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 17
18 18 /**
19 19 * Registers the block for use in Gutenberg
20 20 * This is done via an action so that we can disable
@@ -21,9 +21,9 @@
21 21 * registration if we need to.
22 22 */
23 23 function register_block() {
24 24 Blocks::jetpack_register_block(
25 - BLOCK_NAME,
25 + __DIR__,
26 26 array( 'render_callback' => __NAMESPACE__ . '\render_block' )
27 27 );
28 28 }
29 29 add_action( 'init', __NAMESPACE__ . '\register_block' );
@@ -30,52 +30,15 @@
30 30
31 31 /**
32 32 * Gif block registration/dependency declaration.
33 33 *
34 + * The render implementation lives in render.php and is only loaded when the
35 + * block is actually rendered, keeping it out of the eager front-end path.
36 + *
34 37 * @param array $attr - Array containing the gif block attributes.
35 38 *
36 39 * @return string
37 40 */
38 41 function render_block( $attr ) {
39 - $padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0;
40 - $style = 'padding-top:' . $padding_top;
41 - $giphy_url = isset( $attr['giphyUrl'] )
42 - ? Jetpack_Gutenberg::validate_block_embed_url( $attr['giphyUrl'], array( 'giphy.com' ) )
43 - : null;
44 - $search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : '';
45 - $caption = isset( $attr['caption'] ) ? $attr['caption'] : null;
46 -
47 - if ( ! $giphy_url ) {
48 - return null;
49 - }
50 -
51 - $classes = Blocks::classes( FEATURE_NAME, $attr );
52 -
53 - $placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) );
54 -
55 - ob_start();
56 - ?>
57 - <div class="<?php echo esc_attr( $classes ); ?>">
58 - <figure>
59 - <?php if ( Blocks::is_amp_request() ) : ?>
60 - <amp-iframe src="<?php echo esc_url( $giphy_url ); ?>" width="100" height="<?php echo absint( $padding_top ); ?>" sandbox="allow-scripts allow-same-origin" layout="responsive">
61 - <div placeholder>
62 - <?php echo wp_kses_post( $placeholder ); ?>
63 - </div>
64 - </amp-iframe>
65 - <?php else : ?>
66 - <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>">
67 - <iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe>
68 - </div>
69 - <?php endif; ?>
70 - <?php if ( $caption ) : ?>
71 - <figcaption class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption>
72 - <?php endif; ?>
73 - </figure>
74 - </div>
75 - <?php
76 - $html = ob_get_clean();
77 -
78 - Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
79 -
80 - return $html;
42 + require_once __DIR__ . '/render.php';
43 + return render_implementation( $attr );
81 44 }