PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / Core / AdminNotifier.php

AdminNotifier.php in Tiered Pricing Table for WooCommerce trunk, at src/Core/AdminNotifier.php

81 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Core;
2
3 class AdminNotifier {
4
5 const ERROR = 'error';
6
7 const WARNING = 'warning';
8
9 const SUCCESS = 'success';
10
11 const INFO = 'info';
12
13 /**
14 * Notification key
15 *
16 * @var string
17 */
18 private $key = 'u2code_admin_notifications';
19
20 /**
21 * AdminNotifier constructor.
22 */
23 public function __construct() {
24 $this->key .= get_current_user_id();
25 $this->process();
26 }
27
28 /**
29 * Add message to show on admin_notices action
30 *
31 * @param string $message
32 * @param string $type
33 * @param bool $isDismissible
34 */
35 public function push( $message, $type = self::SUCCESS, $isDismissible = false ) {
36 $dismissible = $isDismissible ? 'is-dismissible' : '';
37 add_action( 'admin_notices', function () use ( $message, $type, $dismissible ) {
38 echo "<div class='notice notice-" . esc_attr($type) . ' ' . esc_attr($dismissible) . "'><p>" . wp_kses_post($message) . '</p></div>';
39 } );
40 }
41
42 /**
43 * Save flash message to show during next request
44 *
45 * @param string $message
46 * @param string $type
47 * @param bool $isDismissible
48 */
49 public function flash( $message, $type = self::SUCCESS, $isDismissible = false ) {
50 $message = array( 'message' => $message, 'type' => $type, 'dismissible' => $isDismissible );
51 $messages = get_transient( $this->key );
52
53 if ( ! is_array( $messages ) ) {
54 $messages = array();
55 }
56
57 $messages[] = $message;
58
59 set_transient( $this->key, $messages, MINUTE_IN_SECONDS );
60 }
61
62 /**
63 * Show flash messages
64 */
65 private function process() {
66 $messages = get_transient( $this->key );
67
68 //Resolve conflict with background process
69 if ( ! wp_doing_ajax() ) {
70 if ( is_array( $messages ) ) {
71
72 delete_transient( $this->key );
73
74 foreach ( $messages as $message ) {
75 $this->push( $message['message'], $message['type'], $message['dismissible'] );
76 }
77 }
78 }
79 }
80 }
81