PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 5.3.4
Pay with Vipps and MobilePay for WooCommerce v5.3.4
6.3.1 6.2.6 6.3.0 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 All 190 releases
woo-vipps / payment / VippsDismissibleAdminBanners.class.php

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

116 lines 4.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 }
58 }
59
60 public static function add() {
61 $instance = VippsDismissibleAdminBanners::instance();
62 add_action('wp_ajax_vipps_dismiss_notice', array($instance, 'ajax_vipps_dismiss_notice'));
63 // Add dismissible banners to the admin screen for promoting Vipps plugins/features
64 $instance->add_vipps_dismissible_admin_banners();
65 }
66
67 public function ajax_vipps_dismiss_notice() {
68 check_ajax_referer('vippssecnonce','vipps_sec');
69 Vipps::set_locale_if_in_header();
70 if (!isset($_POST['key']) || !$_POST['key']) return;
71 $dismissed = get_option('_vipps_dismissed_notices');
72 if (!is_array($dismissed)) $dismissed = array();
73 $key = sanitize_text_field($_POST['key']);
74 $dismissed[$key] = time();
75 Vipps::instance()->log(__("Dismissed message ", 'woo-vipps') . $key, 'info');
76 update_option('_vipps_dismissed_notices', $dismissed, false);
77 $this->dismissed = $dismissed;
78 wp_cache_flush();
79 }
80
81 // Advertise The Login Plugin if not installed
82 public function add_login_vipps_dismissible_admin_banner () {
83 if (!function_exists('get_plugins')) return;
84
85 $dismissed = $this->dismissed;
86 if (isset($dismissed['vippslogin01'])) return;
87
88 $installed_plugins = get_plugins();
89 if (isset($installed_plugins['login-with-vipps/login-with-vipps.php'])) {
90 if (!is_array($dismissed)) $dismissed = array();
91 $dismissed['vippslogin01'] = time();
92 update_option('_vipps_dismissed_notices', $dismissed, false);
93 $this->dismissed = $dismissed;
94 return;
95 }
96
97
98 add_action('admin_notices', function () {
99 $logo = plugins_url('img/vipps-rgb-orange-neg.svg',__FILE__);
100 $loginurl = "https://wordpress.org/plugins/login-with-vipps/#description";
101 ?>
102 <div class='notice notice-vipps notice-vipps-neg notice-info is-dismissible' data-key='vippslogin01'>
103 <a target="_blank" href="<?php echo $loginurl; ?>">
104 <img src="<?php echo $logo; ?>" style="float:left; height: 3rem; margin-top: 0.2rem" alt="Logg inn med Vipps-logo">
105 <div>
106 <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>
107 </div>
108 </a>
109 </div>
110 <?php
111 });
112 }
113
114
115 }
116