%s',
esc_url( $attr['url'] ),
$is_amp ? 'placeholder fallback' : '',
esc_html__( 'Register on Eventbrite', 'jetpack' )
);
if ( $is_amp ) {
$embed = sprintf(
'%s',
esc_url(
add_query_arg(
array(
'eid' => $attr['eventId'],
'parent' => rawurlencode( get_current_url() ),
),
'https://www.eventbrite.com/checkout-external'
)
),
esc_html__( 'Expand', 'jetpack' ),
$direct_link
);
} else {
$embed = $direct_link;
wp_enqueue_script( 'eventbrite-widget', 'https://www.eventbrite.com/static/widgets/eb_widgets.js', array(), JETPACK__VERSION, true );
// Add CSS to hide direct link.
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
wp_add_inline_script(
'eventbrite-widget',
"window.EBWidgets.createWidget( {
widgetType: 'checkout',
eventId: " . absint( $attr['eventId'] ) . ',
iframeContainerId: ' . wp_json_encode( $widget_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ',
} );'
);
}
return sprintf(
'
%3$s
',
esc_attr( $widget_id ),
esc_attr( $classes ),
$embed
);
}
/**
* Render block with modal style.
*
* @param string $widget_id Widget ID to use.
* @param bool $is_amp Whether AMP page.
* @param array $attr Eventbrite block attributes.
* @param string $content Rendered embed element (without scripts) from the block editor.
* @return string Rendered block.
*/
function render_modal_block( $widget_id, $is_amp, $attr, $content ) {
if ( $is_amp ) {
$lightbox_id = "{$widget_id}-lightbox";
// Add CSS to for lightbox.
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
$content = preg_replace(
'/\shref="#" target="_blank/',
sprintf( ' on="%s" ', esc_attr( "tap:{$lightbox_id}.open" ) ),
$content
);
$iframe_src = add_query_arg(
array(
// Note that modal=1 is intentionally omitted here since we need to put the close button inside the amp-lightbox.
'eid' => $attr['eventId'],
'parent' => rawurlencode( get_current_url() ),
),
'https://www.eventbrite.com/checkout-external'
);
$lightbox = sprintf(
'%3$s',
esc_attr( $lightbox_id ),
esc_attr( "tap:{$lightbox_id}.close" ),
sprintf(
'
',
esc_url( $iframe_src ),
esc_attr( "tap:{$lightbox_id}.close" ),
esc_attr__( 'Close', 'jetpack' )
)
);
$content = preg_replace(
':(?=\s*$):',
$lightbox,
$content
);
return $content;
}
wp_enqueue_script( 'eventbrite-widget', 'https://www.eventbrite.com/static/widgets/eb_widgets.js', array(), JETPACK__VERSION, true );
// Show the modal version.
wp_add_inline_script(
'eventbrite-widget',
"window.EBWidgets.createWidget( {
widgetType: 'checkout',
eventId: " . absint( $attr['eventId'] ) . ',
modal: true,
modalTriggerElementId: ' . wp_json_encode( $widget_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ',
} );'
);
/*
* Modal button is saved as an `` element with `role="button"` because `