'', 'variant' => 'info', 'message' => '', 'title' => '', 'actions' => [], 'dismissible' => true, 'pages' => [ 'all' ], ] ); // Ensure pages is an array. if ( ! is_array( $notice['pages'] ) ) { $notice['pages'] = [ $notice['pages'] ]; } // Store the notice. self::$notices[ $notice['id'] ] = $notice; } /** * Get all registered notices. * * @return array Array of notice configurations. * @since 2.5.0 */ public static function get_notices() { return array_values( self::$notices ); } /** * Remove a registered notice. * * @param string $notice_id The notice ID to remove. * @return void * @since 2.5.0 */ public static function remove_notice( $notice_id ) { if ( isset( self::$notices[ $notice_id ] ) ) { unset( self::$notices[ $notice_id ] ); } } /** * Clear all registered notices. * * @return void * @since 2.5.0 */ public static function clear_notices() { self::$notices = []; } /** * Add notices to localized data for React. * * This filter callback adds the notices array to the localized script data * that gets passed to React via window.srfm_admin. * * @param array $localization_data Existing localization data. * @return array Modified localization data with notices. * @since 2.5.0 */ public function add_notices_to_localized_data( $localization_data ) { $localization_data['notices'] = self::get_notices(); return $localization_data; } /** * Helper method to register a notice from existing PHP admin_notices hooks. * * This method simplifies converting existing PHP notices to work with React. * Call this method from your existing admin_notices callback to also register * the notice for React pages. * * Example usage: * ```php * public function my_admin_notice() { * $message = '

' . esc_html__( 'Important notice!', 'sureforms' ) . '

'; * * // Display in PHP (existing behavior - continues to work) * echo '
' . wp_kses_post( $message ) . '
'; * * // Also register for React pages (new behavior) * Notice_Manager::register_from_php_notice( * 'my-notice-id', * 'error', * $message, * [ * [ * 'label' => __( 'Fix Now', 'sureforms' ), * 'url' => admin_url( 'admin.php?page=settings' ), * ] * ] * ); * } * ``` * * @param string $id Unique notice identifier. * @param string $variant Notice type: 'error', 'warning', 'info', 'success'. * @param string $message Notice message. Plain text only; see register_notice(). * @param array $actions Optional. Array of action button configurations. * @param array $pages Optional. Page slugs where notice should appear. Default ['all']. * @return void * @since 2.5.0 */ public static function register_from_php_notice( $id, $variant, $message, $actions = [], $pages = [ 'all' ] ) { self::register_notice( [ 'id' => $id, 'variant' => $variant, 'message' => $message, 'actions' => $actions, 'pages' => $pages, ] ); } }