Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
61 changes: 8 additions & 53 deletions includes/admin/admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Comment thread
iamdharmesh marked this conversation as resolved.
* @param string $msg The message to display.
* @return void
*/
function admin_notice_success( string $msg ) {
?>
<div class="notice notice-success is-dismissible">
<p>
<?php
echo wp_kses(
$msg,
array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'strong' => array(),
'em' => array(),
'br' => array(),
)
);
?>
</p>
</div>
<?php
\Mailchimp_Admin_Notices::instance()->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 ) {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses(
$msg,
array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'strong' => array(),
'em' => array(),
)
);
?>
</p>
</div>
<?php
\Mailchimp_Admin_Notices::instance()->add( $msg, 'error' );
}
129 changes: 129 additions & 0 deletions includes/admin/class-mailchimp-admin-notices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
/**
* Mailchimp admin notices class.
*
* Registers notices and renders them on the admin_notices hook in the same request.
*
* @since x.x.x
*
* @package Mailchimp
Comment thread
iamdharmesh marked this conversation as resolved.
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class Mailchimp_Admin_Notices
*
* @since x.x.x
*/
class Mailchimp_Admin_Notices {

/**
* Singleton instance.
*
* @var Mailchimp_Admin_Notices|null
*/
private static $instance = null;

/**
* Queued notices for the current request.
*
* @var array<int, array{message: string, type: string}>
*/
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(),
);

?>
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<p>
<?php echo wp_kses( $message, $allowed_html ); ?>
</p>
</div>
<?php
}
}
2 changes: 2 additions & 0 deletions includes/class-mailchimp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function init() {
add_action( 'admin_menu', array( $this, 'add_admin_menu_pages' ) );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );

Mailchimp_Admin_Notices::instance()->init();

$user_sync = new Mailchimp_User_Sync();
$user_sync->init();
}
Expand Down
3 changes: 2 additions & 1 deletion mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Comment thread
iamdharmesh marked this conversation as resolved.
$admin->init();
Expand Down
2 changes: 1 addition & 1 deletion phpcs-compat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<config name="minimum_supported_wp_version" value="6.4"/>
<config name="minimum_supported_wp_version" value="6.6"/>
<config name="testVersion" value="7.0-"/>
</ruleset>
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<exclude-pattern>*/tests/*</exclude-pattern>

<config name="minimum_supported_wp_version" value="6.4"/>
<config name="minimum_supported_wp_version" value="6.6"/>
<config name="testVersion" value="7.0-"/>

<!-- Exclude the PHPCompatibilityWP ruleset -->
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading