diff --git a/composer.json b/composer.json index 9965490..0da82f6 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,10 @@ "Mailchimp\\WordPress\\": "src/" }, "classmap": [ - "includes" + "includes/" + ], + "files": [ + "includes/admin/admin-notices.php" ] }, "config": { diff --git a/includes/admin/admin-notices.php b/includes/admin/admin-notices.php new file mode 100644 index 0000000..6307c52 --- /dev/null +++ b/includes/admin/admin-notices.php @@ -0,0 +1,80 @@ + +
+

+ array( + 'href' => array(), + 'title' => array(), + 'target' => array(), + ), + 'strong' => array(), + 'em' => array(), + ) + ); + ?> +

+
+ +
+

+ array( + 'href' => array(), + 'title' => array(), + 'target' => array(), + ), + 'strong' => array(), + 'em' => array(), + ) + ); + ?> +

+
+ ' . esc_html__( 'Fancy Javascript submission turned On!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Fancy Javascript submission turned On!', 'mailchimp' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_use_javascript' ) !== 'off' ) { update_option( 'mc_use_javascript', 'off' ); - $msg = '

' . esc_html__( 'Fancy Javascript submission turned Off!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Fancy Javascript submission turned Off!', 'mailchimp' ); + admin_notice_success( $msg ); } if ( isset( $_POST['mc_use_datepicker'] ) ) { update_option( 'mc_use_datepicker', 'on' ); - $msg = '

' . esc_html__( 'Datepicker turned On!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Datepicker turned On!', 'mailchimp' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_use_datepicker' ) !== 'off' ) { update_option( 'mc_use_datepicker', 'off' ); - $msg = '

' . esc_html__( 'Datepicker turned Off!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Datepicker turned Off!', 'mailchimp' ); + admin_notice_success( $msg ); } /*Enable double optin toggle*/ if ( isset( $_POST['mc_double_optin'] ) ) { update_option( 'mc_double_optin', true ); - $msg = '

' . esc_html__( 'Double opt-in turned On!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Double opt-in turned On!', 'mailchimp' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_double_optin' ) !== false ) { update_option( 'mc_double_optin', false ); - $msg = '

' . esc_html__( 'Double opt-in turned Off!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Double opt-in turned Off!', 'mailchimp' ); + admin_notice_success( $msg ); } /* NUKE the CSS! */ if ( isset( $_POST['mc_nuke_all_styles'] ) ) { update_option( 'mc_nuke_all_styles', true ); - $msg = '

' . esc_html__( 'Mailchimp CSS turned Off!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Mailchimp CSS turned Off!', 'mailchimp' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_nuke_all_styles' ) !== false ) { update_option( 'mc_nuke_all_styles', false ); - $msg = '

' . esc_html__( 'Mailchimp CSS turned On!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Mailchimp CSS turned On!', 'mailchimp' ); + admin_notice_success( $msg ); } /* Update existing */ if ( isset( $_POST['mc_update_existing'] ) ) { update_option( 'mc_update_existing', true ); - $msg = '

' . esc_html__( 'Update existing subscribers turned On!' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Update existing subscribers turned On!' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_update_existing' ) !== false ) { update_option( 'mc_update_existing', false ); - $msg = '

' . esc_html__( 'Update existing subscribers turned Off!' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Update existing subscribers turned Off!' ); + admin_notice_success( $msg ); } if ( isset( $_POST['mc_use_unsub_link'] ) ) { update_option( 'mc_use_unsub_link', 'on' ); - $msg = '

' . esc_html__( 'Unsubscribe link turned On!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Unsubscribe link turned On!', 'mailchimp' ); + admin_notice_success( $msg ); } elseif ( get_option( 'mc_use_unsub_link' ) !== 'off' ) { update_option( 'mc_use_unsub_link', 'off' ); - $msg = '

' . esc_html__( 'Unsubscribe link turned Off!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Unsubscribe link turned Off!', 'mailchimp' ); + admin_notice_success( $msg ); } $content = isset( $_POST['mc_header_content'] ) ? wp_kses_post( wp_unslash( $_POST['mc_header_content'] ) ) : ''; @@ -577,8 +584,8 @@ function mailchimp_sf_save_general_form_settings() { } } - $msg = '

' . esc_html__( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' ); + admin_notice_success( $msg ); } /** @@ -590,8 +597,8 @@ function mailchimp_sf_change_list_if_necessary() { } if ( empty( $_POST['mc_list_id'] ) ) { - $msg = '

' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '

'; - mailchimp_sf_global_msg( $msg ); + $msg = esc_html__( 'Please choose a valid list', 'mailchimp' ); + admin_notice_error( $msg ); return; } @@ -649,16 +656,15 @@ function mailchimp_sf_change_list_if_necessary() { $igs_text .= sprintf( esc_html__( 'and %s Sets of Interest Groups', 'mailchimp' ), count( $igs ) ); } - $msg = '

' . - sprintf( - /* translators: %s: count (number) */ - __( 'Success! Loaded and saved the info for %d Merge Variables', 'mailchimp' ) . $igs_text, - count( $mv ) - ) . ' ' . - esc_html__( 'from your list' ) . ' "' . $list_name . '"

