feat: add admin notices

This commit is contained in:
Keith Solomon
2026-05-07 06:22:50 -05:00
parent 27919ff11f
commit 9f945955d1
3 changed files with 138 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
<?php
/**
* Builds admin notices from redirect query args.
*
* @package WPContentSync
*/
namespace WPContentSync\Admin;
final class AdminNoticeRepository {
/**
* @return array<int, AdminNotice>
*/
public function current(): array {
$notices = array();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_imported'] ) ) {
$notices[] = new AdminNotice( 'success', __( 'The package JSON file was imported successfully.', 'wp-content-sync' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_import_error'] ) ) {
$notices[] = new AdminNotice( 'error', $this->queryValue( 'wpcs_import_error' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_settings_saved'] ) ) {
$notices[] = new AdminNotice( 'success', __( 'Settings saved.', 'wp-content-sync' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_connection_ok'] ) ) {
$notices[] = new AdminNotice( 'success', __( 'REST connection succeeded.', 'wp-content-sync' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_logs_cleared'] ) ) {
$notices[] = new AdminNotice( 'success', __( 'Logs cleared.', 'wp-content-sync' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_connection_error'] ) ) {
$notices[] = new AdminNotice( 'error', $this->queryValue( 'wpcs_connection_error' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
if ( isset( $_GET['wpcs_export_error'] ) ) {
$notices[] = new AdminNotice( 'error', $this->queryValue( 'wpcs_export_error' ) );
}
return $notices;
}
private function queryValue( string $key ): string {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reads redirect-only admin notice query args.
return sanitize_text_field( wp_unslash( $_GET[ $key ] ?? '' ) );
}
}