PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.2.2
Pay with Vipps and MobilePay for WooCommerce v6.2.2
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 5.4.1 5.4.0 All 185 releases
woo-vipps / payment / VippsDismissibleAdminBanners.class.php

VippsDismissibleAdminBanners.class.php in Pay with Vipps and MobilePay for WooCommerce 6.2.2, at payment/VippsDismissibleAdminBanners.class.php

141 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 This singleton class exists just to organize dismissible admin banners that Vipps sometimes wants to show users.
4
5
6 This file is part of the plugin Pay with Vipps and MobilePay for WooCommerce
7 Copyright (c) 2022 WP-Hosting AS
8
9 MIT License
10
11 Copyright (c) 2022 WP-Hosting AS
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30
31
32 */
33 if ( ! defined( 'ABSPATH' ) ) {
34 exit; // Exit if accessed directly
35 }
36
37 class VippsDismissibleAdminBanners {
38 private static $instance = null;
39 private $dismissed = null;
40 public $configured = false;
41 public $vipps_checkout_enabled = false;
42 public static function instance() {
43 if (!static::$instance) static::$instance = new VippsDismissibleAdminBanners();
44 return static::$instance;
45 }
46
47 function __construct() {
48 $this->dismissed = get_option('_vipps_dismissed_notices');
49 $this->configured = get_option('woo-vipps-configured');
50 $this->vipps_checkout_enabled = get_option('woo_vipps_checkout_activated'); // if true, the pages exists etc
51 }
52
53 public function add_vipps_dismissible_admin_banners() {
54 if ($this->configured) {
55 // Login with Vipps
56 $this->add_login_vipps_dismissible_admin_banner();
57 // The Checkout sold to Kustom banner
58 $this->add_kustom_checkout_banner();
59 }
60 }
61
62 public static function add() {
63 $instance = VippsDismissibleAdminBanners::instance();
64 add_action('wp_ajax_vipps_dismiss_notice', array($instance, 'ajax_vipps_dismiss_notice'));
65 // Add dismissible banners to the admin screen for promoting Vipps plugins/features
66 $instance->add_vipps_dismissible_admin_banners();
67 }
68
69 public function ajax_vipps_dismiss_notice() {
70 check_ajax_referer('vippssecnonce','vipps_sec');
71 Vipps::set_locale_if_in_header();
72 if (!isset($_POST['key']) || !$_POST['key']) return;
73 $dismissed = get_option('_vipps_dismissed_notices');
74 if (!is_array($dismissed)) $dismissed = array();
75 $key = sanitize_text_field($_POST['key']);
76 $dismissed[$key] = time();
77 Vipps::instance()->log(__("Dismissed message ", 'woo-vipps') . $key, 'info');
78 update_option('_vipps_dismissed_notices', $dismissed, false);
79 $this->dismissed = $dismissed;
80 wp_cache_flush();
81 }
82
83 // Advertise The Login Plugin if not installed
84 public function add_login_vipps_dismissible_admin_banner () {
85 if (!function_exists('get_plugins')) return;
86
87 $dismissed = $this->dismissed;
88 if (isset($dismissed['vippslogin01'])) return;
89
90 $installed_plugins = get_plugins();
91 if (isset($installed_plugins['login-with-vipps/login-with-vipps.php'])) {
92 if (!is_array($dismissed)) $dismissed = array();
93 $dismissed['vippslogin01'] = time();
94 update_option('_vipps_dismissed_notices', $dismissed, false);
95 $this->dismissed = $dismissed;
96 return;
97 }
98
99
100 add_action('admin_notices', function () {
101 $logo = plugins_url('img/vipps-rgb-orange-neg.svg',__FILE__);
102 $loginurl = "https://wordpress.org/plugins/login-with-vipps/#description";
103 ?>
104 <div class='notice notice-vipps notice-vipps-neg notice-info is-dismissible' data-key='vippslogin01'>
105 <a target="_blank" href="<?php echo $loginurl; ?>">
106 <img src="<?php echo $logo; ?>" style="float:left; height: 3rem; margin-top: 0.2rem" alt="Logg inn med Vipps-logo">
107 <div>
108 <p style="font-size:1rem"><?php echo __("Login with Vipps is available for WordPress and WooCommerce - Super easy registration and login - No more usernames and passwords. Get started here", 'woo-vipps'); ?></p>
109 </div>
110 </a>
111 </div>
112 <?php
113 });
114 }
115
116 // Notify users of Checkout that this is sold to Custom and should be
117 public function add_kustom_checkout_banner () {
118 $dismissed = $this->dismissed;
119 if (isset($dismissed['vippskustom01'])) return;
120
121 $gw = Vipps::instance()->gateway();
122 if (class_exists('VippsCheckout') && $gw->get_option('vipps_checkout_enabled') == 'yes') {
123 add_action('admin_notices', function () {
124 $logo = plugins_url('img/vipps-rgb-orange-neg.svg',__FILE__);
125 $kustomurl = "https://docs.kustom.co/contents/partners/e-commerce-platforms/woocommerce-vipps-guide";
126 ?>
127 <div class='notice notice-vipps notice-vipps-neg notice-info is-dismissible' data-key='vippskustom01'>
128 <img src="<?php echo $logo; ?>" style="float:left; height: 3rem; margin-top: 0.2rem" alt="Vipps-logo">
129 <div>
130 <h2 style='color:white'><?php echo __('Checkout - Important Update', 'woo-vipps'); ?></h2>
131 <p style="color:white;font-size:1rem"><?php echo sprintf(__("Vipps MobilePay has entered into an agreement to sell Checkout to Kustom. As part of this transition, <b>Vipps Mobilepay Checkout will become Kustom Checkout</b>. You can follow <a style='font-weight:bold' target='_blank', href='%s'>this guide</a></b> to migrate over to Kustom Checkout.", 'woo-vipps'), esc_attr($kustomurl)); ?></p>
132 <p style="color:white;font-size:1rem"><?php echo sprintf(__('For help you can reach out to <a href="mailto:%1$s">%1$s</a> and <a href="tel:%2$s">%3$s</a>. You can also find the Kustom portal <a href="%4$s" target="_blank">here</a>.', 'woo-vipps'), 'support@kustom.co', '+4721564684', '+47 21 56 46 84', 'https://portal.kustom.co/'); ?></p>
133 </div>
134 </div>
135 <?php
136 });
137 }
138 }
139
140 }
141