Skip to content

Commit 993a91b

Browse files
authored
Janitorial: use wp_admin_notice function introduced in WP 6.4 (#37051)
* Janitorial: use wp_admin_notice function introduced in WP 6.4 Epic: #33615 * Handle possibility of no message * Switch from string to array * Add missing escaping * Fix indenting * Add missing escaping
1 parent bd10131 commit 993a91b

File tree

51 files changed

+628
-427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+628
-427
lines changed

jetpack.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
* if they tried to install it as one.
3434
*/
3535
function jetpack_monorepo_is_not_a_plugin() {
36-
echo '<div class="notice notice-error"><p>';
37-
printf(
36+
$message = sprintf(
3837
wp_kses(
3938
/* translators: Link to Jetpack installation instructions. */
4039
__( 'The Jetpack Monorepo is not a plugin, and should not be installed as one. See <a href="%s">the Jetpack Monorepo documentation</a> for instructions on correctly installing Jetpack.', 'jetpack' ),
@@ -44,7 +43,12 @@ function jetpack_monorepo_is_not_a_plugin() {
4443
),
4544
esc_url( 'https://github.com/Automattic/jetpack#jetpack-monorepo' )
4645
);
47-
echo "</p></div>\n";
46+
wp_admin_notice(
47+
$message,
48+
array(
49+
'type' => 'error',
50+
)
51+
);
4852
}
4953

5054
add_action( 'admin_notices', 'jetpack_monorepo_is_not_a_plugin' );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/packages/connection/docs/error-handling.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ function my_function( $errors ) {
6060
// do stuff with the errors array
6161

6262
// echo the error notice
63-
?>
64-
<div class="notice notice-error is-dismissible jetpack-message jp-connect" style="display:block !important;">
65-
<p><?php _e( 'my message', 'my_plugin' ); ?></p>
66-
<a href="#" class="my-cta"><?php _e( 'Fix it!', 'my_plugin' ); ?></a>
67-
</div>
68-
<?php
69-
63+
$message = sprintf(
64+
'<p>%s</p><a href="#" class="my-cta">%s</a>',
65+
esc_html__( 'my message', 'my_plugin' ),
66+
esc_html__( 'Fix it!', 'my_plugin' )
67+
);
68+
wp_admin_notice(
69+
$message,
70+
array(
71+
'type' => 'error',
72+
'dismissible' => true,
73+
'additional_classes' => array( 'jetpack-message', 'jp-connect' ),
74+
'paragraph_wrap' => false,
75+
'attributes' => array( 'style' => 'display:block !important;' ),
76+
)
77+
);
7078
}
7179

7280
```

projects/packages/connection/src/class-error-handler.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,15 @@ public function generic_admin_notice_error() {
702702
return;
703703
}
704704

705-
?>
706-
<div class="notice notice-error is-dismissible jetpack-message jp-connect" style="display:block !important;">
707-
<p><?php echo esc_html( $message ); ?></p>
708-
</div>
709-
<?php
705+
wp_admin_notice(
706+
esc_html( $message ),
707+
array(
708+
'type' => 'error',
709+
'dismissible' => true,
710+
'additional_classes' => array( 'jetpack-message', 'jp-connect' ),
711+
'attributes' => array( 'style' => 'display:block !important;' ),
712+
)
713+
);
710714
}
711715

712716
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/packages/forms/src/contact-form/class-admin.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -1518,10 +1518,23 @@ public function grunion_delete_spam_feedbacks() {
15181518
* Show an admin notice if the "Empty Spam" or "Check Spam" process was unable to complete, probably due to a permissions error.
15191519
*/
15201520
public function grunion_feedback_admin_notice() {
1521+
$message = '';
1522+
15211523
if ( isset( $_GET['jetpack_empty_feedback_spam_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1522-
echo '<div class="notice notice-error"><p>' . esc_html( __( 'An error occurred while trying to empty the Feedback spam folder.', 'jetpack-forms' ) ) . '</p></div>';
1524+
$message = esc_html__( 'An error occurred while trying to empty the Feedback spam folder.', 'jetpack-forms' );
15231525
} elseif ( isset( $_GET['jetpack_check_feedback_spam_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1524-
echo '<div class="notice notice-error"><p>' . esc_html( __( 'An error occurred while trying to check for spam among the feedback you received.', 'jetpack-forms' ) ) . '</p></div>';
1526+
$message = esc_html__( 'An error occurred while trying to check for spam among the feedback you received.', 'jetpack-forms' );
1527+
}
1528+
1529+
if ( empty( $message ) ) {
1530+
return;
15251531
}
1532+
1533+
wp_admin_notice(
1534+
$message,
1535+
array(
1536+
'type' => 'error',
1537+
)
1538+
);
15261539
}
15271540
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/packages/jetpack-mu-wpcom/src/features/import-customizations/import-customizations.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ function import_admin_banner() {
3333
$import_url = esc_url( "https://wordpress.com/setup/import-focused/import?siteSlug={$site_slug}&ref=wp-admin" );
3434

3535
$banner_content = sprintf(
36-
'<div class="notice wpcom-import-banner">
37-
<p>%s</p>
38-
<a href="%s" class="button">%s</a>
39-
</div>',
36+
'<p>%s</p><a href="%s" class="button">%s</a>',
4037
esc_html__( 'Use WordPress.com’s guided importer to import posts and comments from Medium, Substack, Squarespace, Wix, and more.', 'jetpack-mu-wpcom' ),
4138
$import_url,
4239
esc_html__( 'Get started', 'jetpack-mu-wpcom' )
4340
);
4441

45-
echo wp_kses_post( $banner_content );
42+
wp_admin_notice(
43+
wp_kses_post( $banner_content ),
44+
array(
45+
'paragraph_wrap' => false,
46+
'additional_classes' => array( 'wpcom-import-banner' ),
47+
)
48+
);
4649
}
4750

4851
/**

projects/plugins/automattic-for-agencies-client/automattic-for-agencies-client.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,27 @@
5858
add_action(
5959
'admin_notices',
6060
function () {
61-
?>
62-
<div class="notice notice-error is-dismissible">
63-
<p>
64-
<?php
65-
printf(
66-
wp_kses(
67-
/* translators: Placeholder is a link to a support document. */
68-
__( 'Your installation of Automattic For Agencies Client is incomplete. If you installed Automattic For Agencies Client from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Automattic For Agencies Client must have Composer dependencies installed and built via the build command.', 'automattic-for-agencies-client' ),
69-
array(
70-
'a' => array(
71-
'href' => array(),
72-
'target' => array(),
73-
'rel' => array(),
74-
),
75-
)
76-
),
77-
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
78-
);
79-
?>
80-
</p>
81-
</div>
82-
<?php
61+
$message = sprintf(
62+
wp_kses(
63+
/* translators: Placeholder is a link to a support document. */
64+
__( 'Your installation of Automattic For Agencies Client is incomplete. If you installed Automattic For Agencies Client from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Automattic For Agencies Client must have Composer dependencies installed and built via the build command.', 'automattic-for-agencies-client' ),
65+
array(
66+
'a' => array(
67+
'href' => array(),
68+
'target' => array(),
69+
'rel' => array(),
70+
),
71+
)
72+
),
73+
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
74+
);
75+
wp_admin_notice(
76+
$message,
77+
array(
78+
'type' => 'error',
79+
'dismissible' => true,
80+
)
81+
);
8382
}
8483
);
8584

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/plugins/backup/jetpack-backup.php

+28-31
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ function jetpack_backup_requirements_check() {
7171
add_action(
7272
'admin_notices',
7373
function () use ( $jetpack_backup_meets_requirements ) {
74-
?>
75-
<div class="notice notice-error is-dismissible">
76-
<p>
77-
<?php
78-
echo esc_html( $jetpack_backup_meets_requirements->get_error_message() );
79-
?>
80-
</p>
81-
</div>
82-
<?php
74+
wp_admin_notice(
75+
esc_html( $jetpack_backup_meets_requirements->get_error_message() ),
76+
array(
77+
'type' => 'error',
78+
'dismissible' => true,
79+
)
80+
);
8381
}
8482
);
8583

@@ -120,28 +118,27 @@ function () {
120118
if ( get_current_screen()->id !== 'plugins' ) {
121119
return;
122120
}
123-
?>
124-
<div class="notice notice-error is-dismissible">
125-
<p>
126-
<?php
127-
printf(
128-
wp_kses(
129-
/* translators: Placeholder is a link to a support document. */
130-
__( 'Your installation of Jetpack VaultPress Backup is incomplete. If you installed Jetpack VaultPress Backup from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack VaultPress Backup must have Composer dependencies installed and built via the build command.', 'jetpack-backup' ),
131-
array(
132-
'a' => array(
133-
'href' => array(),
134-
'target' => array(),
135-
'rel' => array(),
136-
),
137-
)
138-
),
139-
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
140-
);
141-
?>
142-
</p>
143-
</div>
144-
<?php
121+
$message = sprintf(
122+
wp_kses(
123+
/* translators: Placeholder is a link to a support document. */
124+
__( 'Your installation of Jetpack VaultPress Backup is incomplete. If you installed Jetpack VaultPress Backup from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack VaultPress Backup must have Composer dependencies installed and built via the build command.', 'jetpack-backup' ),
125+
array(
126+
'a' => array(
127+
'href' => array(),
128+
'target' => array(),
129+
'rel' => array(),
130+
),
131+
)
132+
),
133+
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
134+
);
135+
wp_admin_notice(
136+
$message,
137+
array(
138+
'type' => 'error',
139+
'dismissible' => true,
140+
)
141+
);
145142
}
146143
);
147144

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/plugins/beta/jetpack-beta.php

+20-21
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,27 @@ function jetpack_beta_admin_missing_autoloader() {
8686
if ( get_current_screen()->id !== 'plugins' ) {
8787
return;
8888
}
89-
?>
90-
<div class="notice notice-error is-dismissible">
91-
<p>
92-
<?php
93-
printf(
94-
wp_kses(
95-
/* translators: Placeholder is a link to a support document. */
96-
__( 'Your installation of Jetpack Beta is incomplete. If you installed Jetpack Beta from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment.', 'jetpack-beta' ),
97-
array(
98-
'a' => array(
99-
'href' => array(),
100-
'target' => array(),
101-
'rel' => array(),
102-
),
103-
)
89+
$message = sprintf(
90+
wp_kses(
91+
/* translators: Placeholder is a link to a support document. */
92+
__( 'Your installation of Jetpack Beta is incomplete. If you installed Jetpack Beta from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment.', 'jetpack-beta' ),
93+
array(
94+
'a' => array(
95+
'href' => array(),
96+
'target' => array(),
97+
'rel' => array(),
10498
),
105-
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md'
106-
);
107-
?>
108-
</p>
109-
</div>
110-
<?php
99+
)
100+
),
101+
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md'
102+
);
103+
wp_admin_notice(
104+
$message,
105+
array(
106+
'type' => 'error',
107+
'dismissible' => true,
108+
)
109+
);
111110
}
112111

113112
add_action( 'admin_notices', 'jetpack_beta_admin_missing_autoloader' );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
General: use wp_admin_notice function introduced in WP 6.4 to display notices.

projects/plugins/boost/jetpack-boost.php

+20-21
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,27 @@ function jetpack_boost_admin_missing_files() {
108108
if ( get_current_screen()->id !== 'plugins' ) {
109109
return;
110110
}
111-
?>
112-
<div class="notice notice-error is-dismissible">
113-
<p>
114-
<?php
115-
printf(
116-
wp_kses(
117-
/* translators: Placeholder is a link to a support document. */
118-
__( 'Your installation of Jetpack Boost is incomplete. If you installed Jetpack Boost from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack Boost must have Composer dependencies installed and built via the build command.', 'jetpack-boost' ),
119-
array(
120-
'a' => array(
121-
'href' => array(),
122-
'target' => array(),
123-
'rel' => array(),
124-
),
125-
)
111+
$message = sprintf(
112+
wp_kses(
113+
/* translators: Placeholder is a link to a support document. */
114+
__( 'Your installation of Jetpack Boost is incomplete. If you installed Jetpack Boost from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack Boost must have Composer dependencies installed and built via the build command.', 'jetpack-boost' ),
115+
array(
116+
'a' => array(
117+
'href' => array(),
118+
'target' => array(),
119+
'rel' => array(),
126120
),
127-
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
128-
);
129-
?>
130-
</p>
131-
</div>
132-
<?php
121+
)
122+
),
123+
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
124+
);
125+
wp_admin_notice(
126+
$message,
127+
array(
128+
'type' => 'error',
129+
'dismissible' => true,
130+
)
131+
);
133132
}
134133

135134
add_action( 'admin_notices', __NAMESPACE__ . '\\jetpack_boost_admin_missing_files' );

0 commit comments

Comments
 (0)