PluginProbe
PayPlug for WooCommerce (Official) / 2.10.0
PayPlug for WooCommerce (Official) v2.10.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 1.2.6 All 101 releases
← All changes | src/Admin/Notices.php +90 -99 3.0.02.10.0 View file →
@@ -2,126 +2,117 @@
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;
12 11
13 12 /**
14 13 * Handle admin notices.
14 + *
15 + * @package Payplug\PayplugWoocommerce\Admin
15 16 */
16 -class Notices
17 -{
18 - use ServiceGetter;
17 +class Notices {
19 18
20 - private $options;
19 + public function __construct() {
20 + //add_action( 'admin_notices', [ $this, 'admin_notices' ] );
21 + //add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
22 + }
21 23
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 - }
29 -
30 - /**
24 + /**
31 25 * Enqueue PayPlug notice style.
32 26 *
33 27 * @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 - }
28 + */
29 + public function admin_enqueue_scripts() {
30 + $options = get_option( 'woocommerce_payplug_settings' );
31 + $payplug_test_key = ! empty( $options['payplug_test_key'] ) ? $options['payplug_test_key'] : '';
32 + $payplug_live_key = ! empty( $options['payplug_live_key'] ) ? $options['payplug_live_key'] : '';
33 + if ( empty( $payplug_test_key ) && empty( $payplug_live_key ) ) {
34 + wp_enqueue_style(
35 + 'payplug-notice',
36 + PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/notice.css',
37 + [],
38 + PAYPLUG_GATEWAY_VERSION
39 + );
40 + }
41 + }
49 42
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 - }
43 + /**
44 + * Display admin notices.
45 + *
46 + * @return void
47 + */
48 + public function admin_notices() {
49 + if ( ! current_user_can( 'manage_woocommerce' ) ) {
50 + return;
51 + }
60 52
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'];
53 + /*
54 + * Before Woocommerce 3.2.x, settings were saved just before displaying the page
55 + * which cause the admin_notice to display old data.
56 + *
57 + * This condition check if we are on the PayPlug gateway settings page and if we
58 + * have new settings to save. If true we hook the notice to a hook which will run after the new
59 + * settings have been saved.
60 + */
61 + $screen = get_current_screen();
62 + $wc = function_exists( 'WC' ) ? WC() : $GLOBALS['woocommerce'];
71 63
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']);
64 + if (
65 + version_compare( $wc->version, '3.2.0', '<' )
66 + && ! empty( $_POST )
67 + && 'woocommerce_page_wc-settings' === $screen->id
68 + && isset( $_GET['section'] )
69 + && 'payplug' === $_GET['section']
70 + ) {
71 + add_action( 'woocommerce_settings_saved', [ $this, 'display_notice' ] );
80 72
81 - return;
82 - }
73 + return;
74 + }
83 75
84 - $this->display_notice();
85 - }
76 + $this->display_notice();
77 + }
86 78
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'] : '';
79 + public function display_notice() {
80 + $options = get_option( 'woocommerce_payplug_settings' );
81 + $testmode = ( isset( $options['mode'] ) && 'no' === $options['mode'] ) ? true : false;
82 + $payplug_test_key = ! empty( $options['payplug_test_key'] ) ? $options['payplug_test_key'] : '';
83 + $payplug_live_key = ! empty( $options['payplug_live_key'] ) ? $options['payplug_live_key'] : '';
93 84
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>
85 + if ( empty( $payplug_test_key ) && empty( $payplug_live_key ) ) {
86 + ?>
87 + <div class="notice notice--start">
88 + <div class="inside">
89 + <div class="main">
90 + <h2 class="notice__title"><?php _e( 'Thank you for installing PayPlug as your online payment solution.', 'payplug' ); ?>
91 + <br>
92 + <strong><?php _e( 'Only one step left to activate the plugin on your site !', 'payplug' ); ?></strong>
93 + </h2>
94 + <a href="<?php echo esc_url( PayplugWoocommerceHelper::get_setting_link() ); ?>"
95 + class="button button-hero"><?php _e( 'Login', 'payplug' ); ?></a>
96 + <img class="notice__img"
97 + src="<?php echo esc_url( PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/PAYPLUG_LOGO_blanc.svg' ); ?>"
98 + alt="PayPlug logo">
99 + </div>
100 + </div>
101 + </div>
111 102 <?php
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>
103 + } elseif ( ! empty( $payplug_test_key ) && empty( $payplug_live_key ) ) {
104 + ?>
105 + <div class="notice notice-warning">
106 + <p><strong><?php _e( 'PayPlug is in TEST mode', 'payplug' ); ?></strong></p>
107 + <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>
108 + </div>
118 109 <?php
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>
110 + } elseif ( ! empty( $payplug_live_key ) && $testmode ) {
111 + ?>
112 + <div class="notice notice-info">
113 + <p><?php _e( 'Payments in TEST mode will be simulations and will not generate real transactions.', 'payplug' ); ?></p>
114 + </div>
124 115 <?php
125 - }
126 - }
116 + }
117 + }
127 118 }