PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
← All changes | src/Admin/Notices.php +102 -150 1.0.6 → 3.1.0 View file →
@@ -2,174 +2,126 @@
2 2
3 3 namespace Payplug\PayplugWoocommerce\Admin;
4 4
5 5 // Exit if accessed directly
6 -if ( ! defined( 'ABSPATH' ) ) {
7 - exit;
6 +if (!defined('ABSPATH')) {
7 + exit;
8 8 }
9 9
10 10 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
11 +use Payplug\PayplugWoocommerce\Traits\ServiceGetter;
11 12
12 13 /**
13 14 * Handle admin notices.
14 - *
15 - * @package Payplug\PayplugWoocommerce\Admin
16 15 */
17 -class Notices {
16 +class Notices
17 +{
18 + use ServiceGetter;
18 19
19 - public function __construct() {
20 - add_action( 'admin_notices', [ $this, 'admin_notices' ] );
21 - }
20 + private $options;
22 21
23 - /**
24 - * Display admin notices.
25 - *
26 - * @return void
27 - */
28 - public function admin_notices() {
29 - if ( ! current_user_can( 'manage_woocommerce' ) ) {
30 - return;
31 - }
22 + public function __construct()
23 + {
24 + $this->options = $this->get_service('configuration')->get_options();
25 + // $this->options = PayplugWoocommerceHelper::get_payplug_options();
26 + //add_action( 'admin_notices', [ $this, 'admin_notices' ] );
27 + //add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
28 + }
32 29
33 - /*
34 - * Before Woocommerce 3.2.x, settings were saved just before displaying the page
35 - * which cause the admin_notice to display old data.
36 - *
37 - * This condition check if we are on the PayPlug gateway settings page and if we
38 - * have new settings to save. If true we hook the notice to a hook which will run after the new
39 - * settings have been saved.
40 - */
41 - $screen = get_current_screen();
42 - $wc = function_exists( 'WC' ) ? WC() : $GLOBALS['woocommerce'];
30 + /**
31 + * Enqueue PayPlug notice style.
32 + *
33 + * @return void
34 + */
35 + public function admin_enqueue_scripts(): void
36 + {
37 + $api_key = json_decode($this->options, true);
38 + $test_key = !empty($api_key['test']) ? $api_key['test'] : '';
39 + $live_key = !empty($api_key['live']) ? $api_key['live'] : '';
40 + if (empty($test_key) && empty($live_key)) {
41 + wp_enqueue_style(
42 + 'payplug-notice',
43 + PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/notice.css',
44 + [],
45 + PAYPLUG_GATEWAY_VERSION
46 + );
47 + }
48 + }
43 49
44 - if (
45 - version_compare( $wc->version, '3.2.0', '<' )
46 - && ! empty( $_POST )
47 - && 'woocommerce_page_wc-settings' === $screen->id
48 - && isset( $_GET['section'] )
49 - && 'payplug' === $_GET['section']
50 - ) {
51 - add_action( 'woocommerce_settings_saved', [ $this, 'display_notice' ] );
50 + /**
51 + * Display admin notices.
52 + *
53 + * @return void
54 + */
55 + public function admin_notices(): void
56 + {
57 + if (!current_user_can('manage_woocommerce')) {
58 + return;
59 + }
52 60
53 - return;
54 - }
61 + /*
62 + * Before Woocommerce 3.2.x, settings were saved just before displaying the page
63 + * which cause the admin_notice to display old data.
64 + *
65 + * This condition check if we are on the PayPlug gateway settings page and if we
66 + * have new settings to save. If true we hook the notice to a hook which will run after the new
67 + * settings have been saved.
68 + */
69 + $screen = get_current_screen();
70 + $wc = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];
55 71
56 - $this->display_notice();
57 - }
72 + if (
73 + version_compare($wc->version, '3.2.0', '<')
74 + && !empty($_POST)
75 + && 'woocommerce_page_wc-settings' === $screen->id
76 + && isset($_GET['section'])
77 + && 'payplug' === $_GET['section']
78 + ) {
79 + add_action('woocommerce_settings_saved', [$this, 'display_notice']);
58 80
59 - public function display_notice() {
60 - $options = get_option( 'woocommerce_payplug_settings' );
61 - $testmode = ( isset( $options['mode'] ) && 'no' === $options['mode'] ) ? true : false;
62 - $payplug_test_key = ! empty( $options['payplug_test_key'] ) ? $options['payplug_test_key'] : '';
63 - $payplug_live_key = ! empty( $options['payplug_live_key'] ) ? $options['payplug_live_key'] : '';
81 + return;
82 + }
64 83
65 - if ( empty( $payplug_test_key ) && empty( $payplug_live_key ) ) {
66 - ?>
67 - <style>
68 - .notice--start {
69 - position: relative;
70 - border: 0;
71 - padding: 30px 40px;
72 - background: url(<?php echo esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/bg_notice--start.jpg' ); ?>) no-repeat 50% 50%;
73 - background-size: cover;
74 - }
84 + $this->display_notice();
85 + }
75 86
76 - .notice--start:before {
77 - content: "";
78 - display: block;
79 - z-index: 1;
80 - position: absolute;
81 - top: 0;
82 - right: 0;
83 - bottom: 0;
84 - left: 0;
85 - background-color: #49829f;
86 - opacity: .28;
87 - }
87 + public function display_notice(): void
88 + {
89 + $testmode = isset($this->options['mode']) && !(bool) $this->options['mode'];
90 + $api_key = json_decode($this->options, true);
91 + $test_key = !empty($api_key['test']) ? $api_key['test'] : '';
92 + $live_key = !empty($api_key['live']) ? $api_key['live'] : '';
88 93
89 - .notice--start .main {
90 - position: relative;
91 - z-index: 2;
92 - }
93 -
94 - .notice--start .notice__title {
95 - margin-top: 0;
96 - color: #fff;
97 - font-size: 16px;
98 - font-weight: 400;
99 - line-height: 1.55;
100 - }
101 -
102 - .notice--start .notice__title strong {
103 - font-size: 20px;
104 - font-weight: 700;
105 - }
106 -
107 - .notice--start .button.button-hero {
108 - font-weight: 400;
109 - font-size: 16px;
110 - height: 46px;
111 - box-shadow: none;
112 - color: #fff;
113 - border-color: #55bf9c;
114 - background-color: #55bf9c;
115 - }
116 -
117 - .notice--start .button:hover,
118 - .notice--start .button:focus,
119 - .notice--start .button:active {
120 - color: #fff;
121 - border-color: #4a977d;
122 - background-color: #4a977d;
123 - }
124 -
125 - .notice--start .notice__img {
126 - display: block;
127 - margin: auto;
128 - }
129 -
130 - @media screen and (min-width: 48em) {
131 - .notice--start .main {
132 - padding-right: 250px;
133 - }
134 -
135 - .notice--start .notice__img {
136 - margin: 0;
137 - position: absolute;
138 - right: 0;
139 - top: 50%;
140 - transform: translateY(-50%);
141 - }
142 - }
143 - </style>
144 - <div class="notice notice--start">
145 - <div class="inside">
146 - <div class="main">
147 - <h2 class="notice__title"><?php _e( 'Thank you for installing PayPlug as your online payment solution.', 'payplug' ); ?>
148 - <br>
149 - <strong><?php _e( 'Only one step left to activate the plugin on your site !', 'payplug' ); ?></strong>
150 - </h2>
151 - <a href="<?php echo esc_url( PayplugWoocommerceHelper::get_setting_link() ); ?>"
152 - class="button button-hero"><?php _e( 'Login', 'payplug' ); ?></a>
153 - <img class="notice__img"
154 - src="<?php echo esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/Payplug_logoWhite.png' ); ?>"
155 - alt="PayPlug logo">
156 - </div>
157 - </div>
158 - </div>
94 + if (empty($test_key) && empty($live_key)) {
95 + ?>
96 + <div class="notice notice--start">
97 + <div class="inside">
98 + <div class="main">
99 + <h2 class="notice__title"><?php _e('Thank you for installing PayPlug as your online payment solution.', 'payplug'); ?>
100 + <br>
101 + <strong><?php _e('Only one step left to activate the plugin on your site !', 'payplug'); ?></strong>
102 + </h2>
103 + <a href="<?php echo esc_url(PayplugWoocommerceHelper::get_setting_link()); ?>"
104 + class="button button-hero"><?php _e('Login', 'payplug'); ?></a>
105 + <img class="notice__img"
106 + src="<?php echo esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/PAYPLUG_LOGO_blanc.svg'); ?>"
107 + alt="PayPlug logo">
108 + </div>
109 + </div>
110 + </div>
159 111 <?php
160 - } elseif ( ! empty( $payplug_test_key ) && empty( $payplug_live_key ) ) {
161 - ?>
162 - <div class="notice notice-warning">
163 - <p><strong><?php _e( 'PayPlug is in TEST mode', 'payplug' ); ?></strong></p>
164 - <p><?php _e( 'Once your PayPlug account has been validated, please log out and log in again from the configuration page in order to activate LIVE mode.', 'payplug' ); ?></p>
165 - </div>
112 + } elseif (!empty($test_key) && empty($live_key)) {
113 + ?>
114 + <div class="notice notice-warning">
115 + <p><strong><?php _e('PayPlug is in TEST mode', 'payplug'); ?></strong></p>
116 + <p><?php _e('Once your PayPlug account has been validated, please log out and log in again from the configuration page in order to activate LIVE mode.', 'payplug'); ?></p>
117 + </div>
166 118 <?php
167 - } elseif ( ! empty( $payplug_live_key ) && $testmode ) {
168 - ?>
169 - <div class="notice notice-info">
170 - <p><?php _e( 'Payments in TEST mode will be simulations and will not generate real transactions.', 'payplug' ); ?></p>
171 - </div>
119 + } elseif (!empty($live_key) && $testmode) {
120 + ?>
121 + <div class="notice notice-info">
122 + <p><?php _e('Payments in TEST mode will be simulations and will not generate real transactions.', 'payplug'); ?></p>
123 + </div>
172 124 <?php
173 - }
174 - }
175 -}
125 + }
126 + }
127 +}