From af52f563398b42cff82d38eefa55c8121d698ebe Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 6 Mar 2023 16:46:08 -0800 Subject: [PATCH] admin_enqueue_scripts after common.js --- src/Dismiss.php | 60 ++++++++++++++++++++++++++----------------------- src/Notices.php | 20 ----------------- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/Dismiss.php b/src/Dismiss.php index 2abcbd9..22cfe98 100644 --- a/src/Dismiss.php +++ b/src/Dismiss.php @@ -63,42 +63,46 @@ public function __construct( $id, $prefix, $scope = 'global' ) { // Handle AJAX requests to dismiss the notice. add_action( 'wp_ajax_wptrt_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); + + // Print the script after common.js. + add_action( 'admin_enqueue_scripts', array( $this, 'add_script' ) ); } /** * Print the script for dismissing the notice. * - * @access private * @since 1.0 * @return void */ - public function print_script() { - - // Create a nonce. - $nonce = wp_create_nonce( 'wptrt_dismiss_notice_' . $this->id ); - ?> - - id ); + $nonce = wp_create_nonce( 'wptrt_dismiss_notice_' . $this->id ); + $admin_ajax_url = esc_url( admin_url( 'admin-ajax.php' ) ); + + $script = <<the_notice(); } } - - /** - * Prints scripts for the notices. - * - * @access public - * @since 1.0 - * @return void - */ - public function print_scripts() { - $notices = $this->get_all(); - - foreach ( $notices as $notice ) { - if ( $notice->show() ) { - $notice->dismiss->print_script(); - } - } - } }