| Server IP : 3.93.235.159 / Your IP : 216.73.216.140 Web Server : Apache System : Linux ip-172-26-0-169 5.10.0-46-cloud-amd64 #1 SMP Debian 5.10.262-1 (2026-07-31) x86_64 User : bitnami ( 1000) PHP Version : 8.2.9 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /bitnami/wordpress/wp-content/plugins/pojo-accessibility/modules/core/components/ |
Upload File : |
<?php
namespace EA11y\Modules\Core\Components;
use EA11y\Classes\Utils\Notice_Base;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Notices {
const AJAX_ACTION = 'ea11y_admin_notice_dismiss';
/**
* @var Notice_Base[] $notices
*/
public array $notices = [];
public function register_notice( $notice_instance ) {
$this->notices[ $notice_instance->get_id() ] = $notice_instance;
}
public function show_notices() {
foreach ( $this->notices as $notice ) {
$notice->maybe_show_notice();
}
}
public function handle_dismiss() {
if ( empty( $_REQUEST['notice_id'] ) ) {
wp_send_json_error( [ 'message' => 'Invalid ID' ] );
}
$notice = $this->get_notice( sanitize_text_field( wp_unslash( $_REQUEST['notice_id'] ) ) );
if ( ! $notice ) {
wp_send_json_error( [ 'message' => 'Invalid ID' ] );
}
$notice->handle_dismiss();
wp_send_json_success( [] );
}
/**
* @param string $sanitize_text_field
*
* @return Notice_Base|null
*/
private function get_notice( string $sanitize_text_field ): ?Notice_Base {
return $this->notices[ $sanitize_text_field ] ?? null;
}
public function __construct() {
if ( ! is_admin() ) {
return;
}
add_action( 'admin_notices', [ $this, 'show_notices' ] );
add_action( 'wp_ajax_' . self::AJAX_ACTION, [ $this, 'handle_dismiss' ] );
add_action('init', function () {
do_action( 'ea11y_register_notices', $this );
});
}
}