PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.2
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.8.2, at inc/modules/login-popup/class-login-popup.php

280 lines 12.4 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 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
87 // Init translations.
88 $this->init_translations();
89 }
90 }
91
92 /**
93 * Init translations.
94 *
95 * @return void
96 */
97 public function init_translations() {
98 $settings = $this->get_module_settings();
99 if ( ! empty( $settings['login_link_text'] ) ) {
100 Merchant_Translator::register_string( $settings['login_link_text'], esc_html__( 'Login popup: link text', 'merchant' ) );
101 }
102 if ( ! empty( $settings['welcome_message_text'] ) ) {
103 Merchant_Translator::register_string( $settings['welcome_message_text'], esc_html__( 'Login popup: welcome message text', 'merchant' ) );
104 }
105 }
106
107 /**
108 * Admin enqueue CSS.
109 *
110 * @return void
111 */
112 public function admin_enqueue_css() {
113 if ( parent::is_module_settings_page() ) {
114 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/login-popup.min.css', array(), MERCHANT_VERSION );
115 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
116 }
117 }
118
119 /**
120 * Admin Enqueue scripts.
121 *
122 * @return void
123 */
124 public function admin_enqueue_scripts() {
125
126 // Register and enqueue the main module script.
127 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/login-popup.min.js', array(), MERCHANT_VERSION, true );
128 }
129
130 /**
131 * Render admin preview
132 *
133 * @param Merchant_Admin_Preview $preview
134 * @param string $module
135 *
136 * @return Merchant_Admin_Preview
137 */
138 public function render_admin_preview( $preview, $module ) {
139 if ( $module === self::MODULE_ID ) {
140 ob_start();
141 self::admin_preview_content();
142 $content = ob_get_clean();
143
144 $preview->set_html( $content );
145
146 $preview->set_text( 'welcome_message_text', '.merchant-login-popup-button', array(
147 array(
148 '{display_name}',
149 ),
150 array(
151 'Bob Jansen',
152 ),
153 )
154 );
155 $preview->set_css( 'login-text-color', '.merchant-login-popup-dropdown', '--merchant-login-text-color' );
156 $preview->set_css( 'login-text-color-hover', '.merchant-login-popup-dropdown', '--merchant-login-text-color-hover' );
157 $preview->set_css( 'dropdown-background-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
158 $preview->set_css( 'dropdown-link-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
159 $preview->set_css( 'dropdown-link-color-hover', '#515151', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
160
161 $preview->set_css( 'popup-width', '.merchant-login-popup', '--merchant-popup-width', 'px' );
162 $preview->set_css( 'popup-title-color', '.merchant-login-popup', '--merchant-popup-title-color' );
163 $preview->set_css( 'popup-text-color', '.merchant-login-popup', '--merchant-popup-text-color' );
164 $preview->set_css( 'popup-icon-color', '.merchant-login-popup', '--merchant-popup-icon-color' );
165 $preview->set_css( 'popup-link-color', '.merchant-login-popup', '--merchant-popup-link-color' );
166 $preview->set_css( 'popup-button-color', '.merchant-login-popup', '--merchant-popup-button-color' );
167 $preview->set_css( 'popup-button-color-hover', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
168 $preview->set_css( 'popup-button-border-color', '.merchant-login-popup', '--merchant-popup-button-border-color' );
169 $preview->set_css( 'popup-button-border-color-hover', '.merchant-login-popup', '--merchant-popup-button-border-color-hover' );
170 $preview->set_css( 'popup-button-background-color', '.merchant-login-popup', '--merchant-popup-button-background-color' );
171 $preview->set_css( 'popup-button-background-color-hover', '.merchant-login-popup', '--merchant-popup-button-background-color-hover' );
172 $preview->set_css( 'popup-link-color-hover', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
173 $preview->set_css( 'popup-background-color', '.merchant-login-popup', '--merchant-popup-background-color' );
174
175 $preview->set_css( 'popup-footer-text-color', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
176 $preview->set_css( 'popup-footer-link-color', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
177 $preview->set_css( 'popup-footer-link-color-hover', '.merchant-login-popup', '--merchant-popup-footer-link-color-hover' );
178 $preview->set_css( 'popup-footer-background-color', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
179 }
180
181 return $preview;
182 }
183
184 /**
185 * Admin preview content.
186 *
187 * @return void
188 */
189 public function admin_preview_content() {
190 $settings = $this->get_module_settings();
191
192 $welcome_text = $settings[ 'welcome_message_text' ];
193 $welcome_text = str_replace(
194 array( '{user_firstname}', '{user_lastname}', '{user_email}', '{user_login}', '{display_name}' ),
195 array( 'Bob', 'Jansen', 'bob@gmail.com', 'Bob Jansen', 'Bob Jansen' ),
196 $welcome_text
197 );
198
199 ?>
200
201 <a href="#" class="merchant-login-popup-button merchant-login-popup-toggle"><?php echo esc_html( $settings[ 'login_link_text' ] ); ?></a>
202
203 <div class="merchant-login-popup">
204 <div class="merchant-login-popup-overlay merchant-login-popup-toggle"></div>
205 <div class="merchant-login-popup-body">
206 <a href="#" class="merchant-login-popup-close merchant-login-popup-toggle">
207 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-cancel' ), merchant_kses_allowed_tags( array(), false ) ); ?>
208 </a>
209 <div class="merchant-login-popup-content">
210 <?php if ( function_exists( 'wc_get_template' ) ) : ?>
211 <?php wc_get_template( 'myaccount/form-login.php' ); ?>
212 <?php endif; ?>
213 </div>
214
215 <?php if ( 'yes' === get_option( 'woocommerce_enable_myaccount_registration' ) ) : ?>
216 <div class="merchant-login-popup-footer">
217 <div class="merchant-show"><?php esc_html_e( 'Not a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Register', 'merchant' ); ?></a></div>
218 <div><?php esc_html_e( 'Already a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Login', 'merchant' ); ?></a></div>
219 </div>
220 <?php endif; ?>
221 </div>
222 </div>
223
224 <?php
225 }
226
227 /**
228 * Custom CSS.
229 *
230 * @return string
231 */
232 public function get_module_custom_css() {
233 $css = '';
234
235 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color' );
236 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color-hover', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color-hover' );
237 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-background-color', '#ffffff', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
238 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color', '#212121', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
239 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color-hover', '#515151', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
240
241 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-width', 400, '.merchant-login-popup', '--merchant-popup-width', 'px' );
242 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-title-color', '#212121', '.merchant-login-popup', '--merchant-popup-title-color' );
243 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-text-color' );
244 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-icon-color', '#212121', '.merchant-login-popup', '--merchant-popup-icon-color' );
245 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-link-color' );
246 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color' );
247 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color-hover', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
248 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-border-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-border-color' );
249 $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' );
250 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-background-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-background-color' );
251 $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' );
252 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color-hover', '#515151', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
253 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-background-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-background-color' );
254
255 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
256 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
257 $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' );
258 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-background-color', '#f5f5f5', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
259
260 return $css;
261 }
262
263 /**
264 * Admin custom CSS.
265 *
266 * @param string $css The custom CSS.
267 * @return string $css The custom CSS.
268 */
269 public function admin_custom_css( $css ) {
270 $css .= $this->get_module_custom_css();
271
272 return $css;
273 }
274 }
275
276 // Initialize the module.
277 add_action( 'init', function() {
278 Merchant_Modules::create_module(new Merchant_Login_Popup());
279 } );
280