Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giphy Block Registration #10989

Merged
merged 14 commits into from
Jan 25, 2019
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion modules/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
* Load code specific to Gutenberg blocks which are not tied to a module.
* This file is unusual, and is not an actual `module` as such.
* It is included in ./module-extras.php
*
*/

jetpack_register_block(
'gif',
array(
'render_callback' => 'jetpack_gif_block_render',
)
);

jetpack_register_block(
'map',
array(
Expand Down Expand Up @@ -60,6 +66,50 @@ function jetpack_tiled_gallery_load_block_assets( $attr, $content ) {
}
}

/**
* Gif block registration/dependency declaration.
*
* @param array $attr - Array containing the map block attributes.
*
* @return string
*/
function jetpack_gif_block_render( $attr ) {
$align = isset( $attr['align'] ) ? $attr['align'] : 'center';
$padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0;
sirreal marked this conversation as resolved.
Show resolved Hide resolved
$style = 'padding-top:' . $padding_top;
$giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null;
$search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : '';
$caption = isset( $attr['caption'] ) ? $attr['caption'] : null;

if ( ! $giphy_url ) {
sirreal marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

$classes = array(
'wp-block-jetpack-gif',
'align' . $align,
);
if ( isset( $attr['className'] ) ) {
array_push( $classes, $attr['className'] );
}

ob_start();
?>
<div class="<?php echo esc_attr( implode( $classes, ' ' ) ); ?>">
<figure style="<?php echo esc_attr( $style ); ?>">
<iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe>
</figure>
<?php if ( $caption ) : ?>
<p class="wp-block-jetpack-gif-caption"><?php echo wp_kses_post( $caption ); ?></p>
<?php endif; ?>
</div>
<?php
$html = ob_get_clean();

Jetpack_Gutenberg::load_assets_as_required( 'gif' );
return $html;
}

/**
* Map block registration/dependency declaration.
*
Expand Down