Skip to content

Commit 7a393f8

Browse files
authored
Merge pull request #205 from mailchimp/wp_7.0
Bump WordPress Tested up to version 7.0
2 parents a7045cb + bd3a89a commit 7a393f8

10 files changed

Lines changed: 158 additions & 58 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
matrix:
2828
core:
2929
- {name: 'WP latest', version: 'latest'}
30-
- {name: 'WP minimum', version: 'WordPress/WordPress#6.4'}
30+
- {name: 'WP minimum', version: 'WordPress/WordPress#6.6'}
3131
- {name: 'WP trunk', version: 'WordPress/WordPress#master'}
3232

3333
steps:

assets/css/admin.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ input[type=radio].mailchimp-sf-radio {
14491449

14501450
input[type=radio].mailchimp-sf-radio:checked {
14511451
border: 2px solid var(--mailchimp-color-link);
1452+
background-color: #fff;
14521453
}
14531454

14541455
input[type=radio].mailchimp-sf-radio:checked:before {

includes/admin/admin-notices.php

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,28 @@
99

1010
/**
1111
* Display success admin notice.
12-
*
13-
* NOTE: WordPress localization i18n functionality should be done
14-
* on string literals outside of this function in order to work
15-
* correctly.
16-
*
17-
* For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/
12+
* This function is now a wrapper around the Mailchimp_Admin_Notices class, will be deprecated in future versions. Use that class instead.
1813
*
1914
* @since 1.7.0
15+
* @since x.x.x - Moved notice rendering to class-mailchimp-admin-notices.php
16+
*
2017
* @param string $msg The message to display.
2118
* @return void
2219
*/
2320
function admin_notice_success( string $msg ) {
24-
?>
25-
<div class="notice notice-success is-dismissible">
26-
<p>
27-
<?php
28-
echo wp_kses(
29-
$msg,
30-
array(
31-
'a' => array(
32-
'href' => array(),
33-
'title' => array(),
34-
'target' => array(),
35-
),
36-
'strong' => array(),
37-
'em' => array(),
38-
'br' => array(),
39-
)
40-
);
41-
?>
42-
</p>
43-
</div>
44-
<?php
21+
\Mailchimp_Admin_Notices::instance()->add( $msg, 'success' );
4522
}
4623

4724
/**
4825
* Display error admin notice.
49-
*
50-
* NOTE: WordPress localization i18n functionality should be done
51-
* on string literals outside of this function in order to work
52-
* correctly.
53-
*
54-
* For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/
26+
* This function is now a wrapper around the Mailchimp_Admin_Notices class, will be deprecated in future versions. Use that class instead.
5527
*
5628
* @since 1.7.0
29+
* @since x.x.x - Moved notice rendering to class-mailchimp-admin-notices.php
30+
*
5731
* @param string $msg The message to display.
5832
* @return void
5933
*/
6034
function admin_notice_error( string $msg ) {
61-
?>
62-
<div class="notice notice-error">
63-
<p>
64-
<?php
65-
echo wp_kses(
66-
$msg,
67-
array(
68-
'a' => array(
69-
'href' => array(),
70-
'title' => array(),
71-
'target' => array(),
72-
),
73-
'strong' => array(),
74-
'em' => array(),
75-
)
76-
);
77-
?>
78-
</p>
79-
</div>
80-
<?php
35+
\Mailchimp_Admin_Notices::instance()->add( $msg, 'error' );
8136
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Mailchimp admin notices class.
4+
*
5+
* Registers notices and renders them on the admin_notices hook in the same request.
6+
*
7+
* @since x.x.x
8+
*
9+
* @package Mailchimp
10+
*/
11+
12+
// Exit if accessed directly.
13+
if ( ! defined( 'ABSPATH' ) ) {
14+
exit;
15+
}
16+
17+
/**
18+
* Class Mailchimp_Admin_Notices
19+
*
20+
* @since x.x.x
21+
*/
22+
class Mailchimp_Admin_Notices {
23+
24+
/**
25+
* Singleton instance.
26+
*
27+
* @var Mailchimp_Admin_Notices|null
28+
*/
29+
private static $instance = null;
30+
31+
/**
32+
* Queued notices for the current request.
33+
*
34+
* @var array<int, array{message: string, type: string}>
35+
*/
36+
private $notices = array();
37+
38+
/**
39+
* Get the singleton instance.
40+
*
41+
* @return Mailchimp_Admin_Notices
42+
*/
43+
public static function instance(): Mailchimp_Admin_Notices {
44+
if ( null === self::$instance ) {
45+
self::$instance = new self();
46+
}
47+
48+
return self::$instance;
49+
}
50+
51+
/**
52+
* Register the admin_notices hook.
53+
*
54+
* @return void
55+
*/
56+
public function init() {
57+
add_action( 'admin_notices', array( $this, 'render' ) );
58+
}
59+
60+
/**
61+
* Queue an admin notice.
62+
*
63+
* @param string $message Notice message (already escaped/translated by caller).
64+
* @param string $type Notice type: success or error.
65+
* @return void
66+
*/
67+
public function add( string $message, string $type ) {
68+
if ( ! is_admin() ) {
69+
return;
70+
}
71+
72+
if ( did_action( 'admin_notices' ) ) {
73+
$this->print_notice( $message, $type );
74+
return;
75+
}
76+
77+
$this->notices[] = array(
78+
'message' => $message,
79+
'type' => $type,
80+
);
81+
}
82+
83+
/**
84+
* Render all queued notices.
85+
*
86+
* @return void
87+
*/
88+
public function render() {
89+
foreach ( $this->notices as $notice ) {
90+
$this->print_notice( $notice['message'], $notice['type'] );
91+
}
92+
93+
$this->notices = array();
94+
}
95+
96+
/**
97+
* Print a single admin notice.
98+
*
99+
* @param string $message Notice message.
100+
* @param string $type Notice type: success or error.
101+
* @return void
102+
*/
103+
private function print_notice( string $message, string $type ) {
104+
$classes = array( 'notice', 'notice-' . sanitize_html_class( $type ) );
105+
106+
if ( 'success' === $type ) {
107+
$classes[] = 'is-dismissible';
108+
}
109+
110+
$allowed_html = array(
111+
'a' => array(
112+
'href' => array(),
113+
'title' => array(),
114+
'target' => array(),
115+
),
116+
'strong' => array(),
117+
'em' => array(),
118+
'br' => array(),
119+
);
120+
121+
?>
122+
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
123+
<p>
124+
<?php echo wp_kses( $message, $allowed_html ); ?>
125+
</p>
126+
</div>
127+
<?php
128+
}
129+
}

includes/class-mailchimp-admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function init() {
4848
add_action( 'admin_menu', array( $this, 'add_admin_menu_pages' ) );
4949
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
5050

51+
Mailchimp_Admin_Notices::instance()->init();
52+
5153
$user_sync = new Mailchimp_User_Sync();
5254
$user_sync->init();
5355
}

mailchimp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Add a Mailchimp signup form block, widget or shortcode to your WordPress site.
66
* Text Domain: mailchimp
77
* Version: 2.0.1
8-
* Requires at least: 6.4
8+
* Requires at least: 6.6
99
* Requires PHP: 7.0
1010
* PHP tested up to: 8.3
1111
* Author: Mailchimp
@@ -96,6 +96,7 @@ function () {
9696
// Init Admin functions.
9797
require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-user-sync-backgroud-process.php';
9898
require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-mailchimp-user-sync.php';
99+
require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-mailchimp-admin-notices.php';
99100
require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-admin.php';
100101
$admin = new Mailchimp_Admin();
101102
$admin->init();

phpcs-compat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<exclude-pattern>*/node_modules/*</exclude-pattern>
1313
<exclude-pattern>*/vendor/*</exclude-pattern>
1414

15-
<config name="minimum_supported_wp_version" value="6.4"/>
15+
<config name="minimum_supported_wp_version" value="6.6"/>
1616
<config name="testVersion" value="7.0-"/>
1717
</ruleset>

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
<config name="minimum_supported_wp_version" value="6.4"/>
9+
<config name="minimum_supported_wp_version" value="6.6"/>
1010
<config name="testVersion" value="7.0-"/>
1111

1212
<!-- Exclude the PHPCompatibilityWP ruleset -->

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Mailchimp List Subscribe Form ===
22
Contributors: Mailchimp
33
Tags: mailchimp, email, newsletter, signup, marketing
4-
Tested up to: 6.9
4+
Tested up to: 7.0
55
Stable tag: 2.0.1
66
License: GPL-2.0-or-later
77
License URI: https://spdx.org/licenses/GPL-2.0-or-later.html

tests/cypress/support/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
import '@10up/cypress-wp-utils';
1717
import './commands';
1818

19+
Cypress.on('uncaught:exception', (err, runnable) => {
20+
/*
21+
* Noticed this "Transition was skipped" error on WP 7.0
22+
*/
23+
if (err.message.includes('Transition was skipped')) {
24+
// returning false here prevents Cypress from failing the test
25+
return false;
26+
}
27+
28+
return runnable;
29+
});
30+
1931
// TODO: Initialize tests from a blank state
2032
// TODO: Wipe WP data related to a users options
2133
// TODO: Delete all contacts in a users Mailchimp account

0 commit comments

Comments
 (0)