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

307 lines 13.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 * 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 * Initialize the module's option group definitions.
33 *
34 * @return array<int, array<string, mixed>> Array of option group arrays.
35 */
36 protected function init_option_groups() {
37 return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
38 }
39
40 /**
41 * Constructor.
42 *
43 */
44 public function __construct() {
45
46 // Module id.
47 $this->module_id = self::MODULE_ID;
48
49 // WooCommerce only.
50 $this->wc_only = true;
51
52 // Parent construct.
53 parent::__construct();
54
55 // Module section.
56 $this->module_section = 'improve-experience';
57
58 // Module default settings.
59 $this->module_default_settings = array(
60 'login_link_text' => esc_html__( 'Login', 'merchant' ),
61 'show_welcome_message' => true,
62 /* Translators: 1. Display name */
63 'welcome_message_text' => sprintf( esc_html__( 'Welcome %s', 'merchant' ), '{display_name}' ),
64 );
65
66 // Module data.
67 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
68
69 // AI prompt examples.
70 $this->ai_examples = array(
71 'blurb' => esc_html__( 'See what AI can do for your login popup, from wording the login link and welcome message to resizing and restyling the popup itself.', 'merchant' ),
72 'prompts' => array(
73 esc_html__( "Explore the abilities WPVibe gives you access to, then change the login popup link text to 'Sign In or Register'", 'merchant' ),
74 esc_html__( 'Check what abilities you have available through WPVibe, then turn off the login popup welcome message shown to logged-in users', 'merchant' ),
75 esc_html__( "Look at your available WPVibe abilities, then set the login popup's welcome message to 'Hi {display_name}, welcome back!'", 'merchant' ),
76 esc_html__( "See what abilities WPVibe exposes, then set the login popup's width to 500px and change its background color to white", 'merchant' ),
77 ),
78 );
79
80 // Module options path.
81 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
82
83 // Is module preview page.
84 if ( is_admin() && parent::is_module_settings_page() ) {
85 self::$is_module_preview = true;
86
87 // Enqueue admin styles.
88 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
89
90 // Enqueue admin scripts.
91 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
92
93 // Localize Script.
94 add_filter( 'merchant_admin_localize_script', array( $this, 'localize_script' ) );
95
96 // Admin preview box.
97 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
98
99 // Custom CSS.
100 // The custom CSS should be added here as well due to ensure preview box works properly.
101 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
102 }
103
104 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
105 // Init translations.
106 $this->init_translations();
107 }
108 }
109
110 /**
111 * Init translations.
112 *
113 * @return void
114 */
115 public function init_translations() {
116 $settings = $this->get_module_settings();
117 if ( ! empty( $settings['login_link_text'] ) ) {
118 Merchant_Translator::register_string( $settings['login_link_text'], esc_html__( 'Login popup: link text', 'merchant' ) );
119 }
120 if ( ! empty( $settings['welcome_message_text'] ) ) {
121 Merchant_Translator::register_string( $settings['welcome_message_text'], esc_html__( 'Login popup: welcome message text', 'merchant' ) );
122 }
123 }
124
125 /**
126 * Admin enqueue CSS.
127 *
128 * @return void
129 */
130 public function admin_enqueue_css() {
131 if ( parent::is_module_settings_page() ) {
132 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/login-popup.min.css', array(), MERCHANT_VERSION );
133 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
134 }
135 }
136
137 /**
138 * Admin Enqueue scripts.
139 *
140 * @return void
141 */
142 public function admin_enqueue_scripts() {
143 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/login-popup.min.js', array(), MERCHANT_VERSION, true );
144 }
145
146 /**
147 * Localize Script.
148 */
149 public function localize_script( $script ) {
150 $script['is_admin'] = is_admin();
151
152 return $script;
153 }
154
155 /**
156 * Render admin preview
157 *
158 * @param Merchant_Admin_Preview $preview
159 * @param string $module
160 *
161 * @return Merchant_Admin_Preview
162 */
163 public function render_admin_preview( $preview, $module ) {
164 if ( $module === self::MODULE_ID ) {
165 ob_start();
166 self::admin_preview_content();
167 $content = ob_get_clean();
168
169 $preview->set_html( $content );
170
171 $preview->set_text( 'welcome_message_text', '.merchant-login-popup-button', array(
172 array(
173 '{display_name}',
174 ),
175 array(
176 'Bob Jansen',
177 ),
178 )
179 );
180 $preview->set_text( 'login_link_text', '.merchant-login-popup-button' );
181
182 $preview->set_css( 'login-text-color', '.merchant-login-popup-dropdown', '--merchant-login-text-color' );
183 $preview->set_css( 'login-text-color-hover', '.merchant-login-popup-dropdown', '--merchant-login-text-color-hover' );
184 $preview->set_css( 'dropdown-background-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
185 $preview->set_css( 'dropdown-link-color', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
186 $preview->set_css( 'dropdown-link-color-hover', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
187
188 $preview->set_css( 'popup-width', '.merchant-login-popup', '--merchant-popup-width', 'px' );
189 $preview->set_css( 'popup-title-color', '.merchant-login-popup', '--merchant-popup-title-color' );
190 $preview->set_css( 'popup-text-color', '.merchant-login-popup', '--merchant-popup-text-color' );
191 $preview->set_css( 'popup-icon-color', '.merchant-login-popup', '--merchant-popup-icon-color' );
192 $preview->set_css( 'popup-link-color', '.merchant-login-popup', '--merchant-popup-link-color' );
193 $preview->set_css( 'popup-button-color', '.merchant-login-popup', '--merchant-popup-button-color' );
194 $preview->set_css( 'popup-button-color-hover', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
195 $preview->set_css( 'popup-button-border-color', '.merchant-login-popup', '--merchant-popup-button-border-color' );
196 $preview->set_css( 'popup-button-border-color-hover', '.merchant-login-popup', '--merchant-popup-button-border-color-hover' );
197 $preview->set_css( 'popup-button-background-color', '.merchant-login-popup', '--merchant-popup-button-background-color' );
198 $preview->set_css( 'popup-button-background-color-hover', '.merchant-login-popup', '--merchant-popup-button-background-color-hover' );
199 $preview->set_css( 'popup-link-color-hover', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
200 $preview->set_css( 'popup-background-color', '.merchant-login-popup', '--merchant-popup-background-color' );
201
202 $preview->set_css( 'popup-footer-text-color', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
203 $preview->set_css( 'popup-footer-link-color', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
204 $preview->set_css( 'popup-footer-link-color-hover', '.merchant-login-popup', '--merchant-popup-footer-link-color-hover' );
205 $preview->set_css( 'popup-footer-background-color', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
206 }
207
208 return $preview;
209 }
210
211 /**
212 * Admin preview content.
213 *
214 * @return void
215 */
216 public function admin_preview_content() {
217 $settings = $this->get_module_settings();
218
219 $welcome_text = $settings[ 'welcome_message_text' ];
220 $welcome_text = str_replace(
221 array( '{user_firstname}', '{user_lastname}', '{user_email}', '{user_login}', '{display_name}' ),
222 array( 'Bob', 'Jansen', 'bob@gmail.com', 'Bob Jansen', 'Bob Jansen' ),
223 $welcome_text
224 );
225
226 ?>
227
228 <a href="#" class="merchant-login-popup-button merchant-login-popup-toggle"><?php echo esc_html( $settings[ 'login_link_text' ] ); ?></a>
229
230 <div class="merchant-login-popup">
231 <div class="merchant-login-popup-overlay merchant-login-popup-toggle"></div>
232 <div class="merchant-login-popup-body">
233 <a href="#" class="merchant-login-popup-close merchant-login-popup-toggle">
234 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-cancel' ), merchant_kses_allowed_tags( array(), false ) ); ?>
235 </a>
236 <div class="merchant-login-popup-content">
237 <?php if ( function_exists( 'wc_get_template' ) ) : ?>
238 <?php wc_get_template( 'myaccount/form-login.php' ); ?>
239 <?php endif; ?>
240 </div>
241
242 <?php if ( 'yes' === get_option( 'woocommerce_enable_myaccount_registration' ) ) : ?>
243 <div class="merchant-login-popup-footer">
244 <div class="merchant-show"><?php esc_html_e( 'Not a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Register', 'merchant' ); ?></a></div>
245 <div><?php esc_html_e( 'Already a member?', 'merchant' ); ?> <a href="#"><?php esc_html_e( 'Login', 'merchant' ); ?></a></div>
246 </div>
247 <?php endif; ?>
248 </div>
249 </div>
250
251 <?php
252 }
253
254 /**
255 * Custom CSS.
256 *
257 * @return string
258 */
259 public function get_module_custom_css() {
260 $css = '';
261
262 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color' );
263 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'login-text-color-hover', '#212121', '.merchant-login-popup-button', '--merchant-login-text-color-hover' );
264 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-background-color', '#ffffff', '.merchant-login-popup-dropdown', '--merchant-dropdown-background-color' );
265 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color', '#212121', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color' );
266 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'dropdown-link-color-hover', '#515151', '.merchant-login-popup-dropdown', '--merchant-dropdown-link-color-hover' );
267
268 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-width', 400, '.merchant-login-popup', '--merchant-popup-width', 'px' );
269 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-title-color', '#212121', '.merchant-login-popup', '--merchant-popup-title-color' );
270 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-text-color' );
271 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-icon-color', '#212121', '.merchant-login-popup', '--merchant-popup-icon-color' );
272 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-link-color' );
273 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color' );
274 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-color-hover', '#ffffff', '.merchant-login-popup', '--merchant-popup-button-color-hover' );
275 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-border-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-border-color' );
276 $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' );
277 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-button-background-color', '#212121', '.merchant-login-popup', '--merchant-popup-button-background-color' );
278 $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' );
279 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-link-color-hover', '#515151', '.merchant-login-popup', '--merchant-popup-link-color-hover' );
280 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-background-color', '#ffffff', '.merchant-login-popup', '--merchant-popup-background-color' );
281
282 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-text-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-text-color' );
283 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-link-color', '#212121', '.merchant-login-popup', '--merchant-popup-footer-link-color' );
284 $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' );
285 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-footer-background-color', '#f5f5f5', '.merchant-login-popup', '--merchant-popup-footer-background-color' );
286
287 return $css;
288 }
289
290 /**
291 * Admin custom CSS.
292 *
293 * @param string $css The custom CSS.
294 * @return string $css The custom CSS.
295 */
296 public function admin_custom_css( $css ) {
297 $css .= $this->get_module_custom_css();
298
299 return $css;
300 }
301 }
302
303 // Initialize the module.
304 add_action( 'init', function() {
305 Merchant_Modules::create_module(new Merchant_Login_Popup());
306 } );
307