Skip to content

Commit

Permalink
Goodreads Block: Make sure we check for id attribute in the goodreads…
Browse files Browse the repository at this point in the history
… block, when rendering (#39713)

* Make sure we check for id attribute in the goodreads block, before attempting to use it for rendering as id of the div.

* changelog
  • Loading branch information
oskosk authored Oct 10, 2024
1 parent 05de241 commit 90f7d63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Fixed rendering of goodreads block when there is not id attribute so to not result in a PHP warning
28 changes: 18 additions & 10 deletions projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,27 @@ function register_block() {
function load_assets( $attr ) {
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );

if ( isset( $attr['link'] ) && isset( $attr['id'] ) ) {
wp_enqueue_script(
'jetpack-goodreads-' . esc_attr( $attr['id'] ),
esc_url_raw( $attr['link'] ),
array(),
JETPACK__VERSION,
true
);
if ( isset( $attr['id'] ) ) {
if ( isset( $attr['link'] ) ) {
wp_enqueue_script(
'jetpack-goodreads-' . esc_attr( $attr['id'] ),
esc_url_raw( $attr['link'] ),
array(),
JETPACK__VERSION,
true
);
}

$id = esc_attr( $attr['id'] );
} else {
$id = '';
}

$classes = esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) );

return sprintf(
'<div id="%1$s" class="%2$s"></div>',
esc_attr( $attr['id'] ),
esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) )
$id,
$classes
);
}

0 comments on commit 90f7d63

Please sign in to comment.