Skip to content

Commit

Permalink
Slideshow: do not render markup when user doesn't select any images (#…
Browse files Browse the repository at this point in the history
…16231)

* Slideshow: do not render markup when images === 0

* Slideshow: do not render markup when images === 0 in AMP mode

* Slideshow: return early when images === 0

* Slideshow: remove empty line

Co-authored-by: cpap <papazoglou.charalampos@gmail.com>
  • Loading branch information
cpapazoglou and cpap authored Jun 25, 2020
1 parent 650a54a commit 3b5cf19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions extensions/blocks/slideshow/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class Slideshow extends Component {
};

render() {
// If user has not selected any images, don't print any markup.
if ( ! this.props?.images?.length ) {
return null;
}

const { autoplay, className, delay, effect, images } = this.props;
// Note: React omits the data attribute if the value is null, but NOT if it is false.
// This is the reason for the unusual logic related to autoplay below.
Expand Down
6 changes: 5 additions & 1 deletion extensions/blocks/slideshow/slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ function load_assets( $attr, $content ) {
* @return string
*/
function render_amp( $attr ) {
if ( empty( $attr['ids'] ) ) {
return '';
}

static $wp_block_jetpack_slideshow_id = 0;
$wp_block_jetpack_slideshow_id++;

$ids = empty( $attr['ids'] ) ? array() : $attr['ids'];
$ids = $attr['ids'];
$autoplay = empty( $attr['autoplay'] ) ? false : true;
$extras = array(
'wp-amp-block',
Expand Down

0 comments on commit 3b5cf19

Please sign in to comment.