summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php')
-rw-r--r--plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php107
1 files changed, 84 insertions, 23 deletions
diff --git a/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php b/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php
index 7be7823a..80641a1c 100644
--- a/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php
+++ b/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php
@@ -28,6 +28,7 @@ function jetpack_mailchimp_block_load_assets( $attr ) {
if ( ! jetpack_mailchimp_verify_connection() ) {
return null;
}
+
$values = array();
$blog_id = ( defined( 'IS_WPCOM' ) && IS_WPCOM )
? get_current_blog_id()
@@ -40,6 +41,9 @@ function jetpack_mailchimp_block_load_assets( $attr ) {
'processingLabel' => esc_html__( 'Processing…', 'jetpack' ),
'successLabel' => esc_html__( 'Success! You\'re on the list.', 'jetpack' ),
'errorLabel' => esc_html__( 'Whoops! There was an error and we couldn\'t process your subscription. Please reload the page and try again.', 'jetpack' ),
+ 'interests' => array(),
+ 'signupFieldTag' => '',
+ 'signupFieldValue' => '',
);
foreach ( $defaults as $id => $default ) {
$values[ $id ] = isset( $attr[ $id ] ) ? $attr[ $id ] : $default;
@@ -47,17 +51,7 @@ function jetpack_mailchimp_block_load_assets( $attr ) {
$values['submitButtonText'] = empty( $values['submitButtonText'] ) ? $defaults['submitButtonText'] : $values['submitButtonText'];
- /* TODO: replace with centralized block_class function */
- $align = isset( $attr['align'] ) ? $attr['align'] : 'center';
- $type = 'mailchimp';
- $classes = array(
- 'wp-block-jetpack-' . $type,
- 'align' . $align,
- );
- if ( isset( $attr['className'] ) ) {
- array_push( $classes, $attr['className'] );
- }
- $classes = implode( $classes, ' ' );
+ $classes = Jetpack_Gutenberg::block_classes( 'mailchimp', $attr );
$button_styles = array();
if ( ! empty( $attr['customBackgroundButtonColor'] ) ) {
@@ -78,13 +72,27 @@ function jetpack_mailchimp_block_load_assets( $attr ) {
)
);
}
- $button_styles = implode( $button_styles, ';' );
+ $button_styles = implode( ';', $button_styles );
+ $amp_form_action = sprintf( 'https://public-api.wordpress.com/rest/v1.1/sites/%s/email_follow/amp/subscribe/', $blog_id );
+ $is_amp_request = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
ob_start();
?>
+
<div class="<?php echo esc_attr( $classes ); ?>" data-blog-id="<?php echo esc_attr( $blog_id ); ?>">
<div class="components-placeholder">
- <form aria-describedby="wp-block-jetpack-mailchimp_consent-text">
+ <form
+ aria-describedby="wp-block-jetpack-mailchimp_consent-text"
+ <?php if ( $is_amp_request ) : ?>
+ action-xhr="<?php echo esc_url( $amp_form_action ); ?>"
+ method="post"
+ id="mailchimp_form"
+ target="_top"
+ <?php if ( $is_amp_request ) : ?>
+ on="submit-success:AMP.setState( { mailing_list_status: 'subscribed', mailing_list_email: event.response.email } )"
+ <?php endif; ?>
+ <?php endif; ?>
+ >
<p>
<input
aria-label="<?php echo esc_attr( $values['emailPlaceholder'] ); ?>"
@@ -92,26 +100,79 @@ function jetpack_mailchimp_block_load_assets( $attr ) {
required
title="<?php echo esc_attr( $values['emailPlaceholder'] ); ?>"
type="email"
+ name="email"
/>
</p>
+ <?php foreach ( is_array( $values['interests'] ) ? $values['interests'] : array() as $interest ) : ?>
+ <input
+ name="interests[<?php echo esc_attr( $interest ); ?>]"
+ type="hidden"
+ class="mc-submit-param"
+ value="1"
+ />
+ <?php endforeach; ?>
+ <?php
+ if (
+ ! empty( $values['signupFieldTag'] )
+ && ! empty( $values['signupFieldValue'] )
+ ) :
+ ?>
+ <input
+ name="merge_fields[<?php echo esc_attr( $values['signupFieldTag'] ); ?>]"
+ type="hidden"
+ class="mc-submit-param"
+ value="<?php echo esc_attr( $values['signupFieldValue'] ); ?>"
+ />
+ <?php endif; ?>
<p>
<button type="submit" class="components-button is-button is-primary" style="<?php echo esc_attr( $button_styles ); ?>">
<?php echo wp_kses_post( $values['submitButtonText'] ); ?>
</button>
</p>
- <p id="wp-block-jetpack-mailchimp_consent-text" name="wp-block-jetpack-mailchimp_consent-text">
+ <p id="wp-block-jetpack-mailchimp_consent-text">
<?php echo wp_kses_post( $values['consentText'] ); ?>
</p>
+
+ <?php if ( $is_amp_request ) : ?>
+
+ <div submit-success>
+ <template type="amp-mustache">
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_success wp-block-jetpack-mailchimp__is-amp">
+ <?php echo esc_html( $values['successLabel'] ); ?>
+ </div>
+ </template>
+ </div>
+ <div submit-error>
+ <template type="amp-mustache">
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_error wp-block-jetpack-mailchimp__is-amp">
+ <?php echo esc_html( $values['errorLabel'] ); ?>
+ </div>
+ </template>
+ </div>
+ <div submitting>
+ <template type="amp-mustache">
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_processing wp-block-jetpack-mailchimp__is-amp" role="status">
+ <?php echo esc_html( $values['processingLabel'] ); ?>
+ </div>
+ </template>
+ </div>
+
+ <?php endif; ?>
+
</form>
- <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_processing" role="status">
- <?php echo esc_html( $values['processingLabel'] ); ?>
- </div>
- <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_success" role="status">
- <?php echo esc_html( $values['successLabel'] ); ?>
- </div>
- <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_error" role="alert">
- <?php echo esc_html( $values['errorLabel'] ); ?>
- </div>
+ <?php if ( ! $is_amp_request ) : ?>
+
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_processing" role="status">
+ <?php echo esc_html( $values['processingLabel'] ); ?>
+ </div>
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_success" role="status">
+ <?php echo esc_html( $values['successLabel'] ); ?>
+ </div>
+ <div class="wp-block-jetpack-mailchimp_notification wp-block-jetpack-mailchimp_error" role="alert">
+ <?php echo esc_html( $values['errorLabel'] ); ?>
+ </div>
+
+ <?php endif; ?>
</div>
</div>
<?php