PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.7
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.7
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / modules / login-popup / class-login-popup.php

class-login-popup.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.7, at inc/modules/login-popup/class-login-popup.php

260 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Login Popup
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Floating login popup class.
15 *
16 */
17 class Merchant_Login_Popup extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'login-popup';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Constructor.
33 *
34 */
35 public function __construct() {
36
37 // Module id.
38 $this->module_id = self::MODULE_ID;
39
40 // WooCommerce only.
41 $this->wc_only = true;
42
43 // Parent construct.
44 parent::__construct();
45
46 // Module section.
47 $this->module_section = 'improve-experience';
48
49 // Module default settings.
50 $this->module_default_settings = array(
51 'login_link_text' => esc_html__( 'Login', 'merchant' ),
52 'show_welcome_message' => true,
53 /* Translators: 1. Display name */
54 'welcome_message_text' => sprintf( esc_html__( 'Welcome %s', 'merchant' ), '{display_name}' )
55 );
56
57 // Mount preview url.
58 $preview_url = site_url( '/' );
59
60 // Module data.
61 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
62 $this->module_data[ 'preview_url' ] = $preview_url;
63
64 // Module options path.
65 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
66
67 // Is module preview page.
68 if ( is_admin() && parent::is_module_settings_page() ) {
69 self::$is_module_preview = true;
70
71 // Enqueue admin styles.
72 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
73
74 // Enqueue admin scripts.
75 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
76
77 // Admin preview box.
78 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
79
80 // Custom CSS.
81 // The custom CSS should be added here as well due to ensure preview box works properly.
82 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
83
84 }
85 }
86
87 /**
88 * Admin enqueue CSS.
89 *
90 * @return void
91 */
92 public function admin_enqueue_css() {
93 if ( parent::is_module_settings_page() ) {
94 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/login-popup.min.css', [], MERCHANT_VERSION );
95 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
96 }
97 }
98
99 /**
100 * Admin Enqueue scripts.
101 *
102 * @return void
103 */
104 public function admin_enqueue_scripts() {
105
106 // Register and enqueue the main module script.
107 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/login-popup.min.js', array(), MERCHANT_VERSION, true );
108 }
109
110 /**
111 * Render admin preview
112 *
113 * @param Merchant_Admin_Preview $preview
114 * @param string $module
115 *
116 * @return Merchant_Admin_Preview
117 */
118 public function render_admin_preview( $preview, $module ) {
119 if ( $module === self::MODULE_ID ) {
120 ob_start();
121 self::admin_preview_content();
122 $content = ob_get_clean();
123
124 $preview->set_html( $content );
125
126 $preview->set_text( 'welcome_message_text', '.merchant-login-popup-button', array(
127 array(
128 '{display_name}'
129 ),
130 array(
131 'Bob Jansen'
132 )
133 )
134 );
135 $preview->set_css( 'login-text-color', '.merchant-login-popup-dropdown', '--merchant-login-text-color' );
136 $preview->set_css( 'login-text-color-hover', '.merchant-login-popup-dropdown', '--merchant-login-text-color-hover' );
137 $preview->set_css( 'dropdown-background-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
138 $preview->set_css( 'dropdown-link-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
139 $preview->set_css( 'dropdown-link-color-hover', '#515151', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
140
141 $preview->set_css( 'popup-width', '.merchant-login-popup', '--merchant-popup-width', 'px' );
142 $preview->set_css( 'popup-title-color', '.merchant-login-popup', '--merchant-popup-title-color' );
143 $preview->set_css( 'popup-text-color', '.merchant-login-popup', '--merchant-popup-text-color' );
144 $preview->set_css( 'popup-icon-color', '.merchant-login-popup', '--merchant-popup-icon-color' );
145 $preview->set_css( 'popup-link-color', '.merchant-login-popup', '--merchant-popup-link-color' );
146 $preview->set_css( 'popup-button-color', '.merchant-login-popup', '--merchant-popup-button-color' );
147 $preview->set_css( 'popup-button-color-hover', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
148 $preview->set_css( 'popup-button-border-color', '.merchant-login-popup', '--merchant-popup-button-border-color' );
149 $preview->set_css( 'popup-button-border-color-hover', '.merchant-login-popup', '--merchant-popup-button-border-color-hover' );
150 $preview->set_css( 'popup-button-background-color', '.merchant-login-popup', '--merchant-popup-button-background-color' );
151 $preview->set_css( 'popup-button-background-color-hover', '.merchant-login-popup', '--merchant-popup-button-background-color-hover' );
152 $preview->set_css( 'popup-link-color-hover', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
153 $preview->set_css( 'popup-background-color', '.merchant-login-popup', '--merchant-popup-background-color' );
154
155 $preview->set_css( 'popup-footer-text-color', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
156 $preview->set_css( 'popup-footer-link-color', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
157 $preview->set_css( 'popup-footer-link-color-hover', '.merchant-login-popup', '--merchant-popup-footer-link-color-hover' );
158 $preview->set_css( 'popup-footer-background-color', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
159 }
160
161 return $preview;
162 }
163
164 /**
165 * Admin preview content.
166 *
167 * @return void
168 */
169 public function admin_preview_content() {
170 $settings = $this->get_module_settings();
171
172 $welcome_text = $settings[ 'welcome_message_text' ];
173 $welcome_text = str_replace(
174 array('{user_firstname}', '{user_lastname}', '{user_email}', '{user_login}', '{display_name}'),
175 array('Bob', 'Jansen', 'bob@gmail.com', 'Bob Jansen', 'Bob Jansen'),
176 $welcome_text
177 );
178
179 ?>
180
181 <a href="#" class="merchant-login-popup-button merchant-login-popup-toggle"><?php echo esc_html( $settings[ 'login_link_text' ] ); ?></a>
182
183 <div class="merchant-login-popup">
184 <div class="merchant-login-popup-overlay merchant-login-popup-toggle"></div>
185 <div class="merchant-login-popup-body">
186 <a href="#" class="merchant-login-popup-close merchant-login-popup-toggle">
187 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-cancel' ), merchant_kses_allowed_tags( [], false ) ); ?>
188 </a>
189 <div class="merchant-login-popup-content">
190 <?php if ( function_exists( 'wc_get_template' ) ) : ?>
191 <?php wc_get_template( 'myaccount/form-login.php' ); ?>
192 <?php endif; ?>
193 </div>
194
195 <?php if ( 'yes' === get_option( 'woocommerce_enable_myaccount_registration' ) ) : ?>
196 <div class="merchant-login-popup-footer">
197 <div class="merchant-show"><?php esc_html_e( 'Not a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Register', 'merchant' ); ?></a></div>
198 <div><?php esc_html_e( 'Already a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Login', 'merchant' ); ?></a></div>
199 </div>
200 <?php endif; ?>
201 </div>
202 </div>
203
204 <?php
205 }
206
207 /**
208 * Custom CSS.
209 *
210 * @return string
211 */
212 public function get_module_custom_css() {
213 $css = '';
214
215 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color' );
216 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color-hover', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color-hover' );
217 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-background-color', '#ffffff', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
218 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color', '#212121', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
219 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color-hover', '#515151', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
220
221 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-width', 400, '.merchant-login-popup', '--merchant-popup-width', 'px' );
222 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-title-color', '#212121', '.merchant-login-popup', '--merchant-popup-title-color' );
223 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-text-color' );
224 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-icon-color', '#212121', '.merchant-login-popup', '--merchant-popup-icon-color' );
225 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-link-color' );
226 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color' );
227 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color-hover', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
228 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-border-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-border-color' );
229 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-border-color-hover', '#757575', '.merchant-login-popup', '--merchant-popup-button-border-color-hover' );
230 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-background-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-background-color' );
231 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-background-color-hover', '#757575', '.merchant-login-popup', '--merchant-popup-button-background-color-hover' );
232 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color-hover', '#515151', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
233 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-background-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-background-color' );
234
235 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
236 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
237 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-link-color-hover', '#515151', '.merchant-login-popup', '--merchant-popup-footer-link-color-hover' );
238 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-background-color', '#f5f5f5', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
239
240 return $css;
241 }
242
243 /**
244 * Admin custom CSS.
245 *
246 * @param string $css The custom CSS.
247 * @return string $css The custom CSS.
248 */
249 public function admin_custom_css( $css ) {
250 $css .= $this->get_module_custom_css();
251
252 return $css;
253 }
254 }
255
256 // Initialize the module.
257 add_action( 'init', function() {
258 Merchant_Modules::create_module(new Merchant_Login_Popup());
259 } );
260