@@ -481,7 +481,7 @@ |
||
481 | 481 | } |
482 | 482 | |
483 | 483 | /** SIGN UP - Display the commercial & newsletter form |
484 | - * @return void |
|
484 | + * @return string |
|
485 | 485 | */ |
486 | 486 | function display_commercial_newsletter_form() { |
487 | 487 | $output = ''; |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_account_ctr { |
3 | 3 | /** Define the main directory containing the template for the current plugin |
4 | 4 | * @var string |
@@ -19,50 +19,50 @@ discard block |
||
19 | 19 | $this->template_dir = WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/"; |
20 | 20 | /** Shortcodes **/ |
21 | 21 | // Sign up Display Shortcode |
22 | - add_shortcode( 'wps_signup', array( &$this, 'display_signup' ) ); |
|
22 | + add_shortcode('wps_signup', array(&$this, 'display_signup')); |
|
23 | 23 | // Log in Form Display Shortcode |
24 | - add_shortcode( 'wpshop_login', array( &$this, 'get_login_form')); |
|
24 | + add_shortcode('wpshop_login', array(&$this, 'get_login_form')); |
|
25 | 25 | //Log in first step |
26 | - add_shortcode( 'wps_first_login', array( &$this, 'get_login_first_step')); |
|
26 | + add_shortcode('wps_first_login', array(&$this, 'get_login_first_step')); |
|
27 | 27 | // Forgot password Form |
28 | - add_shortcode( 'wps_forgot_password', array( &$this, 'get_forgot_password_form')); |
|
28 | + add_shortcode('wps_forgot_password', array(&$this, 'get_forgot_password_form')); |
|
29 | 29 | // Renew password form |
30 | - add_shortcode( 'wps_renew_password', array( &$this, 'get_renew_password_form')); |
|
30 | + add_shortcode('wps_renew_password', array(&$this, 'get_renew_password_form')); |
|
31 | 31 | //Account informations |
32 | - add_shortcode( 'wps_account_informations', array($this, 'display_account_informations') ); |
|
32 | + add_shortcode('wps_account_informations', array($this, 'display_account_informations')); |
|
33 | 33 | //Account form |
34 | - add_shortcode( 'wps_account_informations_form', array($this, 'account_informations_form') ); |
|
34 | + add_shortcode('wps_account_informations_form', array($this, 'account_informations_form')); |
|
35 | 35 | |
36 | 36 | /** Ajax Actions **/ |
37 | 37 | // add_action('wap_ajax_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
38 | 38 | // add_action('wap_ajax_nopriv_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
39 | 39 | |
40 | - add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
41 | - add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
40 | + add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request')); |
|
41 | + add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request')); |
|
42 | 42 | |
43 | - add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
44 | - add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
43 | + add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
44 | + add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
45 | 45 | |
46 | - add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
47 | - add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
46 | + add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
47 | + add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
48 | 48 | |
49 | - add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form') ); |
|
50 | - add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form_nopriv') ); |
|
49 | + add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form')); |
|
50 | + add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form_nopriv')); |
|
51 | 51 | |
52 | - add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
53 | - add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
52 | + add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
53 | + add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
54 | 54 | |
55 | - add_action( 'wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations') ); |
|
55 | + add_action('wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations')); |
|
56 | 56 | |
57 | - add_action( 'wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations') ); |
|
57 | + add_action('wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations')); |
|
58 | 58 | |
59 | - add_action( 'wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
60 | - add_action( 'wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
59 | + add_action('wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
60 | + add_action('wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
61 | 61 | |
62 | - add_action( 'wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
63 | - add_action( 'wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
62 | + add_action('wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
63 | + add_action('wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
64 | 64 | |
65 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
65 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,33 +70,33 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function add_scripts() { |
72 | 72 | wp_enqueue_script('jquery'); |
73 | - wp_enqueue_script( 'wps_forgot_password_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_forgot_password.js' ); |
|
74 | - wp_enqueue_script( 'wps_login_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_login.js' ); |
|
75 | - wp_enqueue_script( 'wps_signup_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_signup.js' ); |
|
76 | - wp_enqueue_script( 'wps_account_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_account.js' ); |
|
77 | - wp_enqueue_style( 'wps_account_css', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/css/frontend.css' ); |
|
73 | + wp_enqueue_script('wps_forgot_password_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_forgot_password.js'); |
|
74 | + wp_enqueue_script('wps_login_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_login.js'); |
|
75 | + wp_enqueue_script('wps_signup_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_signup.js'); |
|
76 | + wp_enqueue_script('wps_account_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_account.js'); |
|
77 | + wp_enqueue_style('wps_account_css', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/css/frontend.css'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** LOG IN - Display log in Form **/ |
81 | - function get_login_form( $force_login = false ) { |
|
81 | + function get_login_form($force_login = false) { |
|
82 | 82 | $args = array(); |
83 | - if ( get_current_user_id() != 0 ) { |
|
84 | - return __( 'You are already logged', 'wpshop'); |
|
83 | + if (get_current_user_id() != 0) { |
|
84 | + return __('You are already logged', 'wpshop'); |
|
85 | 85 | } |
86 | 86 | else { |
87 | - $action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
88 | - $key = !empty( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : ''; |
|
89 | - $login = !empty( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : 0; |
|
90 | - if ( !empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login ) { |
|
87 | + $action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
88 | + $key = !empty($_GET['key']) ? sanitize_text_field($_GET['key']) : ''; |
|
89 | + $login = !empty($_GET['login']) ? sanitize_text_field($_GET['login']) : 0; |
|
90 | + if (!empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login) { |
|
91 | 91 | $output = self::get_renew_password_form(); |
92 | 92 | } |
93 | 93 | else { |
94 | 94 | ob_start(); |
95 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form") ); |
|
95 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form")); |
|
96 | 96 | $output = ob_get_contents(); |
97 | 97 | ob_end_clean(); |
98 | - if ( !$force_login ) { |
|
99 | - $output .= do_shortcode( '[wps_signup]' ); |
|
98 | + if (!$force_login) { |
|
99 | + $output .= do_shortcode('[wps_signup]'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | return $output; |
@@ -106,53 +106,53 @@ discard block |
||
106 | 106 | /** LOG IN - AJAX - Action to connect **/ |
107 | 107 | function control_login_form_request() { |
108 | 108 | |
109 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
109 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
110 | 110 | |
111 | - if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) |
|
111 | + if (!wp_verify_nonce($_wpnonce, 'control_login_form_request')) |
|
112 | 112 | wp_die(); |
113 | 113 | |
114 | 114 | $result = ''; |
115 | 115 | $status = false; |
116 | - $origin = sanitize_text_field( $_POST['wps-checking-origin'] ); |
|
117 | - $wps_login_user_login = !empty( $_POST['wps_login_user_login'] ) ? sanitize_text_field( $_POST['wps_login_user_login' ] ) : ''; |
|
118 | - $wps_login_password = !empty( $_POST['wps_login_password'] ) ? sanitize_text_field( $_POST['wps_login_password' ] ) : ''; |
|
119 | - $page_account_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id') ); |
|
120 | - if ( !empty($wps_login_user_login) && !empty($wps_login_password) ) { |
|
116 | + $origin = sanitize_text_field($_POST['wps-checking-origin']); |
|
117 | + $wps_login_user_login = !empty($_POST['wps_login_user_login']) ? sanitize_text_field($_POST['wps_login_user_login']) : ''; |
|
118 | + $wps_login_password = !empty($_POST['wps_login_password']) ? sanitize_text_field($_POST['wps_login_password']) : ''; |
|
119 | + $page_account_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
120 | + if (!empty($wps_login_user_login) && !empty($wps_login_password)) { |
|
121 | 121 | $creds = array(); |
122 | 122 | // Test if an user exist with this login |
123 | - $user_checking = get_user_by( 'login', $wps_login_user_login ); |
|
124 | - if( !empty($user_checking) ) { |
|
123 | + $user_checking = get_user_by('login', $wps_login_user_login); |
|
124 | + if (!empty($user_checking)) { |
|
125 | 125 | $creds['user_login'] = $wps_login_user_login; |
126 | 126 | } |
127 | 127 | else { |
128 | - if ( is_email($wps_login_user_login) ) { |
|
129 | - $user_checking = get_user_by( 'email', $wps_login_user_login ); |
|
128 | + if (is_email($wps_login_user_login)) { |
|
129 | + $user_checking = get_user_by('email', $wps_login_user_login); |
|
130 | 130 | $creds['user_login'] = $user_checking->user_login; |
131 | 131 | } |
132 | 132 | } |
133 | - $creds['user_password'] = wpshop_tools::varSanitizer( $_POST['wps_login_password'] ); |
|
134 | - $creds['remember'] = !empty( $_POST['wps_login_remember_me'] ) ? (int) $_POST['wps_login_remember_me'] : false; |
|
135 | - $user = wp_signon( $creds, false ); |
|
136 | - if ( is_wp_error($user) ) { |
|
137 | - $result = '<div class="wps-alert-error">' .__('Connexion error', 'wpshop'). '</div>'; |
|
133 | + $creds['user_password'] = wpshop_tools::varSanitizer($_POST['wps_login_password']); |
|
134 | + $creds['remember'] = !empty($_POST['wps_login_remember_me']) ? (int)$_POST['wps_login_remember_me'] : false; |
|
135 | + $user = wp_signon($creds, false); |
|
136 | + if (is_wp_error($user)) { |
|
137 | + $result = '<div class="wps-alert-error">' . __('Connexion error', 'wpshop') . '</div>'; |
|
138 | 138 | } |
139 | 139 | else { |
140 | - $permalink_option = get_option( 'permalink_structure' ); |
|
141 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
142 | - if( $origin == $page_account_id ) { |
|
143 | - $result = get_permalink( $page_account_id ); |
|
140 | + $permalink_option = get_option('permalink_structure'); |
|
141 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
142 | + if ($origin == $page_account_id) { |
|
143 | + $result = get_permalink($page_account_id); |
|
144 | 144 | } |
145 | 145 | else { |
146 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
146 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
147 | 147 | } |
148 | 148 | $status = true; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | else { |
152 | - $result = '<div class="wps-alert-error">' .__('E-Mail and Password are required', 'wpshop'). '</div>'; |
|
152 | + $result = '<div class="wps-alert-error">' . __('E-Mail and Password are required', 'wpshop') . '</div>'; |
|
153 | 153 | } |
154 | 154 | |
155 | - echo json_encode( array( $status, $result) ); |
|
155 | + echo json_encode(array($status, $result)); |
|
156 | 156 | die(); |
157 | 157 | } |
158 | 158 | |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | * LOG IN - AJAX - Display log in Form in Ajax |
161 | 161 | */ |
162 | 162 | function wps_ajax_get_login_form_interface() { |
163 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
163 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
164 | 164 | |
165 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) |
|
165 | + if (!wp_verify_nonce($_wpnonce, 'wps_ajax_get_login_form_interface')) |
|
166 | 166 | wp_die(); |
167 | 167 | |
168 | - $response = array( 'status' => true, 'response' => self::get_login_form() ); |
|
169 | - echo json_encode( $response ); |
|
168 | + $response = array('status' => true, 'response' => self::get_login_form()); |
|
169 | + echo json_encode($response); |
|
170 | 170 | die(); |
171 | 171 | } |
172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | function get_login_first_step() { |
175 | 175 | $output = ''; |
176 | 176 | ob_start(); |
177 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "login/login-form", "first") ); |
|
177 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form", "first")); |
|
178 | 178 | $output .= ob_get_contents(); |
179 | 179 | ob_end_clean(); |
180 | 180 | return $output; |
@@ -184,39 +184,39 @@ discard block |
||
184 | 184 | * LOG IN - First Step log in request |
185 | 185 | */ |
186 | 186 | function wps_login_first_request() { |
187 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
187 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
188 | 188 | |
189 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) |
|
189 | + if (!wp_verify_nonce($_wpnonce, 'wps_login_first_request')) |
|
190 | 190 | wp_die(); |
191 | 191 | |
192 | 192 | $status = false; $login_action = false; $response = ''; |
193 | - $user_email = ( !empty($_POST['email_address']) ) ? wpshop_tools::varSanitizer( $_POST['email_address'] ) : null; |
|
194 | - if ( !empty($user_email) ) { |
|
193 | + $user_email = (!empty($_POST['email_address'])) ? wpshop_tools::varSanitizer($_POST['email_address']) : null; |
|
194 | + if (!empty($user_email)) { |
|
195 | 195 | $status = true; |
196 | 196 | /** Check if a user exist with it's email **/ |
197 | - $checking_user = get_user_by( 'login', $user_email); |
|
198 | - if ( !empty($checking_user) ) { |
|
197 | + $checking_user = get_user_by('login', $user_email); |
|
198 | + if (!empty($checking_user)) { |
|
199 | 199 | $login_action = true; |
200 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
200 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
201 | 201 | $response = $user_firstname; |
202 | 202 | } |
203 | 203 | else { |
204 | - $checking_user = get_user_by( 'email', $user_email); |
|
205 | - if ( !empty( $checking_user ) ) { |
|
204 | + $checking_user = get_user_by('email', $user_email); |
|
205 | + if (!empty($checking_user)) { |
|
206 | 206 | $login_action = true; |
207 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
207 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
208 | 208 | $response = $user_firstname; |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - if( !$login_action && is_email($user_email) ) { |
|
212 | + if (!$login_action && is_email($user_email)) { |
|
213 | 213 | $response = $user_email; |
214 | 214 | } |
215 | 215 | } |
216 | 216 | else { |
217 | - $response = '<div class="wps-alert-error">' .__( 'An e-mail address is required', 'wpshop' ). '</div>'; |
|
217 | + $response = '<div class="wps-alert-error">' . __('An e-mail address is required', 'wpshop') . '</div>'; |
|
218 | 218 | } |
219 | - echo json_encode( array( 'status'=> $status, 'response' => $response, 'login_action' => $login_action) ); |
|
219 | + echo json_encode(array('status'=> $status, 'response' => $response, 'login_action' => $login_action)); |
|
220 | 220 | die(); |
221 | 221 | } |
222 | 222 | |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | */ |
226 | 226 | function get_forgot_password_form() { |
227 | 227 | $output = ''; |
228 | - if ( get_current_user_id() == 0 ) { |
|
228 | + if (get_current_user_id() == 0) { |
|
229 | 229 | ob_start(); |
230 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password") ); |
|
230 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password")); |
|
231 | 231 | $output = ob_get_contents(); |
232 | 232 | ob_end_clean(); |
233 | 233 | } |
@@ -238,16 +238,16 @@ discard block |
||
238 | 238 | * FORGOT PASSWORD - AJAX - Fill the forgot password modal |
239 | 239 | */ |
240 | 240 | function wps_fill_forgot_password_modal() { |
241 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
241 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
242 | 242 | |
243 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) |
|
243 | + if (!wp_verify_nonce($_wpnonce, 'wps_fill_forgot_password_modal')) |
|
244 | 244 | wp_die(); |
245 | 245 | |
246 | 246 | $status = false; $title = $content = ''; |
247 | - $title = __( 'Forgot password', 'wpshop' ); |
|
247 | + $title = __('Forgot password', 'wpshop'); |
|
248 | 248 | $content = do_shortcode('[wps_forgot_password]'); |
249 | 249 | $status = true; |
250 | - echo json_encode( array('status' => $status, 'title' => $title, 'content' => $content) ); |
|
250 | + echo json_encode(array('status' => $status, 'title' => $title, 'content' => $content)); |
|
251 | 251 | wp_die(); |
252 | 252 | } |
253 | 253 | |
@@ -255,48 +255,48 @@ discard block |
||
255 | 255 | * FORGOT PASSWORD- AJAX - Forgot Password Request |
256 | 256 | */ |
257 | 257 | function wps_forgot_password_request() { |
258 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
258 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
259 | 259 | |
260 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) |
|
260 | + if (!wp_verify_nonce($_wpnonce, 'wps_forgot_password_request')) |
|
261 | 261 | wp_die(); |
262 | 262 | |
263 | 263 | global $wpdb; |
264 | 264 | $status = false; $result = ''; |
265 | - $user_login = ( !empty( $_POST['wps_user_login']) ) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
266 | - if ( !empty($user_login) ) { |
|
265 | + $user_login = (!empty($_POST['wps_user_login'])) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
266 | + if (!empty($user_login)) { |
|
267 | 267 | $existing_user = false; |
268 | 268 | $key_for_update = 'user_login'; |
269 | 269 | $exist_user = get_user_by('login', $user_login); |
270 | - if( !empty($exist_user) ) { |
|
270 | + if (!empty($exist_user)) { |
|
271 | 271 | $existing_user = true; |
272 | 272 | } |
273 | 273 | else { |
274 | 274 | $exist_user = get_user_by('email', $user_login); |
275 | 275 | $key_for_update = 'user_email'; |
276 | - if ( !empty($exist_user) ) { |
|
276 | + if (!empty($exist_user)) { |
|
277 | 277 | $existing_user = true; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( $existing_user ) { |
|
281 | + if ($existing_user) { |
|
282 | 282 | $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE $key_for_update = %s", $user_login)); |
283 | - if ( empty($key) ) { |
|
283 | + if (empty($key)) { |
|
284 | 284 | $key = wp_generate_password(20, false); |
285 | 285 | $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); |
286 | 286 | } |
287 | 287 | $this->send_forgot_password_email($key, $user_login, $exist_user); |
288 | - $result = '<div class="wps-alert-info">' .__('An e-mail with an password renew link has been sent to you', 'wpshop'). '</div>'; |
|
288 | + $result = '<div class="wps-alert-info">' . __('An e-mail with an password renew link has been sent to you', 'wpshop') . '</div>'; |
|
289 | 289 | $status = true; |
290 | 290 | } |
291 | 291 | else { |
292 | - $result = '<div class="wps-alert-error">' .__('No customer account corresponds to this email', 'wpshop'). '</div>'; |
|
292 | + $result = '<div class="wps-alert-error">' . __('No customer account corresponds to this email', 'wpshop') . '</div>'; |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | else { |
296 | - $result = '<div class="wps-alert-error">' .__('Please fill the required field', 'wpshop'). '</div>'; |
|
296 | + $result = '<div class="wps-alert-error">' . __('Please fill the required field', 'wpshop') . '</div>'; |
|
297 | 297 | } |
298 | - $response = array( $status, $result ); |
|
299 | - echo json_encode( $response ); |
|
298 | + $response = array($status, $result); |
|
299 | + echo json_encode($response); |
|
300 | 300 | die(); |
301 | 301 | } |
302 | 302 | |
@@ -305,67 +305,67 @@ discard block |
||
305 | 305 | * @param string $key |
306 | 306 | * @param string $user_login |
307 | 307 | */ |
308 | - function send_forgot_password_email($key, $user_login, $exist_user){ |
|
308 | + function send_forgot_password_email($key, $user_login, $exist_user) { |
|
309 | 309 | $user_data = $exist_user->data; |
310 | 310 | $email = $user_data->user_email; |
311 | 311 | $wps_message = new wps_message_ctr(); |
312 | - $first_name = get_user_meta( $user_data->ID, 'first_name', true ); |
|
313 | - $last_name = get_user_meta( $user_data->ID, 'last_name', true ); |
|
314 | - $permalink_option = get_option( 'permalink_structure' ); |
|
315 | - $link = '<a href="' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ).( (!empty($permalink_option)) ? '?' : '&').'order_step=2&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '">' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ). '&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '</a>'; |
|
316 | - if( !empty($key) && !empty( $user_login ) ) { |
|
312 | + $first_name = get_user_meta($user_data->ID, 'first_name', true); |
|
313 | + $last_name = get_user_meta($user_data->ID, 'last_name', true); |
|
314 | + $permalink_option = get_option('permalink_structure'); |
|
315 | + $link = '<a href="' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '">' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . '&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '</a>'; |
|
316 | + if (!empty($key) && !empty($user_login)) { |
|
317 | 317 | $wps_message->wpshop_prepared_email($email, |
318 | 318 | 'WPSHOP_FORGOT_PASSWORD_MESSAGE', |
319 | - array( 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
319 | + array('customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
320 | 320 | ); |
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | /** FORGOT PASSWORD - AJAX - Make renew password action **/ |
325 | 325 | function wps_forgot_password_renew() { |
326 | - check_ajax_referer( 'wps_forgot_password_renew' ); |
|
326 | + check_ajax_referer('wps_forgot_password_renew'); |
|
327 | 327 | |
328 | 328 | global $wpdb; |
329 | 329 | $status = false; $result = $form = ''; |
330 | - $password = ( !empty( $_POST['pass1']) ) ? wpshop_tools::varSanitizer( $_POST['pass1'] ) : null; |
|
331 | - $confirm_password = ( !empty( $_POST['pass2']) ) ? wpshop_tools::varSanitizer( $_POST['pass2'] ) : null; |
|
332 | - $activation_key = ( !empty( $_POST['activation_key']) ) ? wpshop_tools::varSanitizer( $_POST['activation_key'] ) : null; |
|
333 | - $login = ( !empty( $_POST['user_login']) ) ? wpshop_tools::varSanitizer( $_POST['user_login'] ) : null; |
|
334 | - if ( !empty($password) && !empty($confirm_password) && $confirm_password == $password ) { |
|
335 | - if ( !empty($activation_key) && !empty($login) ) { |
|
330 | + $password = (!empty($_POST['pass1'])) ? wpshop_tools::varSanitizer($_POST['pass1']) : null; |
|
331 | + $confirm_password = (!empty($_POST['pass2'])) ? wpshop_tools::varSanitizer($_POST['pass2']) : null; |
|
332 | + $activation_key = (!empty($_POST['activation_key'])) ? wpshop_tools::varSanitizer($_POST['activation_key']) : null; |
|
333 | + $login = (!empty($_POST['user_login'])) ? wpshop_tools::varSanitizer($_POST['user_login']) : null; |
|
334 | + if (!empty($password) && !empty($confirm_password) && $confirm_password == $password) { |
|
335 | + if (!empty($activation_key) && !empty($login)) { |
|
336 | 336 | $existing_user = false; |
337 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login ) ); |
|
338 | - if( !empty($user) ) { |
|
337 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login)); |
|
338 | + if (!empty($user)) { |
|
339 | 339 | $existing_user = true; |
340 | 340 | } |
341 | 341 | else { |
342 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login ) ); |
|
343 | - if( !empty($user) ) { |
|
342 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login)); |
|
343 | + if (!empty($user)) { |
|
344 | 344 | $existing_user = true; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | - if ( $existing_user ){ |
|
348 | + if ($existing_user) { |
|
349 | 349 | wp_set_password($password, $user->ID); |
350 | 350 | wp_password_change_notification($user); |
351 | 351 | $status = true; |
352 | - $result = '<div class="wps-alert-success">' .__('Your password has been updated', 'wpshop'). '. <a href="#" id="display_connexion_form"> ' .__('Connect you', 'wpshop').' !</a></div>'; |
|
353 | - $form = self::get_login_form( true ); |
|
352 | + $result = '<div class="wps-alert-success">' . __('Your password has been updated', 'wpshop') . '. <a href="#" id="display_connexion_form"> ' . __('Connect you', 'wpshop') . ' !</a></div>'; |
|
353 | + $form = self::get_login_form(true); |
|
354 | 354 | } |
355 | 355 | else { |
356 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
356 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | else { |
360 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
360 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | else { |
364 | - $result = '<div class="wps-alert-error">' .__('Password and confirmation password are differents', 'wpshop'). '</div>'; |
|
364 | + $result = '<div class="wps-alert-error">' . __('Password and confirmation password are differents', 'wpshop') . '</div>'; |
|
365 | 365 | } |
366 | 366 | |
367 | - $response = array( $status, $result, $form ); |
|
368 | - echo json_encode( $response); |
|
367 | + $response = array($status, $result, $form); |
|
368 | + echo json_encode($response); |
|
369 | 369 | die(); |
370 | 370 | } |
371 | 371 | |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | * @return string |
375 | 375 | */ |
376 | 376 | function get_renew_password_form() { |
377 | - if ( get_current_user_id() == 0 ) { |
|
377 | + if (get_current_user_id() == 0) { |
|
378 | 378 | ob_start(); |
379 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "forgot-password/password-renew") ); |
|
379 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/password-renew")); |
|
380 | 380 | $output = ob_get_contents(); |
381 | 381 | ob_end_clean(); |
382 | 382 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | |
386 | 386 | /** FORGOT PASSWORD - AJAX - Get Forgot Password form **/ |
387 | 387 | function wps_ajax_get_forgot_password_form() { |
388 | - echo json_encode( array(self::get_forgot_password_form() ) ); |
|
388 | + echo json_encode(array(self::get_forgot_password_form())); |
|
389 | 389 | die(); |
390 | 390 | } |
391 | 391 | |
@@ -393,29 +393,29 @@ discard block |
||
393 | 393 | * SIGN UP - Display Sign up form |
394 | 394 | * @return string |
395 | 395 | */ |
396 | - function display_signup( $args = array() ) { |
|
396 | + function display_signup($args = array()) { |
|
397 | 397 | global $wpdb; |
398 | 398 | $output = ''; |
399 | - if ( get_current_user_id() == 0 || !empty($args) ) { |
|
399 | + if (get_current_user_id() == 0 || !empty($args)) { |
|
400 | 400 | $fields_to_output = $signup_fields = array(); |
401 | 401 | |
402 | - $password_attribute = $signup_form_attributes = array(); |
|
402 | + $password_attribute = $signup_form_attributes = array(); |
|
403 | 403 | |
404 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
404 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
405 | 405 | |
406 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
407 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
406 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
407 | + $customer_entity_id = $wpdb->get_var($query); |
|
408 | 408 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
409 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
410 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid' ); |
|
411 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
412 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
413 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
409 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
410 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
411 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
412 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
413 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
414 | 414 | $signup_fields[] = $attribute; |
415 | 415 | } |
416 | 416 | } |
417 | 417 | ob_start(); |
418 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "signup/signup") ); |
|
418 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup")); |
|
419 | 419 | $output = ob_get_contents(); |
420 | 420 | ob_end_clean(); |
421 | 421 | } |
@@ -423,119 +423,119 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | function wps_save_signup_form_nopriv() { |
426 | - $this->wps_save_signup_form( true ); |
|
426 | + $this->wps_save_signup_form(true); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
430 | 430 | * SIGN UP - Save sign up form |
431 | 431 | */ |
432 | - function wps_save_signup_form( $connect = false ) { |
|
433 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
432 | + function wps_save_signup_form($connect = false) { |
|
433 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
434 | 434 | |
435 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) |
|
435 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_signup_form')) |
|
436 | 436 | wp_die(); |
437 | 437 | |
438 | 438 | global $wpdb, $wpshop; |
439 | - $user_id = ( !empty( $_POST['wps_sign_up_request_from_admin'] ) ) ? (int) $_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
439 | + $user_id = (!empty($_POST['wps_sign_up_request_from_admin'])) ? (int)$_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
440 | 440 | $wps_message = new wps_message_ctr(); |
441 | 441 | $status = $account_creation = false; $result = ''; |
442 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
443 | - $attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array(); |
|
444 | - $element_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
445 | - if ( !empty( $element_id) ){ |
|
446 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
447 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
448 | - if ( !empty($attribute_set_id) ){ |
|
449 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
450 | - foreach ( $group as $attribute_sets ) { |
|
451 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
452 | - if( !empty($user_id) ) { |
|
453 | - foreach( $attribute_set_field['content'] as $attribute_code => $att_def ) { |
|
454 | - if( $attribute_code != 'account_user_email' ) { |
|
442 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
443 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
444 | + $element_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
445 | + if (!empty($element_id)) { |
|
446 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
447 | + $attribute_set_id = $wpdb->get_var($query); |
|
448 | + if (!empty($attribute_set_id)) { |
|
449 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
450 | + foreach ($group as $attribute_sets) { |
|
451 | + foreach ($attribute_sets as $attribute_set_field) { |
|
452 | + if (!empty($user_id)) { |
|
453 | + foreach ($attribute_set_field['content'] as $attribute_code => $att_def) { |
|
454 | + if ($attribute_code != 'account_user_email') { |
|
455 | 455 | $attribute_set_field['content'][$attribute_code]['required'] = 'no'; |
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
459 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute ); |
|
459 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute); |
|
460 | 460 | } |
461 | - if ( empty($wpshop->errors) ) { |
|
462 | - $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field( $attribute['varchar']['user_login'] ) : sanitize_email( $attribute['varchar']['user_email'] ); |
|
463 | - $user_pass = ( !empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation']) ) ? sanitize_text_field( $attribute['varchar']['user_pass'] ) : wp_generate_password( 12, false ); |
|
461 | + if (empty($wpshop->errors)) { |
|
462 | + $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field($attribute['varchar']['user_login']) : sanitize_email($attribute['varchar']['user_email']); |
|
463 | + $user_pass = (!empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation'])) ? sanitize_text_field($attribute['varchar']['user_pass']) : wp_generate_password(12, false); |
|
464 | 464 | |
465 | - if ( $user_id == 0 ) { |
|
466 | - $user_id = wp_create_user($user_name, $user_pass, sanitize_email( $attribute['varchar']['user_email'] ) ); |
|
467 | - if ( !is_object( $user_id) ) { |
|
465 | + if ($user_id == 0) { |
|
466 | + $user_id = wp_create_user($user_name, $user_pass, sanitize_email($attribute['varchar']['user_email'])); |
|
467 | + if (!is_object($user_id)) { |
|
468 | 468 | $account_creation = true; |
469 | 469 | /** Update newsletter user preferences **/ |
470 | 470 | $newsletter_preferences = array(); |
471 | - $newsletters_site = !empty( $_POST['newsletters_site'] ) ? (bool) $_POST['newsletters_site'] : false; |
|
472 | - if( $newsletters_site ) { |
|
471 | + $newsletters_site = !empty($_POST['newsletters_site']) ? (bool)$_POST['newsletters_site'] : false; |
|
472 | + if ($newsletters_site) { |
|
473 | 473 | $newsletter_preferences['newsletters_site'] = 1; |
474 | 474 | } |
475 | - $newsletters_site_partners = !empty( $_POST['newsletters_site_partners'] ) ? (bool) $_POST['newsletters_site_partners'] : false; |
|
476 | - if( $newsletters_site_partners ) { |
|
475 | + $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? (bool)$_POST['newsletters_site_partners'] : false; |
|
476 | + if ($newsletters_site_partners) { |
|
477 | 477 | $newsletter_preferences['newsletters_site_partners'] = 1; |
478 | 478 | } |
479 | 479 | |
480 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
480 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - $customer_entity_request = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
485 | - $customer_post_ID = $wpdb->get_var( $customer_entity_request ); |
|
484 | + $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
485 | + $customer_post_ID = $wpdb->get_var($customer_entity_request); |
|
486 | 486 | |
487 | - if( !empty( $attribute ) ) { |
|
487 | + if (!empty($attribute)) { |
|
488 | 488 | $user_info = $address_forms = $all_addresses_form = array(); |
489 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
490 | - foreach( $attribute as $type => $attributes ) { |
|
491 | - if( !empty( $billing_option['integrate_into_register_form'] ) && $billing_option['integrate_into_register_form'] == 'yes' && ctype_digit( (string) $type ) ) { |
|
489 | + $billing_option = get_option('wpshop_billing_address'); |
|
490 | + foreach ($attribute as $type => $attributes) { |
|
491 | + if (!empty($billing_option['integrate_into_register_form']) && $billing_option['integrate_into_register_form'] == 'yes' && ctype_digit((string)$type)) { |
|
492 | 492 | //wps_address::save_address_infos( (int) $type ); |
493 | - foreach( $attributes as $sub_type => $sub_attributes ) { |
|
494 | - if( !is_array( $sub_attributes ) ) { |
|
495 | - $address_forms[$type][$sub_type] = sanitize_text_field( $sub_attributes ); |
|
493 | + foreach ($attributes as $sub_type => $sub_attributes) { |
|
494 | + if (!is_array($sub_attributes)) { |
|
495 | + $address_forms[$type][$sub_type] = sanitize_text_field($sub_attributes); |
|
496 | 496 | continue; |
497 | 497 | } |
498 | - foreach( $sub_attributes as $sub_meta => $sub_attribute_value ) { |
|
499 | - $address_forms[$type][$sub_type][$sub_meta] = sanitize_text_field( $sub_attribute_value ); |
|
498 | + foreach ($sub_attributes as $sub_meta => $sub_attribute_value) { |
|
499 | + $address_forms[$type][$sub_type][$sub_meta] = sanitize_text_field($sub_attribute_value); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | } else { |
503 | - foreach( $attributes as $meta => $attribute_value ) { |
|
504 | - $user_info[$meta] = sanitize_text_field( $attribute_value ); |
|
505 | - if( !empty( $billing_option['integrate_into_register_form'] ) && $billing_option['integrate_into_register_form'] == 'yes' && isset( $billing_option['integrate_into_register_form_matching_field'], $billing_option['integrate_into_register_form_matching_field'][$meta] ) ) { |
|
503 | + foreach ($attributes as $meta => $attribute_value) { |
|
504 | + $user_info[$meta] = sanitize_text_field($attribute_value); |
|
505 | + if (!empty($billing_option['integrate_into_register_form']) && $billing_option['integrate_into_register_form'] == 'yes' && isset($billing_option['integrate_into_register_form_matching_field'], $billing_option['integrate_into_register_form_matching_field'][$meta])) { |
|
506 | 506 | $all_addresses_form[$type][$meta] = $user_info[$meta]; |
507 | 507 | } |
508 | 508 | } |
509 | 509 | } |
510 | 510 | } |
511 | - wps_customer_ctr::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
512 | - foreach( $address_forms as $type_of_form => $address_form ) { |
|
513 | - $address_form = array_merge_recursive( $all_addresses_form, $address_form ); |
|
514 | - wps_address::save_address_infos( (int) $type_of_form, 0, array( 'type_of_form' => (int) $type_of_form, 'attribute' => array( $type_of_form => $address_form ) ), $customer_post_ID ); |
|
511 | + wps_customer_ctr::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
512 | + foreach ($address_forms as $type_of_form => $address_form) { |
|
513 | + $address_form = array_merge_recursive($all_addresses_form, $address_form); |
|
514 | + wps_address::save_address_infos((int)$type_of_form, 0, array('type_of_form' => (int)$type_of_form, 'attribute' => array($type_of_form => $address_form)), $customer_post_ID); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | - if ( !empty( $_SESSION ) && !empty( $_SESSION[ 'cart' ] ) ) { |
|
519 | - $permalink_option = get_option( 'permalink_structure' ); |
|
520 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' )); |
|
521 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
518 | + if (!empty($_SESSION) && !empty($_SESSION['cart'])) { |
|
519 | + $permalink_option = get_option('permalink_structure'); |
|
520 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
521 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
522 | 522 | } |
523 | 523 | else { |
524 | - $account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' )); |
|
525 | - $result = get_permalink( $account_page_id ); |
|
524 | + $account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
525 | + $result = get_permalink($account_page_id); |
|
526 | 526 | } |
527 | 527 | $status = true; |
528 | 528 | |
529 | - if ( $account_creation && !empty( $user_id ) && $connect ) { |
|
529 | + if ($account_creation && !empty($user_id) && $connect) { |
|
530 | 530 | $secure_cookie = is_ssl() ? true : false; |
531 | - wp_set_auth_cookie( $user_id, true, $secure_cookie ); |
|
531 | + wp_set_auth_cookie($user_id, true, $secure_cookie); |
|
532 | 532 | } |
533 | - $wps_message->wpshop_prepared_email( sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => ( !empty($attribute['varchar']['first_name']) ) ? sanitize_text_field( $attribute['varchar']['first_name'] ) : '', 'customer_last_name' => ( !empty($attribute['varchar']['last_name']) ) ? sanitize_text_field( $attribute['varchar']['last_name'] ) : '', 'customer_user_email' => ( !empty($attribute['varchar']['user_email']) ) ? sanitize_email( $attribute['varchar']['user_email'] ) : '') ); |
|
533 | + $wps_message->wpshop_prepared_email(sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => (!empty($attribute['varchar']['first_name'])) ? sanitize_text_field($attribute['varchar']['first_name']) : '', 'customer_last_name' => (!empty($attribute['varchar']['last_name'])) ? sanitize_text_field($attribute['varchar']['last_name']) : '', 'customer_user_email' => (!empty($attribute['varchar']['user_email'])) ? sanitize_email($attribute['varchar']['user_email']) : '')); |
|
534 | 534 | |
535 | 535 | } else { |
536 | - $result = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
537 | - foreach( $wpshop->errors as $error ){ |
|
538 | - $result .= '<li>' .$error. '</li>'; |
|
536 | + $result = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
537 | + foreach ($wpshop->errors as $error) { |
|
538 | + $result .= '<li>' . $error . '</li>'; |
|
539 | 539 | } |
540 | 540 | $result .= '</div>'; |
541 | 541 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
547 | - wp_die( json_encode( array( $status, $result, $user_id ) ) ); |
|
547 | + wp_die(json_encode(array($status, $result, $user_id))); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** SIGN UP - Display the commercial & newsletter form |
@@ -552,10 +552,10 @@ discard block |
||
552 | 552 | */ |
553 | 553 | function display_commercial_newsletter_form() { |
554 | 554 | $output = ''; |
555 | - $user_preferences = get_user_meta( get_current_user_id(), 'user_preferences', true ); |
|
556 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
555 | + $user_preferences = get_user_meta(get_current_user_id(), 'user_preferences', true); |
|
556 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
557 | 557 | ob_start(); |
558 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter") ); |
|
558 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter")); |
|
559 | 559 | $output = ob_get_contents(); |
560 | 560 | ob_end_clean(); |
561 | 561 | |
@@ -566,88 +566,88 @@ discard block |
||
566 | 566 | * ACCOUNT - Display Account informations |
567 | 567 | * @return string |
568 | 568 | */ |
569 | - function display_account_informations( $customer_id = '', $force_edition_form = false, $customer_link = false ) { |
|
569 | + function display_account_informations($customer_id = '', $force_edition_form = false, $customer_link = false) { |
|
570 | 570 | global $wpdb; |
571 | 571 | $output = $attributes_sections_tpl = $attribute_details = ''; |
572 | - $is_from_admin = ( !empty($customer_id) ) ? true : false; |
|
573 | - $customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id(); |
|
574 | - if( $customer_id != 0 ) { |
|
572 | + $is_from_admin = (!empty($customer_id)) ? true : false; |
|
573 | + $customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
574 | + if ($customer_id != 0) { |
|
575 | 575 | $screen = get_current_screen(); |
576 | - if( ( is_admin() && isset( $screen ) && is_object( $screen ) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) || $force_edition_form ) { |
|
577 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
578 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
579 | - $cid = $wpdb->get_var( $query ); |
|
576 | + if ((is_admin() && isset($screen) && is_object($screen) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) || $force_edition_form) { |
|
577 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
578 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
579 | + $cid = $wpdb->get_var($query); |
|
580 | 580 | |
581 | 581 | $fields_to_output = $signup_fields = array(); |
582 | 582 | |
583 | - $password_attribute = $signup_form_attributes = array(); |
|
583 | + $password_attribute = $signup_form_attributes = array(); |
|
584 | 584 | |
585 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
585 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
586 | 586 | |
587 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
588 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
587 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
588 | + $customer_entity_id = $wpdb->get_var($query); |
|
589 | 589 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
590 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
591 | - $query = $wpdb->prepare('SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
592 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
593 | - foreach( $customer_attributes_sections as $k => $attributes_section ) { |
|
590 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
591 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
592 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
593 | + foreach ($customer_attributes_sections as $k => $attributes_section) { |
|
594 | 594 | $signup_fields[$attributes_section->name] = array(); |
595 | - if ( !empty( $account_attributes[$attributes_section->id] ) ) { |
|
596 | - foreach( $account_attributes[$attributes_section->id]['attribut'] as $attribute ) { |
|
595 | + if (!empty($account_attributes[$attributes_section->id])) { |
|
596 | + foreach ($account_attributes[$attributes_section->id]['attribut'] as $attribute) { |
|
597 | 597 | $signup_fields[$attributes_section->name][] = $attribute; |
598 | 598 | } |
599 | 599 | } |
600 | 600 | } |
601 | 601 | ob_start(); |
602 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"backend", "customer-informations/customer_informations_form") ); |
|
602 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "backend", "customer-informations/customer_informations_form")); |
|
603 | 603 | $output = ob_get_contents(); |
604 | 604 | ob_end_clean(); |
605 | 605 | } else { |
606 | - $customer_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
607 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
608 | - $cid = $wpdb->get_var( $query ); |
|
609 | - |
|
610 | - if( !empty($customer_entity_id) ) { |
|
611 | - $query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes' ); |
|
612 | - $attributes_sets = $wpdb->get_results( $query ); |
|
613 | - foreach( $attributes_sets as $attributes_set ) { |
|
614 | - if( !empty($attributes_set->id) ) { |
|
615 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_GROUP. ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
616 | - $attributes_sections = $wpdb->get_results( $query ); |
|
617 | - |
|
618 | - if( !empty($attributes_sections) ) { |
|
619 | - foreach( $attributes_sections as $attributes_section ) { |
|
620 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
621 | - $attributes_details = $wpdb->get_results( $query ); |
|
622 | - |
|
623 | - foreach( $attributes_details as $attributes_detail ) { |
|
624 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid' ); |
|
625 | - $attribute_def = $wpdb->get_row( $query ); |
|
626 | - |
|
627 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower($attribute_def->data_type). ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid ); |
|
628 | - $attribute_value = $wpdb->get_var( $query ); |
|
606 | + $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
607 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
608 | + $cid = $wpdb->get_var($query); |
|
609 | + |
|
610 | + if (!empty($customer_entity_id)) { |
|
611 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes'); |
|
612 | + $attributes_sets = $wpdb->get_results($query); |
|
613 | + foreach ($attributes_sets as $attributes_set) { |
|
614 | + if (!empty($attributes_set->id)) { |
|
615 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
616 | + $attributes_sections = $wpdb->get_results($query); |
|
617 | + |
|
618 | + if (!empty($attributes_sections)) { |
|
619 | + foreach ($attributes_sections as $attributes_section) { |
|
620 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
621 | + $attributes_details = $wpdb->get_results($query); |
|
622 | + |
|
623 | + foreach ($attributes_details as $attributes_detail) { |
|
624 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid'); |
|
625 | + $attribute_def = $wpdb->get_row($query); |
|
626 | + |
|
627 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid); |
|
628 | + $attribute_value = $wpdb->get_var($query); |
|
629 | 629 | |
630 | 630 | /** Check attribute type for specific type display */ |
631 | - if ( "datetime" == $attribute_def->data_type ) { |
|
632 | - $attribute_value = mysql2date( get_option( 'date_format' ) . ( ( substr( $attribute_value, -9 ) != ' 00:00:00' ) ? ' ' . get_option( 'time_format' ) : '' ), $attribute_value, true); |
|
631 | + if ("datetime" == $attribute_def->data_type) { |
|
632 | + $attribute_value = mysql2date(get_option('date_format') . ((substr($attribute_value, -9) != ' 00:00:00') ? ' ' . get_option('time_format') : ''), $attribute_value, true); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | /** Check attribute input type in order to get specific value */ |
636 | - if ( in_array( $attribute_def->backend_input, array( 'multiple-select', 'select', 'radio', 'checkbox' ) ) ) { |
|
637 | - if ( $attribute_def->data_type_to_use == 'custom' ) { |
|
638 | - $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value ); |
|
639 | - $attribute_value = $wpdb->get_var( $query ); |
|
636 | + if (in_array($attribute_def->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) { |
|
637 | + if ($attribute_def->data_type_to_use == 'custom') { |
|
638 | + $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value); |
|
639 | + $attribute_value = $wpdb->get_var($query); |
|
640 | 640 | } |
641 | - else if ( $attribute_def->data_type_to_use == 'internal') { |
|
642 | - $associated_post = get_post( $atribute_value ); |
|
641 | + else if ($attribute_def->data_type_to_use == 'internal') { |
|
642 | + $associated_post = get_post($atribute_value); |
|
643 | 643 | $attribute_value = $associated_post->post_title; |
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | - if( !empty( $attribute_def ) ) { |
|
648 | - if( $attribute_def->frontend_input != 'password' ) { |
|
647 | + if (!empty($attribute_def)) { |
|
648 | + if ($attribute_def->frontend_input != 'password') { |
|
649 | 649 | ob_start(); |
650 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_element") ); |
|
650 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_element")); |
|
651 | 651 | $attribute_details .= ob_get_contents(); |
652 | 652 | ob_end_clean(); |
653 | 653 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | ob_start(); |
658 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_group_element") ); |
|
658 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_group_element")); |
|
659 | 659 | $attributes_sections_tpl .= ob_get_contents(); |
660 | 660 | ob_end_clean(); |
661 | 661 | |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | } |
667 | 667 | } |
668 | 668 | ob_start(); |
669 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations") ); |
|
669 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations")); |
|
670 | 670 | $output = ob_get_contents(); |
671 | 671 | ob_end_clean(); |
672 | 672 | } |
@@ -680,85 +680,85 @@ discard block |
||
680 | 680 | function account_informations_form() { |
681 | 681 | global $wpdb; |
682 | 682 | $output = ''; |
683 | - if ( get_current_user_id() != 0 ) { |
|
683 | + if (get_current_user_id() != 0) { |
|
684 | 684 | // Customer ID data |
685 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
686 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id() ); |
|
687 | - $cid = $wpdb->get_var( $query ); |
|
685 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
686 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id()); |
|
687 | + $cid = $wpdb->get_var($query); |
|
688 | 688 | |
689 | 689 | $fields_to_output = $signup_fields = array(); |
690 | 690 | |
691 | - $password_attribute = $signup_form_attributes = array(); |
|
691 | + $password_attribute = $signup_form_attributes = array(); |
|
692 | 692 | |
693 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
693 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
694 | 694 | |
695 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
696 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
695 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
696 | + $customer_entity_id = $wpdb->get_var($query); |
|
697 | 697 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
698 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
699 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
700 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
701 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
702 | - if ( !empty( $account_attributes[$customer_attributes_section->id] ) ) { |
|
703 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
698 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
699 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
700 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
701 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
702 | + if (!empty($account_attributes[$customer_attributes_section->id])) { |
|
703 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
704 | 704 | $signup_fields[] = $attribute; |
705 | 705 | } |
706 | 706 | } |
707 | 707 | } |
708 | 708 | |
709 | 709 | ob_start(); |
710 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_form") ); |
|
710 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_form")); |
|
711 | 711 | $output = ob_get_contents(); |
712 | 712 | ob_end_clean(); |
713 | 713 | } |
714 | 714 | return $output; |
715 | 715 | } |
716 | 716 | |
717 | - function save_account_informations( $cid, $args, $admin = true ) { |
|
717 | + function save_account_informations($cid, $args, $admin = true) { |
|
718 | 718 | global $wpdb, $wpshop; |
719 | 719 | |
720 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
720 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
721 | 721 | $wps_entities = new wpshop_entities(); |
722 | - $element_id = $wps_entities->get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
722 | + $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
723 | 723 | |
724 | - $query = $wpdb->prepare( 'SELECT post_author FROM ' .$wpdb->posts. ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid ); |
|
725 | - $user_id = $wpdb->get_var( $query ); |
|
724 | + $query = $wpdb->prepare('SELECT post_author FROM ' . $wpdb->posts . ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid); |
|
725 | + $user_id = $wpdb->get_var($query); |
|
726 | 726 | |
727 | 727 | $user_name = !empty($args['attribute']['varchar']['user_login']) ? $args['attribute']['varchar']['user_login'] : $args['attribute']['varchar']['user_email']; |
728 | 728 | $user_pass = !empty($args['attribute']['varchar']['user_pass']) ? $args['attribute']['varchar']['user_pass'] : ''; |
729 | 729 | |
730 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
731 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
732 | - if ( !empty($attribute_set_id) ) { |
|
733 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
730 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
731 | + $attribute_set_id = $wpdb->get_var($query); |
|
732 | + if (!empty($attribute_set_id)) { |
|
733 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
734 | 734 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
735 | - wpshop_attributes::saveAttributeForEntity( $args['attribute'], $element_id, $cid ); |
|
736 | - foreach ( $group as $attribute_sets ) { |
|
737 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
738 | - if( $admin ) { |
|
739 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute'] ); |
|
735 | + wpshop_attributes::saveAttributeForEntity($args['attribute'], $element_id, $cid); |
|
736 | + foreach ($group as $attribute_sets) { |
|
737 | + foreach ($attribute_sets as $attribute_set_field) { |
|
738 | + if ($admin) { |
|
739 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute']); |
|
740 | 740 | } |
741 | - if ( empty($wpshop->errors) || !$admin ) { |
|
741 | + if (empty($wpshop->errors) || !$admin) { |
|
742 | 742 | $wpshop_attributes = new wpshop_attributes(); |
743 | - foreach( $attribute_set_field['content'] as $attribute ) { |
|
744 | - $attribute_def = wpshop_attributes::getElement( $attribute['name'], "'valid'", 'code'); |
|
745 | - if ( !in_array( $attribute['name'], $exclude_user_meta ) ) { |
|
746 | - update_user_meta( $user_id, $attribute['name'], wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ); |
|
743 | + foreach ($attribute_set_field['content'] as $attribute) { |
|
744 | + $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code'); |
|
745 | + if (!in_array($attribute['name'], $exclude_user_meta)) { |
|
746 | + update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']])); |
|
747 | 747 | } |
748 | 748 | else { |
749 | - wp_update_user( array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ) ); |
|
749 | + wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']]))); |
|
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
753 | 753 | /** Update newsletter user preferences **/ |
754 | 754 | $newsletter_preferences = array(); |
755 | - if( !empty($args['newsletters_site']) ) { |
|
755 | + if (!empty($args['newsletters_site'])) { |
|
756 | 756 | $newsletter_preferences['newsletters_site'] = 1; |
757 | 757 | } |
758 | - if( !empty($args['newsletters_site_partners']) ) { |
|
758 | + if (!empty($args['newsletters_site_partners'])) { |
|
759 | 759 | $newsletter_preferences['newsletters_site_partners'] = 1; |
760 | 760 | } |
761 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
761 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
762 | 762 | } else { |
763 | 763 | return $wpshop->errors; |
764 | 764 | } |
@@ -770,22 +770,22 @@ discard block |
||
770 | 770 | /** |
771 | 771 | * ACCOUNT - Save account informations |
772 | 772 | */ |
773 | - function wps_save_account_informations () { |
|
774 | - check_ajax_referer( 'wps_save_account_informations' ); |
|
773 | + function wps_save_account_informations() { |
|
774 | + check_ajax_referer('wps_save_account_informations'); |
|
775 | 775 | |
776 | 776 | global $wpdb; |
777 | 777 | $status = false; $response = ''; |
778 | 778 | |
779 | 779 | $user_id = get_current_user_id(); |
780 | - if ( !empty($user_id) ) { |
|
781 | - $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id ); |
|
782 | - $cid = $wpdb->get_var( $query ); |
|
780 | + if (!empty($user_id)) { |
|
781 | + $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
782 | + $cid = $wpdb->get_var($query); |
|
783 | 783 | } |
784 | 784 | |
785 | - $errors = $this->save_account_informations( $cid, $_POST ); |
|
786 | - if( !empty( $errors ) ) { |
|
787 | - $response = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
788 | - foreach( $errors as $error ){ |
|
785 | + $errors = $this->save_account_informations($cid, $_POST); |
|
786 | + if (!empty($errors)) { |
|
787 | + $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
788 | + foreach ($errors as $error) { |
|
789 | 789 | $response .= '<li>' . $error . '</li>'; |
790 | 790 | } |
791 | 791 | $response .= '</div>'; |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | $status = true; |
795 | 795 | } |
796 | 796 | |
797 | - wp_die( json_encode( array( 'status' => $status, 'response' => $response) ) ); |
|
797 | + wp_die(json_encode(array('status' => $status, 'response' => $response))); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -805,23 +805,23 @@ discard block |
||
805 | 805 | |
806 | 806 | $status = false; |
807 | 807 | $response = do_shortcode('[wps_account_informations]'); |
808 | - if( !empty($response) ) { |
|
808 | + if (!empty($response)) { |
|
809 | 809 | $status = true; |
810 | 810 | } |
811 | 811 | |
812 | - wp_die( json_encode( array( 'status' => $status, 'response' => $response ) ) ); |
|
812 | + wp_die(json_encode(array('status' => $status, 'response' => $response))); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | 816 | * ACCOUNT - AJAX - Fill account informations modal |
817 | 817 | */ |
818 | 818 | function wps_fill_account_informations_modal() { |
819 | - check_ajax_referer( 'wps_fill_account_informations_modal' ); |
|
819 | + check_ajax_referer('wps_fill_account_informations_modal'); |
|
820 | 820 | |
821 | 821 | $title = $content = ''; |
822 | 822 | $title = __('Edit your account informations', 'wpshop'); |
823 | - $content = do_shortcode( '[wps_account_informations_form]' ); |
|
824 | - echo json_encode( array( 'status' => true, 'title' => $title, 'content' => $content) ); |
|
823 | + $content = do_shortcode('[wps_account_informations_form]'); |
|
824 | + echo json_encode(array('status' => true, 'title' => $title, 'content' => $content)); |
|
825 | 825 | wp_die(); |
826 | 826 | } |
827 | 827 |
@@ -1,31 +1,31 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2 | -$permalink_option = get_option( 'permalink_structure' ); |
|
3 | -$account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' ) ); |
|
4 | -$account_dashboard_part = !empty( $_GET['account_dashboard_part'] ) ? sanitize_text_field( $_GET['account_dashboard_part'] ) : ''; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | +$permalink_option = get_option('permalink_structure'); |
|
3 | +$account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
4 | +$account_dashboard_part = !empty($_GET['account_dashboard_part']) ? sanitize_text_field($_GET['account_dashboard_part']) : ''; |
|
5 | 5 | ?> |
6 | 6 | |
7 | 7 | <?php $user_id = get_current_user_id(); ?> |
8 | 8 | |
9 | -<?php if ( 0 !== $user_id ) : |
|
10 | - $account_user = get_userdata( $user_id ); ?> |
|
9 | +<?php if (0 !== $user_id) : |
|
10 | + $account_user = get_userdata($user_id); ?> |
|
11 | 11 | <div class="wps-user-dashboard" > |
12 | - <?php do_action( 'wps_user_dashboard_header', $user_id, $account_user ); ?> |
|
12 | + <?php do_action('wps_user_dashboard_header', $user_id, $account_user); ?> |
|
13 | 13 | |
14 | 14 | <div class="wps-user-info has-sub-menu" > |
15 | 15 | <span class="wps-user-name"> |
16 | - <?php echo get_avatar( $user_id, 40 ); ?> |
|
17 | - <strong><?php echo esc_html( $account_user->data->user_login ); ?></strong> |
|
16 | + <?php echo get_avatar($user_id, 40); ?> |
|
17 | + <strong><?php echo esc_html($account_user->data->user_login); ?></strong> |
|
18 | 18 | </span> |
19 | 19 | <ul class="sub-menu" > |
20 | 20 | <?php |
21 | - if ( function_exists( 'current_user_switched' ) ) : |
|
21 | + if (function_exists('current_user_switched')) : |
|
22 | 22 | $old_user = current_user_switched(); |
23 | - if ( $old_user && $url = user_switching::maybe_switch_url( $old_user ) ) : |
|
24 | - printf( '<li><a href="%s">Switch back</a></li>', esc_url( $url ) ); |
|
23 | + if ($old_user && $url = user_switching::maybe_switch_url($old_user)) : |
|
24 | + printf('<li><a href="%s">Switch back</a></li>', esc_url($url)); |
|
25 | 25 | endif; |
26 | 26 | endif; |
27 | 27 | ?> |
28 | - <li><a href="<?php echo esc_url( wp_logout_url( site_url() ) ); ?>"><i class="wps-icon-power"></i> <?php esc_html_e( 'Se déconnecter', 'eoxia' ); ?></a></li> |
|
28 | + <li><a href="<?php echo esc_url(wp_logout_url(site_url())); ?>"><i class="wps-icon-power"></i> <?php esc_html_e('Se déconnecter', 'eoxia'); ?></a></li> |
|
29 | 29 | </ul> |
30 | 30 | </div> |
31 | 31 | </div> |
@@ -34,50 +34,50 @@ discard block |
||
34 | 34 | <section class="wps-section-account"> |
35 | 35 | <div class="wps-section-taskbar"> |
36 | 36 | <ul> |
37 | - <li class="<?php echo ( ( empty($account_dashboard_part) || ( !empty($account_dashboard_part) && $account_dashboard_part == 'account' ) ) ? 'wps-activ' : '' ); ?>"> |
|
38 | - <a data-target="menu1" href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=account' ); ?>" title="" class=""> |
|
37 | + <li class="<?php echo ((empty($account_dashboard_part) || (!empty($account_dashboard_part) && $account_dashboard_part == 'account')) ? 'wps-activ' : ''); ?>"> |
|
38 | + <a data-target="menu1" href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=account'); ?>" title="" class=""> |
|
39 | 39 | <i class="wps-icon-user"></i> |
40 | - <span><?php _e( 'Account', 'wpshop'); ?></span> |
|
40 | + <span><?php _e('Account', 'wpshop'); ?></span> |
|
41 | 41 | </a> |
42 | 42 | </li> |
43 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : '' ); ?>"> |
|
44 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=address' ); ?>" title="" class=""> |
|
43 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'address') ? 'wps-activ' : ''); ?>"> |
|
44 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=address'); ?>" title="" class=""> |
|
45 | 45 | <i class="wps-icon-address"></i> |
46 | - <span><?php _e( 'Addresses', 'wpshop'); ?></span> |
|
46 | + <span><?php _e('Addresses', 'wpshop'); ?></span> |
|
47 | 47 | </a> |
48 | 48 | </li> |
49 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : '' ); ?>"> |
|
50 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=order' ); ?>" title="" class=""> |
|
49 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'order') ? 'wps-activ' : ''); ?>"> |
|
50 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=order'); ?>" title="" class=""> |
|
51 | 51 | <i class="wps-icon-truck"></i> |
52 | - <span><?php _e( 'Orders', 'wpshop'); ?></span> |
|
52 | + <span><?php _e('Orders', 'wpshop'); ?></span> |
|
53 | 53 | </a> |
54 | 54 | </li> |
55 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : '' ); ?>"> |
|
56 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=coupon' ); ?>" title="" class=""> |
|
55 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'coupon') ? 'wps-activ' : ''); ?>"> |
|
56 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=coupon'); ?>" title="" class=""> |
|
57 | 57 | <i class="wps-icon-promo"></i> |
58 | - <span><?php _e( 'Coupons', 'wpshop'); ?></span> |
|
58 | + <span><?php _e('Coupons', 'wpshop'); ?></span> |
|
59 | 59 | </a> |
60 | 60 | </li> |
61 | - <?php $opinion_option = get_option( 'wps_opinion' ); |
|
62 | - if( !empty($opinion_option) && !empty($opinion_option['active']) ) : ?> |
|
63 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : '' ); ?>"> |
|
64 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=opinion' ); ?>" title="" class=""> |
|
61 | + <?php $opinion_option = get_option('wps_opinion'); |
|
62 | + if (!empty($opinion_option) && !empty($opinion_option['active'])) : ?> |
|
63 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'opinion') ? 'wps-activ' : ''); ?>"> |
|
64 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=opinion'); ?>" title="" class=""> |
|
65 | 65 | <i class="wps-icon-chat"></i> |
66 | - <span><?php _e( 'Opinions', 'wpshop'); ?></span> |
|
66 | + <span><?php _e('Opinions', 'wpshop'); ?></span> |
|
67 | 67 | </a> |
68 | 68 | </li> |
69 | 69 | <?php endif; ?> |
70 | - <li class="<?php echo ( ( !empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : '' ); ?>"> |
|
71 | - <a href="<?php echo get_permalink($account_page_id).( (!empty($permalink_option) ? '?' : '&' ).'account_dashboard_part=messages' ); ?>" title="" class=""> |
|
70 | + <li class="<?php echo ((!empty($account_dashboard_part) && $account_dashboard_part == 'messages') ? 'wps-activ' : ''); ?>"> |
|
71 | + <a href="<?php echo get_permalink($account_page_id) . ((!empty($permalink_option) ? '?' : '&') . 'account_dashboard_part=messages'); ?>" title="" class=""> |
|
72 | 72 | <i class="wps-icon-email"></i> |
73 | - <span><?php _e( 'Messages', 'wpshop' ); ?></span> |
|
73 | + <span><?php _e('Messages', 'wpshop'); ?></span> |
|
74 | 74 | </a> |
75 | 75 | </li> |
76 | 76 | <?php echo apply_filters('wps_my_account_extra_part_menu', ''); ?> |
77 | 77 | </ul> |
78 | 78 | </div> |
79 | 79 | <div class="wps-section-content"> |
80 | - <div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce( 'wps_refresh_add_opinion_list' ); ?>"> |
|
80 | + <div class="wps-activ" id="wps_dashboard_content" data-nonce="<?php echo wp_create_nonce('wps_refresh_add_opinion_list'); ?>"> |
|
81 | 81 | <?php echo $content; ?> |
82 | 82 | </div> |
83 | 83 | </div> |