PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.1.10
Pay with Vipps and MobilePay for WooCommerce v6.1.10
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 All 187 releases
woo-vipps / recurring / includes / wc-vipps-recurring-admin-notices.php

wc-vipps-recurring-admin-notices.php in Pay with Vipps and MobilePay for WooCommerce 6.1.10, at recurring/includes/wc-vipps-recurring-admin-notices.php

114 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5 class WC_Vipps_Recurring_Admin_Notices {
6 private static $instance;
7 private $admin_notices;
8 private $plugin_path;
9
10 const TYPES = 'error,campaign,warning,info,success';
11
12 private function __construct( $plugin_path ) {
13 $this->admin_notices = new stdClass();
14 $this->plugin_path = $plugin_path;
15
16 foreach ( explode( ',', self::TYPES ) as $type ) {
17 $this->admin_notices->{$type} = [];
18 }
19
20 add_action( 'admin_init', [ &$this, 'action_admin_init' ] );
21 add_action( 'admin_notices', [ &$this, 'action_admin_notices' ] );
22 }
23
24 public function action_admin_init(): void {
25 $dismiss_name = filter_input( INPUT_GET, 'vipps_recurring_dismiss', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
26
27 if ( is_string( $dismiss_name ) ) {
28 if ( $dismiss_name === 'one-or-more' ) {
29 set_transient( "vipps_recurring_dismissed_$dismiss_name", true, 30 * 24 * HOUR_IN_SECONDS );
30 } else {
31 update_option( "vipps_recurring_dismissed_$dismiss_name", true );
32 }
33
34 wp_die();
35 }
36 }
37
38 public function error( $message, $dismiss_name = null, $dismiss_option = false ): void {
39 $this->notice( 'error', $message, $dismiss_name, $dismiss_option );
40 }
41
42 public function warning( $message, $dismiss_name = null, $dismiss_option = false ): void {
43 $this->notice( 'warning', $message, $dismiss_name, $dismiss_option );
44 }
45
46 public function success( $message, $dismiss_name = null, $dismiss_option = false ): void {
47 $this->notice( 'success', $message, $dismiss_name, $dismiss_option );
48 }
49
50 public function info( $message, $dismiss_name = null, $dismiss_option = false ): void {
51 $this->notice( 'info', $message, $dismiss_name, $dismiss_option );
52 }
53
54 public function campaign( $message, $dismiss_name = null, $dismiss_option = false, $logo = null, $theme = null ): void {
55 $this->notice( 'campaign', $message, $dismiss_name, $dismiss_option, $logo, $theme );
56 }
57
58 private function notice( $type, $message, $dismiss_name, $dismiss_option, $logo = null, $theme = null ): void {
59 $notice = new stdClass();
60 $notice->message = $message;
61 $notice->dismiss_name = $dismiss_name;
62 $notice->dismiss_option = $dismiss_option;
63 $notice->logo = $logo;
64 $notice->theme = $theme;
65
66 $this->admin_notices->{$type}[] = $notice;
67 }
68
69 public function action_admin_notices(): void {
70 foreach ( explode( ',', self::TYPES ) as $type ) {
71 foreach ( $this->admin_notices->{$type} as $admin_notice ) {
72 $option = sanitize_title( $admin_notice->dismiss_name );
73
74 $dismiss_url = add_query_arg( [
75 'vipps_recurring_dismiss' => sanitize_title( $admin_notice->dismiss_name )
76 ], admin_url() );
77
78 $gateway = WC_Vipps_Recurring::get_instance()->gateway();
79
80 $logo_url = $admin_notice->logo ?? 'assets/images/vipps-mobilepay-logo.png';
81 $logo = plugins_url( $logo_url, $this->plugin_path );
82 $img_html = "<img src='$logo' alt=''>";
83
84 if ( ! get_option( "vipps_recurring_dismissed_{$option}" ) && ! get_transient( "vipps_recurring_dismissed_{$option}" ) ) {
85 ?>
86 <div class="ui message <?php echo $type; ?> notice notice-vipps-recurring <?php echo $gateway->brand; ?> notice-<?php echo $type;
87 if ( $admin_notice->theme ) {
88 echo " notice-vipps-recurring--$admin_notice->theme";
89 }
90
91 if ( $admin_notice->dismiss_option ) {
92 echo ' is-dismissible" data-dismiss-url="' . esc_url( $dismiss_url );
93 }
94 ?>">
95 <div class='notice-vipps-recurring__inner'>
96 <?php echo $img_html; ?>
97 <p><?php echo $admin_notice->message; ?></p>
98 </div>
99 </div>
100 <?php
101 }
102 }
103 }
104 }
105
106 public static function get_instance( $plugin_path ): WC_Vipps_Recurring_Admin_Notices {
107 if ( ! ( self::$instance instanceof self ) ) {
108 self::$instance = new self( $plugin_path );
109 }
110
111 return self::$instance;
112 }
113 }
114