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 6 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
39 changes: 38 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(
'giphy',
array(
'render_callback' => 'jetpack_giphy_block_load_assets',
jeffersonrabb marked this conversation as resolved.
Show resolved Hide resolved
)
);

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

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

ob_start();
?>
<div class="wp-block-jetpack-giphy align<?php echo esc_attr( $align ); ?>">
<figure style="<?php echo esc_attr( $style ); ?>">
<iframe src="<?php echo esc_attr( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe>
jeffersonrabb marked this conversation as resolved.
Show resolved Hide resolved
</figure>
<?php if ( $caption ) : ?>
<p class="wp-block-jetpack-giphy-caption"><?php echo wp_kses_post( $caption ); ?></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlighting for reviewers the use of wp_kses_post here.

<?php endif; ?>
</div>
<?php
$html = ob_get_clean();

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

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