PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.0
Tiered Pricing Table for WooCommerce v2.2.0
8.0.2 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 All 91 releases
tier-pricing-table / vendor / premmerce / wordpress-sdk / src / V2 / Notifications / AdminNotifier.php

AdminNotifier.php in Tiered Pricing Table for WooCommerce 2.2.0, at vendor/premmerce/wordpress-sdk/src/V2/Notifications/AdminNotifier.php

71 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace Premmerce\SDK\V2\Notifications;
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 private $key = 'premmerce_admin_notifications';
14
15 public function __construct(){
16 $this->key .= get_current_user_id();
17 $this->process();
18 }
19
20 /**
21 * Add message to show on admin_notices action
22 *
23 * @param string $message
24 * @param string $type
25 * @param bool $isDismissible
26 */
27 public function push($message, $type = self::SUCCESS, $isDismissible = false){
28 $dismissible = $isDismissible? "is-dismissible" : '';
29 add_action('admin_notices', function() use ($message, $type, $dismissible){
30 echo "<div class='notice notice-{$type} {$dismissible}'><p>{$message}</p></div>";
31 });
32 }
33
34 /**
35 * Save flash message to show during next request
36 *
37 * @param string $message
38 * @param string $type
39 * @param bool $isDismissible
40 */
41 public function flash($message, $type = self::SUCCESS, $isDismissible = false){
42 $message = ['message' => $message, 'type' => $type, 'dismissible' => $isDismissible];
43 $messages = get_transient($this->key);
44
45 if(!is_array($messages)){
46 $messages = [];
47 }
48
49 $messages[] = $message;
50
51 set_transient($this->key, $messages, MINUTE_IN_SECONDS);
52 }
53
54 /**
55 * Show flash messages
56 */
57 private function process(){
58 $messages = get_transient($this->key);
59
60 if(is_array($messages)){
61
62 delete_transient($this->key);
63
64 foreach($messages as $message){
65 $this->push($message['message'], $message['type'], $message['dismissible']);
66 }
67 }
68 }
69
70
71 }