summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury German <blueknight@gentoo.org>2022-01-23 18:37:36 -0500
committerYury German <blueknight@gentoo.org>2022-01-23 18:37:36 -0500
commitf18b23a3a9378fb0a98856d436aa9ebf94e47429 (patch)
treee418433e22854ebd2d77eaa869d5d0470a973317 /plugins/jetpack/extensions/blocks/gif
parentAdd classic-editor 1.5 (diff)
downloadblogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.gz
blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.bz2
blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.zip
Updating Classic Editor, Google Authenticatior, Jetpack, Public Post Preview, Table of Contents, Wordpress Importer
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/extensions/blocks/gif')
-rw-r--r--plugins/jetpack/extensions/blocks/gif/gif.php40
1 files changed, 28 insertions, 12 deletions
diff --git a/plugins/jetpack/extensions/blocks/gif/gif.php b/plugins/jetpack/extensions/blocks/gif/gif.php
index 1ababeeb..cb860e9a 100644
--- a/plugins/jetpack/extensions/blocks/gif/gif.php
+++ b/plugins/jetpack/extensions/blocks/gif/gif.php
@@ -4,15 +4,29 @@
*
* @since 7.0.0
*
- * @package Jetpack
+ * @package automattic/jetpack
*/
-jetpack_register_block(
- 'jetpack/gif',
- array(
- 'render_callback' => 'jetpack_gif_block_render',
- )
-);
+namespace Automattic\Jetpack\Extensions\Gif;
+
+use Automattic\Jetpack\Blocks;
+use Jetpack_Gutenberg;
+
+const FEATURE_NAME = 'gif';
+const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
+
+/**
+ * Registers the block for use in Gutenberg
+ * This is done via an action so that we can disable
+ * registration if we need to.
+ */
+function register_block() {
+ Blocks::jetpack_register_block(
+ BLOCK_NAME,
+ array( 'render_callback' => __NAMESPACE__ . '\render_block' )
+ );
+}
+add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Gif block registration/dependency declaration.
@@ -21,10 +35,12 @@ jetpack_register_block(
*
* @return string
*/
-function jetpack_gif_block_render( $attr ) {
+function render_block( $attr ) {
$padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0;
$style = 'padding-top:' . $padding_top;
- $giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null;
+ $giphy_url = isset( $attr['giphyUrl'] )
+ ? Jetpack_Gutenberg::validate_block_embed_url( $attr['giphyUrl'], array( 'giphy.com' ) )
+ : null;
$search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : '';
$caption = isset( $attr['caption'] ) ? $attr['caption'] : null;
@@ -32,7 +48,7 @@ function jetpack_gif_block_render( $attr ) {
return null;
}
- $classes = Jetpack_Gutenberg::block_classes( 'gif', $attr );
+ $classes = Blocks::classes( FEATURE_NAME, $attr );
$placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) );
@@ -40,7 +56,7 @@ function jetpack_gif_block_render( $attr ) {
?>
<div class="<?php echo esc_attr( $classes ); ?>">
<figure>
- <?php if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) : ?>
+ <?php if ( Blocks::is_amp_request() ) : ?>
<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">
<div placeholder>
<?php echo wp_kses_post( $placeholder ); ?>
@@ -59,7 +75,7 @@ function jetpack_gif_block_render( $attr ) {
<?php
$html = ob_get_clean();
- Jetpack_Gutenberg::load_assets_as_required( 'gif' );
+ Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
return $html;
}