PUM_Utils_Alerts::admin_notices()

Render admin alerts if available.


Description Description


Source Source

File: classes/Utils/Alerts.php

	public static function admin_notices() {
		if ( ! self::should_show_alerts() ) {
			return;
		}

		$global_only = ! pum_is_admin_page();

		$alerts = $global_only ? self::get_global_alerts() : self::get_alerts();

		$count = count( $alerts );

		if ( ! $count ) {
			return;
		}

		wp_enqueue_script( 'pum-admin-general' );
		wp_enqueue_style( 'pum-admin-general' );

		$nonce = wp_create_nonce( 'pum_alerts_action' );
		?>

		<script type="text/javascript">
            window.pum_alerts_nonce = '<?php echo $nonce ?>';
		</script>

		<div class="pum-alerts">

			<h3>
				<img alt="" class="logo" width="30" src="<?php echo Popup_Maker::$URL; ?>assets/images/logo.png" /> <?php printf( '%s%s (%s)', ( $global_only ? __( 'Popup Maker', 'popup-maker' ) . ' ' : '' ), __( 'Notifications', 'popup-maker' ), '<span class="pum-alert-count">' . $count . '</span>' ); ?>
			</h3>

			<p><?php __( 'Check out the following notifications from Popup Maker.', 'popup-maker' ); ?></p>

			<?php foreach ( $alerts as $alert ) {
				$expires = 1 == $alert['dismissible'] ? '' :  $alert['dismissible'];
				$dismiss_url = add_query_arg( array(
					'nonce'             => $nonce,
					'code'              => $alert['code'],
					'pum_dismiss_alert' => 'dismiss',
					'expires'           => $expires,
				));
				?>

				<div class="pum-alert-holder" data-code="<?php echo $alert['code']; ?>" class="<?php echo $alert['dismissible'] ? 'is-dismissible' : ''; ?>" data-dismissible="<?php echo esc_attr( $alert['dismissible'] ); ?>">

					<div class="pum-alert <?php echo '' !== $alert['type'] ? 'pum-alert__' . esc_attr( $alert['type'] ) : ''; ?>">

						<?php if ( ! empty( $alert['message'] ) ) : ?>
							<p><?php echo $alert['message']; ?></p>
						<?php endif; ?>

						<?php if ( ! empty( $alert['html'] ) ) : ?>
							<?php echo function_exists( 'wp_encode_emoji' ) ? wp_encode_emoji( $alert['html'] ) : $alert['html']; ?>
						<?php endif; ?>

						<?php if ( ! empty( $alert['actions'] ) && is_array( $alert['actions'] ) ) : ?>
							<ul>
								<?php
								foreach ( $alert['actions'] as $action ) {
									$link_text = ! empty( $action['primary'] ) && true === $action['primary'] ? '<strong>' . esc_html( $action['text'] ) . '</strong>' : esc_html( $action['text'] );
									if ( 'link' === $action['type'] ) {
										$url        = $action['href'];
										$attributes = 'target="_blank" rel="noreferrer noopener"';
									} else {
										$url = add_query_arg( array(
											'nonce'             => $nonce,
											'code'              => $alert['code'],
											'pum_dismiss_alert' => $action['action'],
											'expires'           => $expires,
										));

										$attributes = 'class="pum-dismiss"';
									}
									?>
									<li><a data-action="<?php echo esc_attr( $action['action'] ); ?>" href="<?php echo esc_url( $url ); ?>" <?php echo $attributes; ?> ><?php echo $link_text; ?></a></li>
								<?php } ?>
							</ul>
						<?php endif; ?>

					</div>

					<?php if ( $alert['dismissible'] ) : ?>

						<a href="<?php echo esc_url( $dismiss_url ); ?>" data-action="dismiss" class="button dismiss pum-dismiss">
							<span class="screen-reader-text"><?php _e( 'Dismiss this item.', 'popup-maker' ); ?></span> <span class="dashicons dashicons-no-alt"></span>
						</a>

					<?php endif; ?>

				</div>

			<?php } ?>

		</div>

		<?php
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.