diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 84062bd2..d6fd552f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -27,7 +27,7 @@ jobs: matrix: core: - {name: 'WP latest', version: 'latest'} - - {name: 'WP minimum', version: 'WordPress/WordPress#6.4'} + - {name: 'WP minimum', version: 'WordPress/WordPress#6.6'} - {name: 'WP trunk', version: 'WordPress/WordPress#master'} steps: diff --git a/assets/css/admin.css b/assets/css/admin.css index 9014abd5..2ca927a4 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1449,6 +1449,7 @@ input[type=radio].mailchimp-sf-radio { input[type=radio].mailchimp-sf-radio:checked { border: 2px solid var(--mailchimp-color-link); + background-color: #fff; } input[type=radio].mailchimp-sf-radio:checked:before { diff --git a/includes/admin/admin-notices.php b/includes/admin/admin-notices.php index 16dd25b3..6c8ff261 100644 --- a/includes/admin/admin-notices.php +++ b/includes/admin/admin-notices.php @@ -9,73 +9,28 @@ /** * Display success admin notice. - * - * NOTE: WordPress localization i18n functionality should be done - * on string literals outside of this function in order to work - * correctly. - * - * For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/ + * This function is now a wrapper around the Mailchimp_Admin_Notices class, will be deprecated in future versions. Use that class instead. * * @since 1.7.0 + * @since x.x.x - Moved notice rendering to class-mailchimp-admin-notices.php + * * @param string $msg The message to display. * @return void */ function admin_notice_success( string $msg ) { - ?> -
-

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

-
- add( $msg, 'success' ); } /** * Display error admin notice. - * - * NOTE: WordPress localization i18n functionality should be done - * on string literals outside of this function in order to work - * correctly. - * - * For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/ + * This function is now a wrapper around the Mailchimp_Admin_Notices class, will be deprecated in future versions. Use that class instead. * * @since 1.7.0 + * @since x.x.x - Moved notice rendering to class-mailchimp-admin-notices.php + * * @param string $msg The message to display. * @return void */ function admin_notice_error( string $msg ) { - ?> -
-

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

-
- add( $msg, 'error' ); } diff --git a/includes/admin/class-mailchimp-admin-notices.php b/includes/admin/class-mailchimp-admin-notices.php new file mode 100644 index 00000000..5d8d4df2 --- /dev/null +++ b/includes/admin/class-mailchimp-admin-notices.php @@ -0,0 +1,129 @@ + + */ + private $notices = array(); + + /** + * Get the singleton instance. + * + * @return Mailchimp_Admin_Notices + */ + public static function instance(): Mailchimp_Admin_Notices { + if ( null === self::$instance ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Register the admin_notices hook. + * + * @return void + */ + public function init() { + add_action( 'admin_notices', array( $this, 'render' ) ); + } + + /** + * Queue an admin notice. + * + * @param string $message Notice message (already escaped/translated by caller). + * @param string $type Notice type: success or error. + * @return void + */ + public function add( string $message, string $type ) { + if ( ! is_admin() ) { + return; + } + + if ( did_action( 'admin_notices' ) ) { + $this->print_notice( $message, $type ); + return; + } + + $this->notices[] = array( + 'message' => $message, + 'type' => $type, + ); + } + + /** + * Render all queued notices. + * + * @return void + */ + public function render() { + foreach ( $this->notices as $notice ) { + $this->print_notice( $notice['message'], $notice['type'] ); + } + + $this->notices = array(); + } + + /** + * Print a single admin notice. + * + * @param string $message Notice message. + * @param string $type Notice type: success or error. + * @return void + */ + private function print_notice( string $message, string $type ) { + $classes = array( 'notice', 'notice-' . sanitize_html_class( $type ) ); + + if ( 'success' === $type ) { + $classes[] = 'is-dismissible'; + } + + $allowed_html = array( + 'a' => array( + 'href' => array(), + 'title' => array(), + 'target' => array(), + ), + 'strong' => array(), + 'em' => array(), + 'br' => array(), + ); + + ?> +
+

+ +

+
+ init(); + $user_sync = new Mailchimp_User_Sync(); $user_sync->init(); } diff --git a/mailchimp.php b/mailchimp.php index caf1cd26..7e539a12 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -5,7 +5,7 @@ * Description: Add a Mailchimp signup form block, widget or shortcode to your WordPress site. * Text Domain: mailchimp * Version: 2.0.1 - * Requires at least: 6.4 + * Requires at least: 6.6 * Requires PHP: 7.0 * PHP tested up to: 8.3 * Author: Mailchimp @@ -96,6 +96,7 @@ function () { // Init Admin functions. require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-user-sync-backgroud-process.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-mailchimp-user-sync.php'; +require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-mailchimp-admin-notices.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-admin.php'; $admin = new Mailchimp_Admin(); $admin->init(); diff --git a/phpcs-compat.xml b/phpcs-compat.xml index 3dbb2557..60a16e5c 100644 --- a/phpcs-compat.xml +++ b/phpcs-compat.xml @@ -12,6 +12,6 @@ */node_modules/* */vendor/* - + diff --git a/phpcs.xml b/phpcs.xml index 555ec4b2..ea8ca060 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -6,7 +6,7 @@ */tests/* - + diff --git a/readme.txt b/readme.txt index 91703902..0838902f 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Mailchimp List Subscribe Form === Contributors: Mailchimp Tags: mailchimp, email, newsletter, signup, marketing -Tested up to: 6.9 +Tested up to: 7.0 Stable tag: 2.0.1 License: GPL-2.0-or-later License URI: https://spdx.org/licenses/GPL-2.0-or-later.html diff --git a/tests/cypress/support/index.js b/tests/cypress/support/index.js index 76d9fdaf..3edb7ce6 100644 --- a/tests/cypress/support/index.js +++ b/tests/cypress/support/index.js @@ -16,6 +16,18 @@ import '@10up/cypress-wp-utils'; import './commands'; +Cypress.on('uncaught:exception', (err, runnable) => { + /* + * Noticed this "Transition was skipped" error on WP 7.0 + */ + if (err.message.includes('Transition was skipped')) { + // returning false here prevents Cypress from failing the test + return false; + } + + return runnable; +}); + // TODO: Initialize tests from a blank state // TODO: Wipe WP data related to a users options // TODO: Delete all contacts in a users Mailchimp account