Skip to content

Commit

Permalink
Janitorial: use wp_admin_notice function introduced in WP 6.4 (#37051)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jeherve authored Apr 25, 2024
1 parent bd10131 commit 993a91b
Show file tree
Hide file tree
Showing 51 changed files with 628 additions and 427 deletions.
10 changes: 7 additions & 3 deletions jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* if they tried to install it as one.
*/
function jetpack_monorepo_is_not_a_plugin() {
echo '<div class="notice notice-error"><p>';
printf(
$message = sprintf(
wp_kses(
/* translators: Link to Jetpack installation instructions. */
__( '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' ),
Expand All @@ -44,7 +43,12 @@ function jetpack_monorepo_is_not_a_plugin() {
),
esc_url( 'https://github.com/Automattic/jetpack#jetpack-monorepo' )
);
echo "</p></div>\n";
wp_admin_notice(
$message,
array(
'type' => 'error',
)
);
}

add_action( 'admin_notices', 'jetpack_monorepo_is_not_a_plugin' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
22 changes: 15 additions & 7 deletions projects/packages/connection/docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ function my_function( $errors ) {
// do stuff with the errors array

// echo the error notice
?>
<div class="notice notice-error is-dismissible jetpack-message jp-connect" style="display:block !important;">
<p><?php _e( 'my message', 'my_plugin' ); ?></p>
<a href="#" class="my-cta"><?php _e( 'Fix it!', 'my_plugin' ); ?></a>
</div>
<?php

$message = sprintf(
'<p>%s</p><a href="#" class="my-cta">%s</a>',
esc_html__( 'my message', 'my_plugin' ),
esc_html__( 'Fix it!', 'my_plugin' )
);
wp_admin_notice(
$message,
array(
'type' => 'error',
'dismissible' => true,
'additional_classes' => array( 'jetpack-message', 'jp-connect' ),
'paragraph_wrap' => false,
'attributes' => array( 'style' => 'display:block !important;' ),
)
);
}

```
Expand Down
14 changes: 9 additions & 5 deletions projects/packages/connection/src/class-error-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,15 @@ public function generic_admin_notice_error() {
return;
}

?>
<div class="notice notice-error is-dismissible jetpack-message jp-connect" style="display:block !important;">
<p><?php echo esc_html( $message ); ?></p>
</div>
<?php
wp_admin_notice(
esc_html( $message ),
array(
'type' => 'error',
'dismissible' => true,
'additional_classes' => array( 'jetpack-message', 'jp-connect' ),
'attributes' => array( 'style' => 'display:block !important;' ),
)
);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/forms/changelog/update-use-wp-admin-notice
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
17 changes: 15 additions & 2 deletions projects/packages/forms/src/contact-form/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1518,10 +1518,23 @@ public function grunion_delete_spam_feedbacks() {
* Show an admin notice if the "Empty Spam" or "Check Spam" process was unable to complete, probably due to a permissions error.
*/
public function grunion_feedback_admin_notice() {
$message = '';

if ( isset( $_GET['jetpack_empty_feedback_spam_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
echo '<div class="notice notice-error"><p>' . esc_html( __( 'An error occurred while trying to empty the Feedback spam folder.', 'jetpack-forms' ) ) . '</p></div>';
$message = esc_html__( 'An error occurred while trying to empty the Feedback spam folder.', 'jetpack-forms' );
} elseif ( isset( $_GET['jetpack_check_feedback_spam_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
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>';
$message = esc_html__( 'An error occurred while trying to check for spam among the feedback you received.', 'jetpack-forms' );
}

if ( empty( $message ) ) {
return;
}

wp_admin_notice(
$message,
array(
'type' => 'error',
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ function import_admin_banner() {
$import_url = esc_url( "https://wordpress.com/setup/import-focused/import?siteSlug={$site_slug}&ref=wp-admin" );

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

echo wp_kses_post( $banner_content );
wp_admin_notice(
wp_kses_post( $banner_content ),
array(
'paragraph_wrap' => false,
'additional_classes' => array( 'wpcom-import-banner' ),
)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,27 @@
add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
?>
</p>
</div>
<?php
$message = sprintf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
wp_admin_notice(
$message,
array(
'type' => 'error',
'dismissible' => true,
)
);
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
4 changes: 4 additions & 0 deletions projects/plugins/backup/changelog/update-use-wp-admin-notice
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
59 changes: 28 additions & 31 deletions projects/plugins/backup/jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ function jetpack_backup_requirements_check() {
add_action(
'admin_notices',
function () use ( $jetpack_backup_meets_requirements ) {
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
echo esc_html( $jetpack_backup_meets_requirements->get_error_message() );
?>
</p>
</div>
<?php
wp_admin_notice(
esc_html( $jetpack_backup_meets_requirements->get_error_message() ),
array(
'type' => 'error',
'dismissible' => true,
)
);
}
);

Expand Down Expand Up @@ -120,28 +118,27 @@ function () {
if ( get_current_screen()->id !== 'plugins' ) {
return;
}
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
?>
</p>
</div>
<?php
$message = sprintf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
wp_admin_notice(
$message,
array(
'type' => 'error',
'dismissible' => true,
)
);
}
);

Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/beta/changelog/update-use-wp-admin-notice
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
41 changes: 20 additions & 21 deletions projects/plugins/beta/jetpack-beta.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,27 @@ function jetpack_beta_admin_missing_autoloader() {
if ( get_current_screen()->id !== 'plugins' ) {
return;
}
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
$message = sprintf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md'
);
?>
</p>
</div>
<?php
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md'
);
wp_admin_notice(
$message,
array(
'type' => 'error',
'dismissible' => true,
)
);
}

add_action( 'admin_notices', 'jetpack_beta_admin_missing_autoloader' );
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/boost/changelog/update-use-wp-admin-notice
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: use wp_admin_notice function introduced in WP 6.4 to display notices.
41 changes: 20 additions & 21 deletions projects/plugins/boost/jetpack-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,27 @@ function jetpack_boost_admin_missing_files() {
if ( get_current_screen()->id !== 'plugins' ) {
return;
}
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
$message = sprintf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( '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' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
?>
</p>
</div>
<?php
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
wp_admin_notice(
$message,
array(
'type' => 'error',
'dismissible' => true,
)
);
}

add_action( 'admin_notices', __NAMESPACE__ . '\\jetpack_boost_admin_missing_files' );
Expand Down
Loading

0 comments on commit 993a91b

Please sign in to comment.