Skip to content

Commit

Permalink
Change Calendly buttons to a standard link for AMP requests
Browse files Browse the repository at this point in the history
AMP strips out `onClick` handlers, so when the button version of the
block is rendered we should change it to a standard link to the Calendly
appointment page.

We could probably get aronud this by attaching the click handler in
another way, but it would still be good to treat an AMP request
differently.
  • Loading branch information
pablinos committed Feb 17, 2020
1 parent cb1e169 commit b97687f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extensions/blocks/calendly/calendly.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function load_assets( $attr, $content ) {
$submit_button_text_color = get_attribute( $attr, 'customTextButtonColor' );
$submit_button_background_color = get_attribute( $attr, 'customBackgroundButtonColor' );
$classes = \Jetpack_Gutenberg::block_classes( 'calendly', $attr );
$is_amp_request = class_exists( 'Jetpack_AMP_Support' ) && \Jetpack_AMP_Support::is_amp_request();
$block_id = wp_unique_id( 'calendly-block-' );

$url = add_query_arg(
Expand Down Expand Up @@ -139,8 +140,11 @@ function load_assets( $attr, $content ) {
wp_add_inline_style( 'jetpack-calendly-external-css', $inline_styles );
}

$markup = $is_amp_request
? '<div class="%1$s" id="%2$s"><a class="wp-block-button__link" role="button" href="%3$s">%4$s</a></div>'
: '<div class="%1$s" id="%2$s"><a class="wp-block-button__link" role="button" onclick="Calendly.initPopupWidget({url:\'%3$s\'});return false;">%4$s</a></div>';
$content = sprintf(
'<div class="%1$s" id="%2$s"><a class="wp-block-button__link" role="button" onclick="Calendly.initPopupWidget({url:\'%3$s\'});return false;">%4$s</a></div>',
$markup,
esc_attr( $classes ),
esc_attr( $block_id ),
esc_js( $url ),
Expand Down

0 comments on commit b97687f

Please sign in to comment.