' . - esc_html__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' ) . '

'; - - mailchimp_sf_global_msg( $msg ); + $msg = sprintf( + /* translators: %s: count (number) */ + __( 'Success! Loaded and saved the info for %d Merge Variables', 'mailchimp' ) . $igs_text, + count( $mv ) + ) . ' ' . + esc_html__( 'from your list' ) . ' "' . $list_name . '"

' . + esc_html__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' ); + + admin_notice_success( $msg ); } } } @@ -832,7 +838,7 @@ function mailchimp_sf_signup_submit() { // Catch errors and fail early. if ( is_wp_error( $merge ) ) { $msg = '' . $merge->get_error_message() . ''; - mailchimp_sf_global_msg( $msg ); + mailchimp_sf_frontend_msg( $msg ); return false; } @@ -873,7 +879,7 @@ function mailchimp_sf_signup_submit() { ] ) ); - mailchimp_sf_global_msg( $error ); + mailchimp_sf_frontend_msg( $error ); return false; } @@ -885,7 +891,7 @@ function mailchimp_sf_signup_submit() { if ( ! get_option( 'mc_update_existing' ) && ! $is_new_subscriber ) { $msg = esc_html__( 'This email address has already been subscribed to this list.', 'mailchimp' ); $error = new WP_Error( 'mailchimp-update-existing', $msg ); - mailchimp_sf_global_msg( '' . $msg . '' ); + mailchimp_sf_frontend_msg( '' . $msg . '' ); return false; } @@ -898,7 +904,7 @@ function mailchimp_sf_signup_submit() { // If we have errors, then show them if ( is_wp_error( $retval ) ) { $msg = '' . $retval->get_error_message() . ''; - mailchimp_sf_global_msg( $msg ); + mailchimp_sf_frontend_msg( $msg ); return false; } @@ -910,8 +916,8 @@ function mailchimp_sf_signup_submit() { $msg = "{$esc}"; } - // Set our global message - mailchimp_sf_global_msg( $msg ); + // Set our front end success message + mailchimp_sf_frontend_msg( $msg ); return true; } diff --git a/mailchimp_widget.php b/mailchimp_widget.php index d2d129c..a5266e4 100644 --- a/mailchimp_widget.php +++ b/mailchimp_widget.php @@ -184,7 +184,7 @@ function mailchimp_sf_signup_form( $args = array() ) {
- +
{ cy.get('#mailchimp-sf-create-activate-account').should('be.visible'); }); - it("Admin shouldn't able to submit create account form with invalid data", () => { + it("Admin shouldn't be able to submit create account form with invalid data", () => { cy.visit('/wp-admin/admin.php?page=mailchimp_sf_create_account'); // Submit form without filling any data. diff --git a/tests/cypress/e2e/settings.test.js b/tests/cypress/e2e/settings.test.js index 0466b10..8399234 100644 --- a/tests/cypress/e2e/settings.test.js +++ b/tests/cypress/e2e/settings.test.js @@ -13,7 +13,7 @@ describe('Admin can update plugin settings', () => { cy.get('.mc-h2').contains('Your Lists'); cy.get('#mc_list_id').select('10up'); cy.get('input[value="Update List"]').click(); - cy.get('#mc-message .success_msg b').contains('Success!'); + cy.get('#mailchimp-sf-settings-page .notice.notice-success p').contains('Success!'); }); it('Admin can create a Signup form using the shortcode', () => { diff --git a/views/setup_page.php b/views/setup_page.php index b2e64d4..c146261 100644 --- a/views/setup_page.php +++ b/views/setup_page.php @@ -5,6 +5,8 @@ * @package Mailchimp */ +use function Mailchimp\WordPress\Includes\Admin\admin_notice_error; + $user = get_option( 'mc_user' ); // If we have an API Key, see if we need to change the lists and its options @@ -14,14 +16,6 @@ ?>

- -
-

:

@@ -53,29 +47,19 @@ // we *could* support paging, but few users have that many lists (and shouldn't) $lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) ); if ( is_wp_error( $lists ) ) { - ?> -
- get_error_message() ) - ); - ?> -
- get_error_message() ) + ); + admin_notice_error( $msg ); } elseif ( isset( $lists['lists'] ) && count( $lists['lists'] ) === 0 ) { - ?> -
- Mailchimp" - ); - ?> -
- Mailchimp" + ); + admin_notice_error( $msg ); } else { $lists = $lists['lists']; $option = get_option( 'mc_list_id' );