HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: //var/chroot/var/www/wp-content/mu-plugins/gd-system-plugin/includes/admin/class-growl.php
<?php

namespace WPaaS\Admin;

use \WPaaS\Plugin;

if ( ! defined( 'ABSPATH' ) ) {

	exit;

}

final class Growl {

	/**
	 * Array of messages to display.
	 *
	 * @var array
	 */
	private static $messages = [];

	/**
	 * Class constructor.
	 */
	public function __construct() {

		/**
		 * Filter the admin growl messages.
		 *
		 * @since 2.0.0
		 *
		 * @var array
		 */
		self::$messages = (array) apply_filters( 'wpaas_admin_growl_messages', self::messages() );

		if ( self::$messages ) {

			add_action( 'init', [ $this, 'init' ] );

		}


	}

	/**
	 * Initialize the script.
	 *
	 * @action init
	 */
	public function init() {

		/**
		 * Filter the user cap required to view admin growls.
		 *
		 * @since 2.0.0
		 *
		 * @var string
		 */
		$cap = (string) apply_filters( 'wpaas_admin_growl_cap', 'activate_plugins' );

		if ( ! current_user_can( $cap ) ) {

			return;

		}

		add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
		add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
		add_action( 'admin_bar_menu', [ $this, 'display' ] );

	}

	/**
	 * Enqueue scripts and styles.
	 *
	 * @action wp_enqueue_scripts
	 */
	public function enqueue_scripts() {

		$rtl    = is_rtl() ? '-rtl' : '';
		$suffix = SCRIPT_DEBUG ? '' : '.min';

		wp_enqueue_script( 'wpaas-gritter', Plugin::assets_url( "js/jquery-gritter{$suffix}.js" ), [ 'jquery' ], '1.7.4', false );

		wp_enqueue_style( 'wpaas-gritter', Plugin::assets_url( "css/jquery-gritter{$rtl}{$suffix}.css" ), [], Plugin::version() );

	}

	/**
	 * Display any system messages to the user.
	 *
	 * @action admin_bar_menu
	 */
	public function display() {

		?>
		<script type="text/javascript">
			jQuery( document ).ready( function( $ ) {
				<?php foreach ( self::$messages as $message ) : ?>
					$.gritter.add( {
						title: "<?php echo esc_js( __( 'Success', 'gd-system-plugin' ) ); ?>",
						text: "<?php echo esc_js( $message ); ?>",
						time: <?php echo absint( 5 * 1000 ); ?>
					} );
				<?php endforeach; ?>
			} );
		</script>
		<?php

		delete_option( 'gd_system_growl_messages' );

	}

	/**
	 * Return an array of messages from the database.
	 *
	 * @return array
	 */
	public static function messages() {

		return (array) get_option( 'gd_system_growl_messages', [] );

	}

	/**
	 * Add a message to be displayed to the user.
	 *
	 * @param string $message
	 */
	public static function add( $message ) {
		self::$messages   = self::messages();
		self::$messages[] = $message;

		update_option( 'gd_system_growl_messages', self::$messages );

	}

}