diff --git a/projects/plugins/jetpack/changelog/fix-missing-id-args-goodreads-block b/projects/plugins/jetpack/changelog/fix-missing-id-args-goodreads-block new file mode 100644 index 0000000000000..cbf50937eab07 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-missing-id-args-goodreads-block @@ -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 diff --git a/projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php b/projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php index 7f5eafb3c5467..eb5b8c5723fc3 100644 --- a/projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php +++ b/projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php @@ -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( '
', - esc_attr( $attr['id'] ), - esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ) + $id, + $classes ); }