@@ -9,37 +9,37 @@ |
||
9 | 9 | * @version 3.0.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if (!defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | ?> |
16 | -<?php foreach ( $users as $user_id => $user ) : ?> |
|
17 | - <?php if ( 0 !== $user_id ) : ?> |
|
18 | - <?php if ( true === $user['is_default'] ) : ?> |
|
16 | +<?php foreach ($users as $user_id => $user) : ?> |
|
17 | + <?php if (0 !== $user_id) : ?> |
|
18 | + <?php if (true === $user['is_default']) : ?> |
|
19 | 19 | <?php $default_user = $user_id; ?> |
20 | 20 | <?php endif; ?> |
21 | - <tr data-customer-id="<?php echo esc_attr( $customer->ID ); ?>" data-user-id="<?php echo esc_attr( $user_id ); ?>" > |
|
22 | - <td>#<?php echo esc_html( $user_id ); ?></td> |
|
23 | - <td><?php echo esc_html( $user['last_name'] . ' ' . $user['first_name'] ); ?></td> |
|
24 | - <td><?php echo esc_html( $user['display_name'] ); ?></td> |
|
25 | - <td><?php echo esc_html( $user['user_email'] ); ?></td> |
|
21 | + <tr data-customer-id="<?php echo esc_attr($customer->ID); ?>" data-user-id="<?php echo esc_attr($user_id); ?>" > |
|
22 | + <td>#<?php echo esc_html($user_id); ?></td> |
|
23 | + <td><?php echo esc_html($user['last_name'] . ' ' . $user['first_name']); ?></td> |
|
24 | + <td><?php echo esc_html($user['display_name']); ?></td> |
|
25 | + <td><?php echo esc_html($user['user_email']); ?></td> |
|
26 | 26 | |
27 | 27 | <td class="wps-customer-contacts-actions" > |
28 | 28 | |
29 | - <?php do_action( 'wps_customer_contacts_list_action', $user_id ); ?> |
|
29 | + <?php do_action('wps_customer_contacts_list_action', $user_id); ?> |
|
30 | 30 | |
31 | - <?php if ( true === $user['is_default'] ) : ?> |
|
32 | - <i title="<?php esc_attr_e( 'This is the main contact / customer creator', 'wpshop' ); ?>" class="dashicons dashicons-star-filled" ></i> |
|
31 | + <?php if (true === $user['is_default']) : ?> |
|
32 | + <i title="<?php esc_attr_e('This is the main contact / customer creator', 'wpshop'); ?>" class="dashicons dashicons-star-filled" ></i> |
|
33 | 33 | <?php else : ?> |
34 | - <i title="<?php esc_attr_e( 'Change to default customer', 'wpshop' ); ?>" class="dashicons dashicons-star-empty" ></i> |
|
34 | + <i title="<?php esc_attr_e('Change to default customer', 'wpshop'); ?>" class="dashicons dashicons-star-empty" ></i> |
|
35 | 35 | <?php endif; ?> |
36 | 36 | |
37 | - <!-- <a title="<?php esc_attr_e( 'User account edition', 'wpshop' ); ?>" href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=load_user_account_form&_wpnonce=' . wp_create_nonce( 'load_user_account_form' ) . '&user_id=' . $user_id ) ); ?>" class="thickbox" ><i class="dashicons dashicons-edit" ></i></a> --> |
|
37 | + <!-- <a title="<?php esc_attr_e('User account edition', 'wpshop'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php?action=load_user_account_form&_wpnonce=' . wp_create_nonce('load_user_account_form') . '&user_id=' . $user_id)); ?>" class="thickbox" ><i class="dashicons dashicons-edit" ></i></a> --> |
|
38 | 38 | |
39 | - <?php if ( true === $user['is_default'] ) : ?> |
|
40 | - <i title="<?php esc_attr_e( 'This is the main contact, you can\'t unlink it', 'wpshop' ); ?>" class="dashicons dashicons-lock" ></i> |
|
39 | + <?php if (true === $user['is_default']) : ?> |
|
40 | + <i title="<?php esc_attr_e('This is the main contact, you can\'t unlink it', 'wpshop'); ?>" class="dashicons dashicons-lock" ></i> |
|
41 | 41 | <?php else : ?> |
42 | - <i title="<?php esc_attr_e( 'Unlink this user', 'wpshop' ); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
42 | + <i title="<?php esc_attr_e('Unlink this user', 'wpshop'); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
43 | 43 | <?php endif; ?> |
44 | 44 | </td> |
45 | 45 | </tr> |
@@ -9,19 +9,19 @@ discard block |
||
9 | 9 | * @version 3.0.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if (!defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
16 | 16 | $default_user = 0; |
17 | 17 | ob_start(); |
18 | -require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contact' ) ); |
|
18 | +require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contact')); |
|
19 | 19 | $output = ob_get_clean(); |
20 | 20 | |
21 | 21 | ?><table class="wp-list-table widefat fixed striped users" |
22 | - data-dissociate-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_dissociate' ) ); ?>" |
|
23 | - data-change-default-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_change_default' ) ); ?>" |
|
24 | - data-default-user-id="<?php echo esc_attr( $default_user ); ?>" > |
|
22 | + data-dissociate-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_dissociate')); ?>" |
|
23 | + data-change-default-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_change_default')); ?>" |
|
24 | + data-default-user-id="<?php echo esc_attr($default_user); ?>" > |
|
25 | 25 | |
26 | 26 | <tbody> |
27 | 27 | <?php echo $output; // WPCS: XSS ok. ?> |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | <tr> |
32 | 32 | <td colspan="5" class="wps-customer-associate-contact-container" > |
33 | 33 | <span class="wps-customer-contact-association-opener" ><i class="dashicons dashicons-plus" ></i></span> |
34 | - <input type="text" class="wps-customer-autocomplete-input hidden" placeholder="<?php esc_html_e( 'Start typing for user searching', 'wpshop' ); ?>" |
|
35 | - data-search-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_search' ) ); ?>" |
|
34 | + <input type="text" class="wps-customer-autocomplete-input hidden" placeholder="<?php esc_html_e('Start typing for user searching', 'wpshop'); ?>" |
|
35 | + data-search-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_search')); ?>" |
|
36 | 36 | data-types="users" |
37 | - data-customer="<?php echo esc_attr( $customer->ID ); ?>" |
|
38 | - data-associate-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_associate' ) ); ?>" /> |
|
37 | + data-customer="<?php echo esc_attr($customer->ID); ?>" |
|
38 | + data-associate-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_associate')); ?>" /> |
|
39 | 39 | </td> |
40 | 40 | </tr> |
41 | 41 | </tfoot> |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage modules |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | * Instanciation des actions pour la gestion des clients |
30 | 30 | */ |
31 | 31 | public function __construct() { |
32 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); |
|
32 | + add_action('add_meta_boxes', array($this, 'add_meta_box')); |
|
33 | 33 | |
34 | - add_action( 'admin_enqueue_scripts', array( $this, 'callback_admin_enqueue_scripts' ), 11 ); |
|
35 | - add_action( 'wp_enqueue_scripts', array( $this, 'callback_enqueue_scripts' ), 11 ); |
|
34 | + add_action('admin_enqueue_scripts', array($this, 'callback_admin_enqueue_scripts'), 11); |
|
35 | + add_action('wp_enqueue_scripts', array($this, 'callback_enqueue_scripts'), 11); |
|
36 | 36 | |
37 | 37 | /** Affichage de la liste déroulante des clients associés dans le compte de l'utilisateur connecté / Display associated customer list into connected user account */ |
38 | - add_action( 'wps_user_dashboard_header', array( $this, 'callback_customer_dashboard' ), 10, 2 ); |
|
38 | + add_action('wps_user_dashboard_header', array($this, 'callback_customer_dashboard'), 10, 2); |
|
39 | 39 | |
40 | 40 | // Association des utilisateurs à un client / Associate a user to a customer. |
41 | - add_action( 'wp_ajax_wps_customer_contacts_associate', array( $this, 'ajax_callback_associate_user' ) ); |
|
41 | + add_action('wp_ajax_wps_customer_contacts_associate', array($this, 'ajax_callback_associate_user')); |
|
42 | 42 | // Dissociation d'un utilisateur à un client / Dissociate a user from a customer. |
43 | - add_action( 'wp_ajax_wps_customer_contacts_dissociate', array( $this, 'ajax_callback_dissociate_user' ) ); |
|
43 | + add_action('wp_ajax_wps_customer_contacts_dissociate', array($this, 'ajax_callback_dissociate_user')); |
|
44 | 44 | // Changement de l'utilisateur par défaut (auteur) d'un client / Change the default user (author) for a customer. |
45 | - add_action( 'wp_ajax_wps_customer_contacts_change_default', array( $this, 'ajax_callback_change_default_user' ) ); |
|
45 | + add_action('wp_ajax_wps_customer_contacts_change_default', array($this, 'ajax_callback_change_default_user')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param string $post_type Le type d'élément sur lequel se trouve l'utilisateur / Element type where the user is. |
52 | 52 | */ |
53 | - function add_meta_box( $post_type ) { |
|
54 | - add_meta_box( 'wps_customer_contacts', __( 'Customer contact list', 'wpshop' ), array( $this, 'customer_contact_list_callback' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high' ); |
|
53 | + function add_meta_box($post_type) { |
|
54 | + add_meta_box('wps_customer_contacts', __('Customer contact list', 'wpshop'), array($this, 'customer_contact_list_callback'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function callback_admin_enqueue_scripts() { |
63 | 63 | $screen = get_current_screen(); |
64 | - if ( in_array( $screen->id, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
65 | - wp_register_style( 'wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION ); |
|
66 | - wp_enqueue_style( 'wps_customer_contacts-style' ); |
|
67 | - wp_register_script( 'wps_customer_contacts-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.backend.js', array( 'jquery', 'jquery-form', 'jquery-ui-autocomplete' ), WPSHOP_VERSION ); |
|
68 | - wp_localize_script( 'wps_customer_contacts-script', 'wpshopCrm', array( |
|
69 | - 'confirm_user_dissociation' => __( 'Are you sure you want to dissociate this user', 'wpshop' ), |
|
70 | - 'confirm_change_default_user' => __( 'Are you sure you want to change default user for current customer?', 'wpshop' ), |
|
71 | - ) ); |
|
72 | - wp_enqueue_script( 'wps_customer_contacts-script' ); |
|
64 | + if (in_array($screen->id, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
65 | + wp_register_style('wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION); |
|
66 | + wp_enqueue_style('wps_customer_contacts-style'); |
|
67 | + wp_register_script('wps_customer_contacts-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.backend.js', array('jquery', 'jquery-form', 'jquery-ui-autocomplete'), WPSHOP_VERSION); |
|
68 | + wp_localize_script('wps_customer_contacts-script', 'wpshopCrm', array( |
|
69 | + 'confirm_user_dissociation' => __('Are you sure you want to dissociate this user', 'wpshop'), |
|
70 | + 'confirm_change_default_user' => __('Are you sure you want to change default user for current customer?', 'wpshop'), |
|
71 | + )); |
|
72 | + wp_enqueue_script('wps_customer_contacts-script'); |
|
73 | 73 | add_thickbox(); |
74 | 74 | } |
75 | 75 | } |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | * Enqueue scripts and style in frontend |
79 | 79 | */ |
80 | 80 | public function callback_enqueue_scripts() { |
81 | - $pagename = get_query_var( 'pagename' ); |
|
82 | - if ( in_array( $pagename, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
83 | - wp_register_style( 'task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION ); |
|
84 | - wp_enqueue_style( 'task-manager-frontend-style' ); |
|
81 | + $pagename = get_query_var('pagename'); |
|
82 | + if (in_array($pagename, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
83 | + wp_register_style('task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION); |
|
84 | + wp_enqueue_style('task-manager-frontend-style'); |
|
85 | 85 | } |
86 | - wp_register_script( 'wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION ); |
|
87 | - wp_enqueue_script( 'wps_customer_contacts-frontend-script' ); |
|
86 | + wp_register_script('wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION); |
|
87 | + wp_enqueue_script('wps_customer_contacts-frontend-script'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @param WP_Post $customer La définition principale du client actuellement en cours d'édition / Current edited customer definition. |
94 | 94 | */ |
95 | - function customer_contact_list_callback( $customer ) { |
|
96 | - $users = $this->get_customer_contact_list( $customer ); |
|
95 | + function customer_contact_list_callback($customer) { |
|
96 | + $users = $this->get_customer_contact_list($customer); |
|
97 | 97 | |
98 | 98 | /** Display user list for current customer */ |
99 | - require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts' ) ); |
|
99 | + require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts')); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return [type] [description] |
108 | 108 | */ |
109 | - function get_customer_contact_list( $customer ) { |
|
109 | + function get_customer_contact_list($customer) { |
|
110 | 110 | /** Define user list */ |
111 | 111 | $users = array(); |
112 | 112 | |
113 | 113 | /** Get associated users' */ |
114 | - $associated_users = (array) get_post_meta( $customer->ID, $this->user_contact_list_meta_key, true ); |
|
115 | - $user_list = wp_parse_id_list( array_merge( $associated_users, array( $customer->post_author ) ) ); |
|
116 | - if ( ! empty( $user_list ) ) { |
|
117 | - foreach ( $user_list as $user_id ) { |
|
118 | - if ( 0 !== $user_id ) { |
|
119 | - $associated_user = get_user_by( 'ID', $user_id ); |
|
120 | - if ( is_object( $associated_user ) ) { |
|
121 | - $users[ $user_id ] = wp_parse_args( $associated_user->data, array( |
|
114 | + $associated_users = (array)get_post_meta($customer->ID, $this->user_contact_list_meta_key, true); |
|
115 | + $user_list = wp_parse_id_list(array_merge($associated_users, array($customer->post_author))); |
|
116 | + if (!empty($user_list)) { |
|
117 | + foreach ($user_list as $user_id) { |
|
118 | + if (0 !== $user_id) { |
|
119 | + $associated_user = get_user_by('ID', $user_id); |
|
120 | + if (is_object($associated_user)) { |
|
121 | + $users[$user_id] = wp_parse_args($associated_user->data, array( |
|
122 | 122 | 'last_name' => $associated_user->last_name, |
123 | 123 | 'first_name' => $associated_user->first_name, |
124 | - 'is_default' => ( $user_id === (int) $customer->post_author ? true : false ), |
|
125 | - ) ); |
|
124 | + 'is_default' => ($user_id === (int)$customer->post_author ? true : false), |
|
125 | + )); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -137,20 +137,20 @@ discard block |
||
137 | 137 | * @param integer $user_id Identifiant de l'utilisateur actuellement connecté / User identifier currenly connected. |
138 | 138 | * @param WP_User $account_user La définition du compte utilisateur / The user account definition. |
139 | 139 | */ |
140 | - function callback_customer_dashboard( $user_id, $account_user ) { |
|
140 | + function callback_customer_dashboard($user_id, $account_user) { |
|
141 | 141 | $customers = array(); |
142 | 142 | |
143 | - $customers_from_posts = new WP_Query( array( |
|
143 | + $customers_from_posts = new WP_Query(array( |
|
144 | 144 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
145 | 145 | 'author' => $user_id, |
146 | 146 | 'posts_per_page' => -1, |
147 | 147 | 'post_status' => 'any', |
148 | - ) ); |
|
149 | - if ( $customers_from_posts->have_posts() ) { |
|
150 | - $customers = array_merge( $customers, $customers_from_posts->posts ); |
|
148 | + )); |
|
149 | + if ($customers_from_posts->have_posts()) { |
|
150 | + $customers = array_merge($customers, $customers_from_posts->posts); |
|
151 | 151 | } |
152 | 152 | |
153 | - $customers_from_meta = new WP_Query( array( |
|
153 | + $customers_from_meta = new WP_Query(array( |
|
154 | 154 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
155 | 155 | 'posts_per_page' => -1, |
156 | 156 | 'post_status' => 'any', |
@@ -162,20 +162,20 @@ discard block |
||
162 | 162 | 'type' => 'CHAR', |
163 | 163 | ), |
164 | 164 | ), |
165 | - ) ); |
|
166 | - if ( $customers_from_meta->have_posts() ) { |
|
167 | - $customers = array_merge( $customers, $customers_from_meta->posts ); |
|
165 | + )); |
|
166 | + if ($customers_from_meta->have_posts()) { |
|
167 | + $customers = array_merge($customers, $customers_from_meta->posts); |
|
168 | 168 | } |
169 | - usort( $customers, function( $a, $b ) { |
|
170 | - if ( $a->ID === $b->ID ) { |
|
169 | + usort($customers, function($a, $b) { |
|
170 | + if ($a->ID === $b->ID) { |
|
171 | 171 | return 0; |
172 | 172 | } |
173 | 173 | return ($a < $b) ? -1 : 1; |
174 | 174 | }); |
175 | 175 | |
176 | - if ( ! empty( $customers ) && ( 1 < count( $customers ) ) ) { |
|
176 | + if (!empty($customers) && (1 < count($customers))) { |
|
177 | 177 | /** Display user list for current customer */ |
178 | - require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice' ) ); |
|
178 | + require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice')); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -183,20 +183,20 @@ discard block |
||
183 | 183 | * Ajax callback - Associate a user to a customer |
184 | 184 | */ |
185 | 185 | function ajax_callback_associate_user() { |
186 | - check_ajax_referer( 'wps_customer_contacts_associate' ); |
|
186 | + check_ajax_referer('wps_customer_contacts_associate'); |
|
187 | 187 | |
188 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
189 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
188 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
189 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
190 | 190 | |
191 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
192 | - if ( ! empty( $associated_users ) ) { |
|
193 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $user_id ) ) ); |
|
191 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
192 | + if (!empty($associated_users)) { |
|
193 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($user_id))); |
|
194 | 194 | } else { |
195 | - $new_associated_users = array( $user_id ); |
|
195 | + $new_associated_users = array($user_id); |
|
196 | 196 | } |
197 | 197 | |
198 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
199 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
198 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
199 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
200 | 200 | wp_die(); |
201 | 201 | } |
202 | 202 | |
@@ -204,20 +204,20 @@ discard block |
||
204 | 204 | * Ajax callback - Associate a user to a customer |
205 | 205 | */ |
206 | 206 | function ajax_callback_dissociate_user() { |
207 | - check_ajax_referer( 'wps_customer_contacts_dissociate' ); |
|
207 | + check_ajax_referer('wps_customer_contacts_dissociate'); |
|
208 | 208 | |
209 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
210 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
209 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
210 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
211 | 211 | |
212 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
213 | - foreach ( $associated_users as $key => $id ) { |
|
214 | - if ( $id === $user_id ) { |
|
215 | - unset( $associated_users[ $key ] ); |
|
212 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
213 | + foreach ($associated_users as $key => $id) { |
|
214 | + if ($id === $user_id) { |
|
215 | + unset($associated_users[$key]); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $associated_users ); |
|
220 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
219 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $associated_users); |
|
220 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
221 | 221 | wp_die(); |
222 | 222 | } |
223 | 223 | |
@@ -225,30 +225,30 @@ discard block |
||
225 | 225 | * Ajax callback - Change the default user for a customer |
226 | 226 | */ |
227 | 227 | function ajax_callback_change_default_user() { |
228 | - check_ajax_referer( 'wps_customer_contacts_change_default' ); |
|
228 | + check_ajax_referer('wps_customer_contacts_change_default'); |
|
229 | 229 | |
230 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
231 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
232 | - $old_user_id = ! empty( $_POST ) && ! empty( $_POST['current_default_user_id'] ) && is_int( (int) $_POST['current_default_user_id'] ) ? (int) $_POST['current_default_user_id'] : null; |
|
230 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
231 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
232 | + $old_user_id = !empty($_POST) && !empty($_POST['current_default_user_id']) && is_int((int)$_POST['current_default_user_id']) ? (int)$_POST['current_default_user_id'] : null; |
|
233 | 233 | |
234 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_author' => $user_id ), array( 'ID' => $customer_id ) ); |
|
235 | - $customer_default_user_changes = get_post_meta( $customer_id, '_wps_customer_default_user_histo', true ); |
|
234 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, array('post_author' => $user_id), array('ID' => $customer_id)); |
|
235 | + $customer_default_user_changes = get_post_meta($customer_id, '_wps_customer_default_user_histo', true); |
|
236 | 236 | $customer_default_user_changes[] = array( |
237 | - 'date' => current_time( 'mysql' ), |
|
237 | + 'date' => current_time('mysql'), |
|
238 | 238 | 'old_post_author' => $old_user_id, |
239 | 239 | 'update_author' => get_current_user_id(), |
240 | 240 | ); |
241 | - update_post_meta( $customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes ); |
|
241 | + update_post_meta($customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes); |
|
242 | 242 | |
243 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
244 | - if ( ! empty( $associated_users ) ) { |
|
245 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $old_user_id ) ) ); |
|
243 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
244 | + if (!empty($associated_users)) { |
|
245 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($old_user_id))); |
|
246 | 246 | } else { |
247 | - $new_associated_users = array( $old_user_id ); |
|
247 | + $new_associated_users = array($old_user_id); |
|
248 | 248 | } |
249 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
249 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
250 | 250 | |
251 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
251 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
252 | 252 | wp_die(); |
253 | 253 | } |
254 | 254 |
@@ -5,25 +5,25 @@ |
||
5 | 5 | * @package WPShop |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
12 | 12 | ?> |
13 | 13 | <div id="wps_address_error_container"></div> |
14 | -<form id="wps_address_form_save" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> |
|
14 | +<form id="wps_address_form_save" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" method="post"> |
|
15 | 15 | <input type="hidden" name="action" value="wps_save_address" /> |
16 | - <input type="hidden" name="post_ID" value="<?php echo esc_attr( $customer_id ); ?>" /> |
|
17 | - <?php wp_nonce_field( 'wps_save_address' ); ?> |
|
18 | - <?php echo self::display_form_fields( $address_type_id, $address_id, '', '', array(), array(), array(), $customer_id ); // WPCS: XSS ok. ?> |
|
16 | + <input type="hidden" name="post_ID" value="<?php echo esc_attr($customer_id); ?>" /> |
|
17 | + <?php wp_nonce_field('wps_save_address'); ?> |
|
18 | + <?php echo self::display_form_fields($address_type_id, $address_id, '', '', array(), array(), array(), $customer_id); // WPCS: XSS ok. ?> |
|
19 | 19 | |
20 | 20 | <?php |
21 | 21 | /** Check if a billing address is already save **/ |
22 | - if ( $first_address_checking && ( $address_type_id !== (int) $billing_option['choice'] ) ) : ?> |
|
22 | + if ($first_address_checking && ($address_type_id !== (int)$billing_option['choice'])) : ?> |
|
23 | 23 | <div class="wps-form"> |
24 | - <input name="wps-shipping-to-billing" id="wps-shipping-to-billing" checked="checked" type="checkbox" /> <label for="wps-shipping-to-billing"><?php esc_html_e( 'Use the same address for billing', 'wpshop' ); ?></label> |
|
24 | + <input name="wps-shipping-to-billing" id="wps-shipping-to-billing" checked="checked" type="checkbox" /> <label for="wps-shipping-to-billing"><?php esc_html_e('Use the same address for billing', 'wpshop'); ?></label> |
|
25 | 25 | </div> |
26 | 26 | <?php endif; ?> |
27 | 27 | |
28 | - <button id="wps_submit_address_form" class="wps-bton-first-alignRight-rounded" ><?php esc_html_e( 'Save', 'wpshop' ); ?></button> |
|
28 | + <button id="wps_submit_address_form" class="wps-bton-first-alignRight-rounded" ><?php esc_html_e('Save', 'wpshop'); ?></button> |
|
29 | 29 | </form> |
@@ -1,66 +1,66 @@ |
||
1 | 1 | <?php |
2 | - if ( !defined( 'ABSPATH' ) ) exit; |
|
3 | -?><div class="wps-<?php echo esc_attr( $address_type ); ?>-address" <?php if ( ! empty( $first_address_checking ) && ! is_admin() && ( 'billing' === $address_type ) ) { echo 'style="display: none;"'; } ?>> |
|
2 | + if (!defined('ABSPATH')) exit; |
|
3 | +?><div class="wps-<?php echo esc_attr($address_type); ?>-address" <?php if (!empty($first_address_checking) && !is_admin() && ('billing' === $address_type)) { echo 'style="display: none;"'; } ?>> |
|
4 | 4 | <div class="wps-gridwrapper"> |
5 | - <div class="wps-grid4x6"><span class="wps-h3"><?php echo esc_html( $address_title ); ?></span></div> |
|
5 | + <div class="wps-grid4x6"><span class="wps-h3"><?php echo esc_html($address_title); ?></span></div> |
|
6 | 6 | </div> |
7 | - <ul class="wps-itemList wps-address-container" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_reload_address_interface' ) ); ?>" id="wps-address-container-<?php echo esc_attr( $address_type_id ); ?>"> |
|
8 | -<?php if ( ! empty( $box_content ) ) : ?> |
|
7 | + <ul class="wps-itemList wps-address-container" data-nonce="<?php echo esc_attr(wp_create_nonce('wps_reload_address_interface')); ?>" id="wps-address-container-<?php echo esc_attr($address_type_id); ?>"> |
|
8 | +<?php if (!empty($box_content)) : ?> |
|
9 | 9 | <?php echo $box_content; // WPCS: XSS ok. ?> |
10 | 10 | <?php endif; ?> |
11 | 11 | </ul> |
12 | 12 | |
13 | 13 | <?php |
14 | 14 | $hide_add_btn = true; |
15 | -if ( empty( $box_content ) && ( 'shipping' === $address_type ) ) : |
|
15 | +if (empty($box_content) && ('shipping' === $address_type)) : |
|
16 | 16 | $hide_add_btn = false; |
17 | 17 | ?> <div class="wps-address-first-address-creation-container" > |
18 | 18 | <div id="wps_address_error_container" ></div> |
19 | - <form id="wps_address_form_save_first_address" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> |
|
19 | + <form id="wps_address_form_save_first_address" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" method="post"> |
|
20 | 20 | <input type="hidden" name="action" value="wps_save_address" /> |
21 | - <?php wp_nonce_field( 'wps_save_address' ); ?> |
|
22 | - <input type="hidden" name="wps-address-save-the-first" value="<?php echo esc_attr( $address_type ); ?>" /> |
|
23 | - <?php echo self::display_form_fields( $address_type_id, '', 'first', '', array(), array(), array(), get_current_user_id() ); // WPCS: XSS ok. ?> |
|
21 | + <?php wp_nonce_field('wps_save_address'); ?> |
|
22 | + <input type="hidden" name="wps-address-save-the-first" value="<?php echo esc_attr($address_type); ?>" /> |
|
23 | + <?php echo self::display_form_fields($address_type_id, '', 'first', '', array(), array(), array(), get_current_user_id()); // WPCS: XSS ok. ?> |
|
24 | 24 | |
25 | 25 | <?php // Affichage d'une case à cocher permettant la création d'une adresse de facturatoin à parti de l'adresse de livraison / Display checkbox for creating billing address from shipping if there is no billing address. ?> |
26 | - <?php if ( $address_type_id === $shipping_option['choice'] ) : ?> |
|
26 | + <?php if ($address_type_id === $shipping_option['choice']) : ?> |
|
27 | 27 | <label class="wps-form" > |
28 | 28 | <input name="wps-shipping-to-billing" id="wps-shipping_to_billing" checked="checked" type="checkbox" /> |
29 | - <?php esc_html_e( 'Use the same address for billing', 'wpshop' ); ?> |
|
29 | + <?php esc_html_e('Use the same address for billing', 'wpshop'); ?> |
|
30 | 30 | </label> |
31 | 31 | <?php endif; ?> |
32 | 32 | |
33 | - <button class="wps_submit_address_form wps-bton-first-alignRight-rounded"><?php esc_html_e( 'Save', 'wpshop' ); ?></button> |
|
33 | + <button class="wps_submit_address_form wps-bton-first-alignRight-rounded"><?php esc_html_e('Save', 'wpshop'); ?></button> |
|
34 | 34 | </form> |
35 | 35 | </div> |
36 | -<?php elseif ( empty( $box_content ) && ( 'billing' === $address_type ) && ! $shipping_is_avalaible ) : |
|
36 | +<?php elseif (empty($box_content) && ('billing' === $address_type) && !$shipping_is_avalaible) : |
|
37 | 37 | $hide_add_btn = $shipping_is_avalaible; |
38 | 38 | ?> |
39 | 39 | |
40 | 40 | <div class="wps-address-first-address-creation-container" > |
41 | 41 | <div id="wps_address_error_container" ></div> |
42 | - <form id="wps_address_form_save_first_address" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" method="post"> |
|
42 | + <form id="wps_address_form_save_first_address" action="<?php echo admin_url('admin-ajax.php'); ?>" method="post"> |
|
43 | 43 | <input type="hidden" name="action" value="wps_save_address" /> |
44 | - <?php wp_nonce_field( 'wps_save_address' ); ?> |
|
44 | + <?php wp_nonce_field('wps_save_address'); ?> |
|
45 | 45 | <input type="hidden" name="wps-address-save-the-first" value="<?php echo $address_type; ?>" /> |
46 | - <?php echo self::display_form_fields( $address_type_id, '', 'first', '', array(), array(), array(), get_current_user_id() ); ?> |
|
46 | + <?php echo self::display_form_fields($address_type_id, '', 'first', '', array(), array(), array(), get_current_user_id()); ?> |
|
47 | 47 | |
48 | 48 | <?php |
49 | 49 | /** Check if a billing address is already save **/ |
50 | - if ( $address_type_id != $billing_option['choice'] ) : |
|
50 | + if ($address_type_id != $billing_option['choice']) : |
|
51 | 51 | ?> |
52 | 52 | <label class="wps-form" > |
53 | 53 | <input name="wps-shipping-to-billing" id="wps-shipping_to_billing" checked="checked" type="checkbox" /> |
54 | - <?php esc_html_e( 'Use the same address for billing', 'wpshop' ); ?> |
|
54 | + <?php esc_html_e('Use the same address for billing', 'wpshop'); ?> |
|
55 | 55 | </label> |
56 | 56 | <?php endif; ?> |
57 | 57 | |
58 | - <button class="wps_submit_address_form wps-bton-first-alignRight-rounded"><?php esc_html_e( 'Save', 'wpshop' ); ?></button> |
|
58 | + <button class="wps_submit_address_form wps-bton-first-alignRight-rounded"><?php esc_html_e('Save', 'wpshop'); ?></button> |
|
59 | 59 | </form> |
60 | 60 | </div> |
61 | 61 | <?php endif; ?> |
62 | 62 | |
63 | - <?php if ( ! is_admin() && $hide_add_btn ) : ?> |
|
64 | - <button data-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_load_address_form_' . $address_type_id ) ); ?>" id="wps-add-an-address-<?php echo esc_attr( $address_type_id ); ?>" class="wps-bton-third wps-add-an-address<?php echo ( empty( $box_content ) && ! $hide_add_btn ? ' hidden' : '' ); ?>" ><i class="wps-icon-plus"></i><?php printf( __( 'Add a %s', 'wpshop' ), strtolower( $address_title ) ); ?></button> |
|
63 | + <?php if (!is_admin() && $hide_add_btn) : ?> |
|
64 | + <button data-nonce="<?php echo esc_attr(wp_create_nonce('wps_load_address_form_' . $address_type_id)); ?>" id="wps-add-an-address-<?php echo esc_attr($address_type_id); ?>" class="wps-bton-third wps-add-an-address<?php echo (empty($box_content) && !$hide_add_btn ? ' hidden' : ''); ?>" ><i class="wps-icon-plus"></i><?php printf(__('Add a %s', 'wpshop'), strtolower($address_title)); ?></button> |
|
65 | 65 | <?php endif; ?> |
66 | 66 | </div> |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | $i = 0; |
3 | -if ( !empty($list_addresses) ) : |
|
4 | - foreach( $list_addresses as $address_id => $address ) : |
|
3 | +if (!empty($list_addresses)) : |
|
4 | + foreach ($list_addresses as $address_id => $address) : |
|
5 | 5 | $name_to_display = ''; |
6 | - $name_to_display .= ( !empty($address['address_last_name']) ) ? $address['address_last_name'].' ': ''; |
|
7 | - $name_to_display .= ( !empty($address['address_first_name']) ) ? $address['address_first_name'].' - ': ''; |
|
8 | - $name_to_display .= ( !empty($address['address']) ) ? $address['address'].' ': ''; |
|
9 | - $name_to_display .= ( !empty($address['postcode']) ) ? $address['postcode'].' ': ''; |
|
10 | - $name_to_display .= ( !empty($address['city']) ) ? $address['city'].' ': ''; |
|
6 | + $name_to_display .= (!empty($address['address_last_name'])) ? $address['address_last_name'] . ' ' : ''; |
|
7 | + $name_to_display .= (!empty($address['address_first_name'])) ? $address['address_first_name'] . ' - ' : ''; |
|
8 | + $name_to_display .= (!empty($address['address'])) ? $address['address'] . ' ' : ''; |
|
9 | + $name_to_display .= (!empty($address['postcode'])) ? $address['postcode'] . ' ' : ''; |
|
10 | + $name_to_display .= (!empty($address['city'])) ? $address['city'] . ' ' : ''; |
|
11 | 11 | |
12 | 12 | $class = $checked = ''; |
13 | 13 | |
14 | - $selected_address = ( !empty($_SESSION[ $type.'_address' ] ) ) ? $_SESSION[ $type.'_address' ] : ''; |
|
14 | + $selected_address = (!empty($_SESSION[$type . '_address'])) ? $_SESSION[$type . '_address'] : ''; |
|
15 | 15 | |
16 | - if( !empty($selected_address) && $address_id == $selected_address ) { |
|
16 | + if (!empty($selected_address) && $address_id == $selected_address) { |
|
17 | 17 | $class = 'wps-activ'; |
18 | 18 | $checked = 'checked="checked"'; |
19 | 19 | } else { |
20 | - if( $i == 0 && empty($selected_address) ) { |
|
20 | + if ($i == 0 && empty($selected_address)) { |
|
21 | 21 | $checked = 'checked="checked"'; |
22 | 22 | $class = 'wps-activ'; |
23 | 23 | } else { |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | ?> |
29 | 29 | <li class="<?php echo $class; ?> wps-bloc-loader"> |
30 | 30 | <span><input type="radio" class="wps_select_address" value="<?php echo $address_id; ?>" name="<?php echo $type; ?>_address_id" id="wps_select_address_<?php echo $address_id; ?>" <?php echo $checked; ?> /></span> |
31 | - <span><strong><?php echo ( ( !empty($address['address_title']) ) ? $address['address_title'] : '' ); ?></strong></span> |
|
31 | + <span><strong><?php echo ((!empty($address['address_title'])) ? $address['address_title'] : ''); ?></strong></span> |
|
32 | 32 | <span><?php echo $name_to_display; ?></span> |
33 | 33 | <span class="wps-itemList-tools"> |
34 | - <a href="" title="<?php _e( 'Edit this address', 'wpshop' ); ?>" class="wps-address-edit-address" id="wps-address-edit-address-<?php echo $address_id; ?>" data-address_type="<?php echo $address_type_id; ?>" data-nonce="<?php echo wp_create_nonce( 'wps_load_address_form_' . $address_type_id ); ?>" ><i class="wps-icon-pencil"></i></a> |
|
35 | - <a href="" title="<?php _e( 'Delete this address', 'wpshop' ); ?>" class="wps-address-delete-address" id="wps-address-delete-address-<?php echo $address_id; ?>-<?php echo $address_type_id; ?>" data-nonce="<?php echo wp_create_nonce( 'wps_delete_an_address' ); ?>" ><i class="wps-icon-trash"></i></a> |
|
34 | + <a href="" title="<?php _e('Edit this address', 'wpshop'); ?>" class="wps-address-edit-address" id="wps-address-edit-address-<?php echo $address_id; ?>" data-address_type="<?php echo $address_type_id; ?>" data-nonce="<?php echo wp_create_nonce('wps_load_address_form_' . $address_type_id); ?>" ><i class="wps-icon-pencil"></i></a> |
|
35 | + <a href="" title="<?php _e('Delete this address', 'wpshop'); ?>" class="wps-address-delete-address" id="wps-address-delete-address-<?php echo $address_id; ?>-<?php echo $address_type_id; ?>" data-nonce="<?php echo wp_create_nonce('wps_delete_an_address'); ?>" ><i class="wps-icon-trash"></i></a> |
|
36 | 36 | </span> |
37 | 37 | <div class="wps-itemList-content"> |
38 | - <?php echo wps_address::display_an_address( $address, $address_id ); ?> |
|
38 | + <?php echo wps_address::display_an_address($address, $address_id); ?> |
|
39 | 39 | </div> |
40 | 40 | </li> |
41 | 41 | <?php |
@@ -6,60 +6,60 @@ |
||
6 | 6 | * @subpackage Customer |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
13 | 13 | global $post_id; |
14 | -$post_id = ( ! empty( $order_id ) ) ? $order_id : $post_id; |
|
14 | +$post_id = (!empty($order_id)) ? $order_id : $post_id; |
|
15 | 15 | |
16 | -$order_infos = get_post_meta( $post_id, '_order_info', true ); |
|
17 | -$order_meta = get_post_meta( $post_id, '_order_postmeta', true ); |
|
16 | +$order_infos = get_post_meta($post_id, '_order_info', true); |
|
17 | +$order_meta = get_post_meta($post_id, '_order_postmeta', true); |
|
18 | 18 | $i = 0; |
19 | 19 | |
20 | -if ( ! empty( $list_addresses ) ) : |
|
21 | - foreach ( $list_addresses as $address_id => $address ) : |
|
22 | - $adress_post = get_post( $address_id ); |
|
20 | +if (!empty($list_addresses)) : |
|
21 | + foreach ($list_addresses as $address_id => $address) : |
|
22 | + $adress_post = get_post($address_id); |
|
23 | 23 | $name_to_display = $customer_name = ''; |
24 | - $customer_name = ( ! empty( $address['address_last_name'] ) ) ? $address['address_last_name'] . ' ' : ''; |
|
25 | - $customer_name .= ( ! empty( $address['address_first_name'] ) ) ? $address['address_first_name'] . ' - ': ''; |
|
26 | - $name_to_display .= ( ! empty( $address['address'] ) ) ? $address['address'] . ' ' : ''; |
|
27 | - $name_to_display .= ( ! empty( $address['postcode'] ) ) ? $address['postcode'] . ' ' : ''; |
|
28 | - $name_to_display .= ( ! empty( $address['city'] ) ) ? $address['city'] . ' ' : ''; |
|
29 | - $name_to_display .= ( ! empty( $address['country'] ) ) ? $address['country'] . ' ' : ''; |
|
24 | + $customer_name = (!empty($address['address_last_name'])) ? $address['address_last_name'] . ' ' : ''; |
|
25 | + $customer_name .= (!empty($address['address_first_name'])) ? $address['address_first_name'] . ' - ' : ''; |
|
26 | + $name_to_display .= (!empty($address['address'])) ? $address['address'] . ' ' : ''; |
|
27 | + $name_to_display .= (!empty($address['postcode'])) ? $address['postcode'] . ' ' : ''; |
|
28 | + $name_to_display .= (!empty($address['city'])) ? $address['city'] . ' ' : ''; |
|
29 | + $name_to_display .= (!empty($address['country'])) ? $address['country'] . ' ' : ''; |
|
30 | 30 | |
31 | 31 | $class = $checked = $selected_address = ''; |
32 | - if ( ! empty( $order_infos ) && ! empty( $order_infos[ $type ] ) && ! empty( $order_infos[ $type ]['address_id'] ) ) { |
|
33 | - $selected_address = $order_infos[ $type ]['address_id']; |
|
32 | + if (!empty($order_infos) && !empty($order_infos[$type]) && !empty($order_infos[$type]['address_id'])) { |
|
33 | + $selected_address = $order_infos[$type]['address_id']; |
|
34 | 34 | } |
35 | 35 | |
36 | - if ( ! empty( $selected_address ) && $address_id == $selected_address ) { |
|
36 | + if (!empty($selected_address) && $address_id == $selected_address) { |
|
37 | 37 | $class = 'wps-activ'; |
38 | 38 | $checked = 'checked="checked"'; |
39 | 39 | } else { |
40 | - if ( ( 0 === $i) && empty( $selected_address ) ) { |
|
40 | + if ((0 === $i) && empty($selected_address)) { |
|
41 | 41 | $checked = 'checked="checked"'; |
42 | 42 | $class = 'wps-activ'; |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | $url_separator = '?'; |
47 | - if ( strpos( admin_url( 'admin-ajax.php' ), '?' ) ) : |
|
47 | + if (strpos(admin_url('admin-ajax.php'), '?')) : |
|
48 | 48 | $url_separator = '&'; |
49 | 49 | endif; |
50 | 50 | ?> |
51 | - <li class="<?php echo esc_attr( $class ); ?> wps-bloc-loader wps_address_li"> |
|
52 | - <span><input type="radio" class="wps_select_address" value="<?php echo esc_attr( $address_id ); ?>" name="<?php echo esc_attr( $type ); ?>_address_id" id="wps_select_address_<?php echo esc_attr( $address_id ); ?>" <?php echo $checked; ?> /></span> |
|
53 | - <span><strong><?php echo ( ! empty( $customer_name ) ? $customer_name : '' ); ?></strong></span> |
|
54 | - <span><?php echo esc_html( $name_to_display ); ?></span> |
|
51 | + <li class="<?php echo esc_attr($class); ?> wps-bloc-loader wps_address_li"> |
|
52 | + <span><input type="radio" class="wps_select_address" value="<?php echo esc_attr($address_id); ?>" name="<?php echo esc_attr($type); ?>_address_id" id="wps_select_address_<?php echo esc_attr($address_id); ?>" <?php echo $checked; ?> /></span> |
|
53 | + <span><strong><?php echo (!empty($customer_name) ? $customer_name : ''); ?></strong></span> |
|
54 | + <span><?php echo esc_html($name_to_display); ?></span> |
|
55 | 55 | <span class="wps-itemList-tools"> |
56 | 56 | <!-- wps_delete_an_address --> |
57 | - <a href="<?php print wp_nonce_url( admin_url( 'admin-ajax.php' ) . $url_separator . 'action=wps_order_load_address_edit_form&address_id=' . $address_id . '&address_type=' . $address_type_id . '&customer_id=' . $customer_id . '&width=740&height=690', 'load_adress_edit_form', '_wpnonce' ); ?>" title="<?php _e( 'Edit this address', 'wpshop' ); ?>" class="wps-address-edit-address thickbox" id="wps-address-edit-address-<?php echo $address_id; ?>"><i class="wps-icon-pencil"></i></a> |
|
58 | - <a href="" data-nonce="<?php echo wp_create_nonce( 'delete_address_in_order_panel_' . $address_id . '-' . $address_type_id ); ?>" title="<?php _e( 'Delete this address', 'wpshop' ); ?>" class="wps-address-delete-address" id="wps-address-delete-address-<?php echo $address_id; ?>-<?php echo $address_type_id; ?>"><i class="wps-icon-trash"></i></a> |
|
57 | + <a href="<?php print wp_nonce_url(admin_url('admin-ajax.php') . $url_separator . 'action=wps_order_load_address_edit_form&address_id=' . $address_id . '&address_type=' . $address_type_id . '&customer_id=' . $customer_id . '&width=740&height=690', 'load_adress_edit_form', '_wpnonce'); ?>" title="<?php _e('Edit this address', 'wpshop'); ?>" class="wps-address-edit-address thickbox" id="wps-address-edit-address-<?php echo $address_id; ?>"><i class="wps-icon-pencil"></i></a> |
|
58 | + <a href="" data-nonce="<?php echo wp_create_nonce('delete_address_in_order_panel_' . $address_id . '-' . $address_type_id); ?>" title="<?php _e('Delete this address', 'wpshop'); ?>" class="wps-address-delete-address" id="wps-address-delete-address-<?php echo $address_id; ?>-<?php echo $address_type_id; ?>"><i class="wps-icon-trash"></i></a> |
|
59 | 59 | </span> |
60 | 60 | </li> |
61 | - <li class="wps_address_li_content"<?php echo ($checked) ? ' style="display: list-item;"' : '';?>> |
|
62 | - <?php echo wps_address::display_an_address( $address, $address_id ); ?> |
|
61 | + <li class="wps_address_li_content"<?php echo ($checked) ? ' style="display: list-item;"' : ''; ?>> |
|
62 | + <?php echo wps_address::display_an_address($address, $address_id); ?> |
|
63 | 63 | </li> |
64 | 64 | <?php |
65 | 65 | $i++; |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | /** |
3 | 3 | * File defining class for addresses initialisation |
4 | 4 | * |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | /** Check if the plugin WPS_LOCALISATION_VERSION is defined. If not defined script will be stopped here */ |
11 | -if ( !defined( 'WPS_LOCALISATION_VERSION' ) ) { |
|
12 | - die( __("You are not allowed to use this service.", 'wpeo_geoloc') ); |
|
11 | +if (!defined('WPS_LOCALISATION_VERSION')) { |
|
12 | + die(__("You are not allowed to use this service.", 'wpeo_geoloc')); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -26,49 +26,49 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function __construct() { |
28 | 28 | /** Create customer entity type on wordpress initilisation*/ |
29 | - add_action( 'init', array( $this, 'create_addresses_entity' ) ); |
|
29 | + add_action('init', array($this, 'create_addresses_entity')); |
|
30 | 30 | |
31 | 31 | /** Add filters for addresses list */ |
32 | - add_filter( 'bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, array( $this, 'addresses_list_table_bulk_actions' ) ); |
|
33 | - add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_columns', array( $this, 'list_table_header' ) ); |
|
34 | - add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_posts_custom_column' , array( $this, 'list_table_column_content' ), 10, 2 ); |
|
32 | + add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, array($this, 'addresses_list_table_bulk_actions')); |
|
33 | + add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_columns', array($this, 'list_table_header')); |
|
34 | + add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2); |
|
35 | 35 | |
36 | 36 | /** Filter search for customers */ |
37 | - add_filter( 'pre_get_posts', array( $this, 'addresses_custom_query' ) ); |
|
37 | + add_filter('pre_get_posts', array($this, 'addresses_custom_query')); |
|
38 | 38 | |
39 | 39 | /** Load */ |
40 | - add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) ); |
|
40 | + add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
41 | 41 | |
42 | 42 | |
43 | 43 | /** Add shortocde listener for addresses */ |
44 | - add_shortcode( 'wps_address_list', array( &$this, 'get_addresses') ); |
|
45 | - add_shortcode( 'wps_addresses', array( &$this, 'shortcode_callback_display_addresses') ); |
|
46 | - add_shortcode( 'wps_addresses_list', array( &$this, 'shortcode_display_addresses_list' ) ); |
|
44 | + add_shortcode('wps_address_list', array(&$this, 'get_addresses')); |
|
45 | + add_shortcode('wps_addresses', array(&$this, 'shortcode_callback_display_addresses')); |
|
46 | + add_shortcode('wps_addresses_list', array(&$this, 'shortcode_display_addresses_list')); |
|
47 | 47 | |
48 | 48 | /** Add listener for ajax actions */ |
49 | - add_action( 'wp_ajax_wps_load_address_form', array( &$this, 'wps_load_address_form') ); // DONE |
|
50 | - add_action( 'wp_ajax_wps_save_address', array( &$this, 'wps_save_address') ); // DONE |
|
51 | - add_action( 'wp_ajax_wps-address-edition-form-load', array( &$this, 'load_address_edition_form' ) ); // DONE |
|
52 | - add_action( 'wp_ajax_wps-address-display-an-address', array( &$this, 'display_address' ) ); // DONE |
|
49 | + add_action('wp_ajax_wps_load_address_form', array(&$this, 'wps_load_address_form')); // DONE |
|
50 | + add_action('wp_ajax_wps_save_address', array(&$this, 'wps_save_address')); // DONE |
|
51 | + add_action('wp_ajax_wps-address-edition-form-load', array(&$this, 'load_address_edition_form')); // DONE |
|
52 | + add_action('wp_ajax_wps-address-display-an-address', array(&$this, 'display_address')); // DONE |
|
53 | 53 | // add_action( 'wap_ajax_wps-address-save-address', array( &$this, 'wps_save_address' ) ); |
54 | - add_action( 'wp_ajax_wps-address-display-list', array( &$this, 'display_addresses_list' ) ); // DONE |
|
55 | - add_action( 'wp_ajax_wps-address-add-new', array( &$this, 'display_address_adding_form' ) ); // DONE |
|
56 | - add_action( 'wp_ajax_wps_delete_an_address', array( &$this, 'wps_delete_an_address' ) ); // DONE |
|
57 | - add_action( 'wp_ajax_wps_reload_address_interface', array( &$this, 'wps_reload_address_interface' ) ); |
|
54 | + add_action('wp_ajax_wps-address-display-list', array(&$this, 'display_addresses_list')); // DONE |
|
55 | + add_action('wp_ajax_wps-address-add-new', array(&$this, 'display_address_adding_form')); // DONE |
|
56 | + add_action('wp_ajax_wps_delete_an_address', array(&$this, 'wps_delete_an_address')); // DONE |
|
57 | + add_action('wp_ajax_wps_reload_address_interface', array(&$this, 'wps_reload_address_interface')); |
|
58 | 58 | // add_action( 'wap_ajax_display_address_form', array( &$this, '') ); |
59 | 59 | // add_action( 'wap_ajax_wps-add-an-address-in-admin', array( $this, 'wps_add_an_address_in_admin' ) ); |
60 | 60 | |
61 | 61 | /* Include the different javascript */ |
62 | - add_action( 'wp_enqueue_scripts', array( &$this, 'frontend_js' ) ); |
|
63 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_scripts' ) ); |
|
62 | + add_action('wp_enqueue_scripts', array(&$this, 'frontend_js')); |
|
63 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_scripts')); |
|
64 | 64 | |
65 | 65 | /** Add addresses metaboxes to wordpress element */ |
66 | - add_action('add_meta_boxes', array( &$this, 'addresses_metaboxes'), 1); |
|
66 | + add_action('add_meta_boxes', array(&$this, 'addresses_metaboxes'), 1); |
|
67 | 67 | } |
68 | 68 | |
69 | - function shortcode_display_addresses_list( $args ) { |
|
70 | - $addresses = $this->get_addresses_list( $args[ 'id' ] ); |
|
71 | - require_once( wpshop_tools::get_template_part( WPS_LOCALISATION_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses') ); |
|
69 | + function shortcode_display_addresses_list($args) { |
|
70 | + $addresses = $this->get_addresses_list($args['id']); |
|
71 | + require_once(wpshop_tools::get_template_part(WPS_LOCALISATION_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses')); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | */ |
77 | 77 | function create_addresses_entity() { |
78 | 78 | global $wpdb; |
79 | - $query = $wpdb->prepare( "SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, '_wpshop_entity_params' ); |
|
80 | - $entity_definition = $wpdb->get_row( $query ); |
|
81 | - $entity_params = !empty( $entity_definition ) && !empty( $entity_definition->meta_value ) ? unserialize( $entity_definition->meta_value ) : null; |
|
79 | + $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, '_wpshop_entity_params'); |
|
80 | + $entity_definition = $wpdb->get_row($query); |
|
81 | + $entity_params = !empty($entity_definition) && !empty($entity_definition->meta_value) ? unserialize($entity_definition->meta_value) : null; |
|
82 | 82 | |
83 | 83 | $post_type_params = array( |
84 | 84 | 'labels' => array( |
85 | - 'name' => __( 'Addresses' , 'wpshop' ), |
|
86 | - 'singular_name' => __( 'Address', 'wpshop' ), |
|
87 | - 'add_new_item' => __( 'New address', 'wpshop' ), |
|
88 | - 'add_new' => __( 'New address', 'wpshop' ), |
|
89 | - 'edit_item' => __( 'Edit address', 'wpshop' ), |
|
90 | - 'new_item' => __( 'New address', 'wpshop' ), |
|
91 | - 'view_item' => __( 'View address', 'wpshop' ), |
|
92 | - 'search_items' => __( 'Search in addresses', 'wpshop' ), |
|
93 | - 'not_found' => __( 'No address found', 'wpshop' ), |
|
94 | - 'not_found_in_trash' => __( 'No address founded in trash', 'wpshop' ), |
|
85 | + 'name' => __('Addresses', 'wpshop'), |
|
86 | + 'singular_name' => __('Address', 'wpshop'), |
|
87 | + 'add_new_item' => __('New address', 'wpshop'), |
|
88 | + 'add_new' => __('New address', 'wpshop'), |
|
89 | + 'edit_item' => __('Edit address', 'wpshop'), |
|
90 | + 'new_item' => __('New address', 'wpshop'), |
|
91 | + 'view_item' => __('View address', 'wpshop'), |
|
92 | + 'search_items' => __('Search in addresses', 'wpshop'), |
|
93 | + 'not_found' => __('No address found', 'wpshop'), |
|
94 | + 'not_found_in_trash' => __('No address founded in trash', 'wpshop'), |
|
95 | 95 | 'parent_item_colon' => '', |
96 | 96 | ), |
97 | 97 | 'description' => '', |
98 | - 'supports' => !empty($entity_params['support']) ? $entity_params['support'] : array( 'title' ), |
|
98 | + 'supports' => !empty($entity_params['support']) ? $entity_params['support'] : array('title'), |
|
99 | 99 | 'hierarchical' => false, |
100 | 100 | 'public' => false, |
101 | 101 | 'show_ui' => false, |
102 | - 'show_in_menu' => 'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
102 | + 'show_in_menu' => 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
103 | 103 | 'show_in_nav_menus' => false, |
104 | 104 | 'show_in_admin_bar' => false, |
105 | 105 | 'can_export' => false, |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'publicly_queryable' => false, |
109 | 109 | 'rewrite' => false, |
110 | 110 | ); |
111 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $post_type_params ); |
|
111 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $post_type_params); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return array The new action list to use into customer list table |
120 | 120 | */ |
121 | - function addresses_list_table_bulk_actions( $actions ){ |
|
122 | - unset( $actions[ 'edit' ] ); |
|
123 | - unset( $actions[ 'trash' ] ); |
|
121 | + function addresses_list_table_bulk_actions($actions) { |
|
122 | + unset($actions['edit']); |
|
123 | + unset($actions['trash']); |
|
124 | 124 | |
125 | 125 | return $actions; |
126 | 126 | } |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return array The new header to display |
134 | 134 | */ |
135 | - function list_table_header( $current_header ) { |
|
136 | - unset( $current_header['title'] ); |
|
137 | - unset( $current_header['date'] ); |
|
135 | + function list_table_header($current_header) { |
|
136 | + unset($current_header['title']); |
|
137 | + unset($current_header['date']); |
|
138 | 138 | |
139 | - $current_header['address_identifier'] = __( 'Address ID', 'wpshop' ); |
|
140 | - $current_header['address_element_name'] = __( 'Element', 'wpshop' ); |
|
141 | - $current_header['address_type'] = __( 'Address type', 'wpshop' ); |
|
142 | - $current_header['address_content'] = __( 'Address', 'wpshop' ); |
|
139 | + $current_header['address_identifier'] = __('Address ID', 'wpshop'); |
|
140 | + $current_header['address_element_name'] = __('Element', 'wpshop'); |
|
141 | + $current_header['address_type'] = __('Address type', 'wpshop'); |
|
142 | + $current_header['address_content'] = __('Address', 'wpshop'); |
|
143 | 143 | |
144 | 144 | return $current_header; |
145 | 145 | } |
@@ -150,50 +150,50 @@ discard block |
||
150 | 150 | * @param string $column The column identifier to modify output for |
151 | 151 | * @param integer $post_id The current post identifier |
152 | 152 | */ |
153 | - function list_table_column_content( $column, $post_id ) { |
|
153 | + function list_table_column_content($column, $post_id) { |
|
154 | 154 | global $wpdb; |
155 | 155 | |
156 | 156 | /** Get wp_users idenfifier from customer id */ |
157 | - $query = $wpdb->prepare( "SELECT PA.post_parent AS post_parent, PA.post_author AS post_author, PC.ID AS parent_id, PC.post_title AS post_title, PC.post_type AS post_type FROM {$wpdb->posts} AS PC INNER JOIN {$wpdb->posts} AS PA ON ( PA.post_parent = PC.ID ) WHERE PA.ID = %d", $post_id); |
|
158 | - $address_associated_element = $wpdb->get_row( $query ); |
|
157 | + $query = $wpdb->prepare("SELECT PA.post_parent AS post_parent, PA.post_author AS post_author, PC.ID AS parent_id, PC.post_title AS post_title, PC.post_type AS post_type FROM {$wpdb->posts} AS PC INNER JOIN {$wpdb->posts} AS PA ON ( PA.post_parent = PC.ID ) WHERE PA.ID = %d", $post_id); |
|
158 | + $address_associated_element = $wpdb->get_row($query); |
|
159 | 159 | |
160 | 160 | /** SCOTCH - Define the associated element type - SCOTCH */ |
161 | 161 | $address_associated_element_type = $address_associated_element->post_type; |
162 | - if ( $address_associated_element->post_parent == $address_associated_element->post_author ) { |
|
162 | + if ($address_associated_element->post_parent == $address_associated_element->post_author) { |
|
163 | 163 | $address_associated_element_type = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS; |
164 | 164 | } |
165 | 165 | |
166 | 166 | /** Get the associated element definition */ |
167 | - $associated_element_definition = get_post_type_object( $address_associated_element_type ); |
|
167 | + $associated_element_definition = get_post_type_object($address_associated_element_type); |
|
168 | 168 | |
169 | 169 | /** Get address informations */ |
170 | - $address_meta = get_post_meta( $post_id ); |
|
170 | + $address_meta = get_post_meta($post_id); |
|
171 | 171 | |
172 | 172 | /** Get user data */ |
173 | - switch ( $address_associated_element_type ) { |
|
173 | + switch ($address_associated_element_type) { |
|
174 | 174 | case WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS: |
175 | - $associated_customer = get_userdata( $address_associated_element->post_author ); |
|
175 | + $associated_customer = get_userdata($address_associated_element->post_author); |
|
176 | 176 | $customer_name_to_display = $associated_customer->display_name; |
177 | - if ( !empty( $associated_customer->first_name ) && !empty( $associated_customer->last_name ) ) { |
|
178 | - $customer_name_to_display = $associated_customer->last_name . ' ' . $associated_customer->first_name ; |
|
177 | + if (!empty($associated_customer->first_name) && !empty($associated_customer->last_name)) { |
|
178 | + $customer_name_to_display = $associated_customer->last_name . ' ' . $associated_customer->first_name; |
|
179 | 179 | } |
180 | - $element_main_infos = ( !empty( $associated_element_definition ) && !empty( $associated_element_definition->labels ) && !empty( $associated_element_definition->labels->singular_name ) ? $associated_element_definition->labels->singular_name . ' - ' : "" ) . $address_associated_element->parent_id . ' - ' . $customer_name_to_display; |
|
180 | + $element_main_infos = (!empty($associated_element_definition) && !empty($associated_element_definition->labels) && !empty($associated_element_definition->labels->singular_name) ? $associated_element_definition->labels->singular_name . ' - ' : "") . $address_associated_element->parent_id . ' - ' . $customer_name_to_display; |
|
181 | 181 | break; |
182 | 182 | |
183 | 183 | default: |
184 | - $element_main_infos = ( !empty( $associated_element_definition ) && !empty( $associated_element_definition->labels ) && !empty( $associated_element_definition->labels->singular_name ) ? $associated_element_definition->labels->singular_name . ' - ' : "" ) . $address_associated_element->parent_id . ' - ' . $address_associated_element->post_title; |
|
184 | + $element_main_infos = (!empty($associated_element_definition) && !empty($associated_element_definition->labels) && !empty($associated_element_definition->labels->singular_name) ? $associated_element_definition->labels->singular_name . ' - ' : "") . $address_associated_element->parent_id . ' - ' . $address_associated_element->post_title; |
|
185 | 185 | break; |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** Switch current column for custom case */ |
189 | 189 | $use_template = true; |
190 | - switch ( $column ) { } |
|
190 | + switch ($column) { } |
|
191 | 191 | |
192 | 192 | /** Require the template for displaying the current column */ |
193 | - if ( $use_template ) { |
|
194 | - $template = wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses_listtable/' . $column ); |
|
195 | - if ( is_file( $template ) ) { |
|
196 | - require( $template ); |
|
193 | + if ($use_template) { |
|
194 | + $template = wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'backend', 'addresses_listtable/' . $column); |
|
195 | + if (is_file($template)) { |
|
196 | + require($template); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param WP_Object $query The current query launched for retrieving addresses |
205 | 205 | */ |
206 | - function addresses_custom_query( $query ) { |
|
207 | - if( is_admin() && $query->query['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && $query->is_main_query() ) { |
|
208 | - add_filter( 'posts_orderby', array( $this, 'addresses_custom_query_order' ) ); |
|
206 | + function addresses_custom_query($query) { |
|
207 | + if (is_admin() && $query->query['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && $query->is_main_query()) { |
|
208 | + add_filter('posts_orderby', array($this, 'addresses_custom_query_order')); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
@@ -227,15 +227,15 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @since 1.0 - WPShop 1.3.7.0 |
229 | 229 | */ |
230 | - function addresses_metaboxes( $post ) { |
|
230 | + function addresses_metaboxes($post) { |
|
231 | 231 | global $wpdb; |
232 | 232 | |
233 | - $query = $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = %s", $post, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES ); |
|
234 | - $parent = $wpdb->get_var( $query ); |
|
235 | - if ( !empty( $parent ) ) { |
|
236 | - $address_meta_box_checking = get_post_meta( $parent, '_wpshop_entity_attached_address', true); |
|
237 | - if ( !empty($address_meta_box_checking) ) { |
|
238 | - add_meta_box( 'wps_attached_addresses', __('Attached addresses', 'wpshop'), array( &$this, 'addresses_metaboxes_content' ), $post, 'normal', 'default' ); |
|
233 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s AND post_type = %s", $post, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
234 | + $parent = $wpdb->get_var($query); |
|
235 | + if (!empty($parent)) { |
|
236 | + $address_meta_box_checking = get_post_meta($parent, '_wpshop_entity_attached_address', true); |
|
237 | + if (!empty($address_meta_box_checking)) { |
|
238 | + add_meta_box('wps_attached_addresses', __('Attached addresses', 'wpshop'), array(&$this, 'addresses_metaboxes_content'), $post, 'normal', 'default'); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @since 1.0 - WPShop 1.3.7.0 |
250 | 250 | */ |
251 | - function addresses_metaboxes_content( $post, $args ) { |
|
252 | - $addresses = self::get_addresses_list( $post->ID ); |
|
253 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "metabox") ); |
|
251 | + function addresses_metaboxes_content($post, $args) { |
|
252 | + $addresses = self::get_addresses_list($post->ID); |
|
253 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "metabox")); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -259,19 +259,19 @@ discard block |
||
259 | 259 | * @since 1.0 - WPShop 1.3.7.0 |
260 | 260 | */ |
261 | 261 | function frontend_js() { |
262 | - wp_register_style( 'wps_address_frontend_css', WPS_ADDRESS_URL . '/assets/css/frontend.css' ); |
|
263 | - wp_enqueue_style( 'wps_address_frontend_css' ); |
|
264 | - wp_enqueue_script( 'wps_address_js', WPS_ADDRESS_URL . '/assets/frontend/js/wps_address.js', array( 'jquery', 'jquery-form' ) ); |
|
262 | + wp_register_style('wps_address_frontend_css', WPS_ADDRESS_URL . '/assets/css/frontend.css'); |
|
263 | + wp_enqueue_style('wps_address_frontend_css'); |
|
264 | + wp_enqueue_script('wps_address_js', WPS_ADDRESS_URL . '/assets/frontend/js/wps_address.js', array('jquery', 'jquery-form')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | function admin_scripts() { |
268 | 268 | global $current_screen; |
269 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) |
|
269 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) |
|
270 | 270 | return; |
271 | 271 | |
272 | - wp_enqueue_script( 'wps_address_js', WPS_ADDRESS_URL . '/assets/backend/js/wps_address.js', array( 'jquery', 'jquery-form' ) ); |
|
273 | - wp_register_style( 'wps_address_backend_css', WPS_ADDRESS_URL . '/assets/backend/css/backend.css'/*, array( '' )*/ ); |
|
274 | - wp_enqueue_style( 'wps_address_backend_css' ); |
|
272 | + wp_enqueue_script('wps_address_js', WPS_ADDRESS_URL . '/assets/backend/js/wps_address.js', array('jquery', 'jquery-form')); |
|
273 | + wp_register_style('wps_address_backend_css', WPS_ADDRESS_URL . '/assets/backend/css/backend.css'/*, array( '' )*/); |
|
274 | + wp_enqueue_style('wps_address_backend_css'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** Load module/addon automatically to existing template list |
@@ -280,11 +280,11 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return array The template with new elements |
282 | 282 | */ |
283 | - function custom_template_load( $templates ) { |
|
284 | - include( WPS_LOCALISATION_TEMPLATES_MAIN_DIR . 'wpshop/main_elements.tpl.php'); |
|
283 | + function custom_template_load($templates) { |
|
284 | + include(WPS_LOCALISATION_TEMPLATES_MAIN_DIR . 'wpshop/main_elements.tpl.php'); |
|
285 | 285 | |
286 | 286 | $wpshop_display = new wpshop_display(); |
287 | - $templates = $wpshop_display->add_modules_template_to_internal( $tpl_element, $templates ); |
|
287 | + $templates = $wpshop_display->add_modules_template_to_internal($tpl_element, $templates); |
|
288 | 288 | unset($tpl_element); |
289 | 289 | |
290 | 290 | return $templates; |
@@ -298,23 +298,23 @@ discard block |
||
298 | 298 | * @param Integer $user_id |
299 | 299 | * @return Ambigous <multitype:, mixed, string, boolean, unknown, string> |
300 | 300 | */ |
301 | - public static function get_addresses_list_no_hidden_attributes( $user_id ) { |
|
301 | + public static function get_addresses_list_no_hidden_attributes($user_id) { |
|
302 | 302 | global $wpdb; |
303 | - $query = $wpdb->prepare( 'SELECT ID FROM '. $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id ); |
|
304 | - $addresses_ids = $wpdb->get_col( $query ); |
|
305 | - $address_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ); |
|
303 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id); |
|
304 | + $addresses_ids = $wpdb->get_col($query); |
|
305 | + $address_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
306 | 306 | $addresses_result = array(); |
307 | - foreach( $addresses_ids as $address_id ) { |
|
308 | - $address_post_meta = get_post_meta( $address_id, '_wpshop_address_metadata', true ); |
|
309 | - $address_type_id = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true ); |
|
310 | - $query = $wpdb->prepare( 'SELECT attribute_id FROM '.WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type_id, $address_entity_id ); |
|
311 | - $attributes_ids = $wpdb->get_col( $query ); |
|
312 | - if( !empty( $attributes_ids ) ) { |
|
313 | - foreach( $attributes_ids as $attributes_id ) { |
|
314 | - $attribute_def = wpshop_attributes::getElement( $attributes_id, '"valid"', 'id' ); |
|
315 | - if( !empty( $attribute_def ) && !empty( $address_post_meta[ $attribute_def->code ] ) && $attribute_def->frontend_input != 'hidden' ) { |
|
316 | - $addresses_result[ $address_type_id ][ $address_id ][ $attribute_def->code ]['label'] = stripslashes( __( $attribute_def->frontend_label , 'wpshop' ) ); |
|
317 | - $addresses_result[ $address_type_id ][ $address_id ][ $attribute_def->code ]['value'] = stripslashes( __( $address_post_meta[ $attribute_def->code ], 'wpshop' ) ); |
|
307 | + foreach ($addresses_ids as $address_id) { |
|
308 | + $address_post_meta = get_post_meta($address_id, '_wpshop_address_metadata', true); |
|
309 | + $address_type_id = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
310 | + $query = $wpdb->prepare('SELECT attribute_id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type_id, $address_entity_id); |
|
311 | + $attributes_ids = $wpdb->get_col($query); |
|
312 | + if (!empty($attributes_ids)) { |
|
313 | + foreach ($attributes_ids as $attributes_id) { |
|
314 | + $attribute_def = wpshop_attributes::getElement($attributes_id, '"valid"', 'id'); |
|
315 | + if (!empty($attribute_def) && !empty($address_post_meta[$attribute_def->code]) && $attribute_def->frontend_input != 'hidden') { |
|
316 | + $addresses_result[$address_type_id][$address_id][$attribute_def->code]['label'] = stripslashes(__($attribute_def->frontend_label, 'wpshop')); |
|
317 | + $addresses_result[$address_type_id][$address_id][$attribute_def->code]['value'] = stripslashes(__($address_post_meta[$attribute_def->code], 'wpshop')); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | } |
@@ -327,16 +327,16 @@ discard block |
||
327 | 327 | * @param Integer $user_id |
328 | 328 | * @return Ambigous <multitype:, mixed, string, boolean, unknown, string> |
329 | 329 | */ |
330 | - public static function get_addresses_list( $user_id ) { |
|
330 | + public static function get_addresses_list($user_id) { |
|
331 | 331 | global $wpdb; |
332 | 332 | $addresses_list = array(); |
333 | - $query = $wpdb->prepare( 'SELECT ID FROM '. $wpdb->posts. ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id ); |
|
334 | - $addresses = $wpdb->get_results( $query ); |
|
335 | - foreach( $addresses as $address ) { |
|
336 | - $address_post_meta = get_post_meta( $address->ID, '_wpshop_address_metadata', true); |
|
337 | - $address_type_post_meta = get_post_meta( $address->ID, '_wpshop_address_attribute_set_id', true); |
|
333 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_parent = %s', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $user_id); |
|
334 | + $addresses = $wpdb->get_results($query); |
|
335 | + foreach ($addresses as $address) { |
|
336 | + $address_post_meta = get_post_meta($address->ID, '_wpshop_address_metadata', true); |
|
337 | + $address_type_post_meta = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); |
|
338 | 338 | |
339 | - if( !empty($address_post_meta) && !empty($address_type_post_meta) ) { |
|
339 | + if (!empty($address_post_meta) && !empty($address_type_post_meta)) { |
|
340 | 340 | $addresses_list[$address_type_post_meta][$address->ID] = $address_post_meta; |
341 | 341 | } |
342 | 342 | } |
@@ -344,58 +344,58 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | /** Display Address**/ |
347 | - public static function display_an_address( $address, $address_id = '', $address_type_id = '' ) { |
|
347 | + public static function display_an_address($address, $address_id = '', $address_type_id = '') { |
|
348 | 348 | global $wpdb; |
349 | 349 | $countries = unserialize(WPSHOP_COUNTRY_LIST); |
350 | 350 | $output = ''; |
351 | - if ( !empty($address) ) { |
|
351 | + if (!empty($address)) { |
|
352 | 352 | $has_model = false; |
353 | 353 | |
354 | 354 | /** Check if a model exists**/ |
355 | - if ( !empty($address_id) || !empty( $address_type_id ) ) { |
|
356 | - $address_type = ( !empty($address_type_id) ) ? $address_type_id : get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true ); |
|
357 | - if( !empty($address_type) ) { |
|
355 | + if (!empty($address_id) || !empty($address_type_id)) { |
|
356 | + $address_type = (!empty($address_type_id)) ? $address_type_id : get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
357 | + if (!empty($address_type)) { |
|
358 | 358 | /** Shipping & Billing option **/ |
359 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
360 | - if ( !empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $address_type && !empty($shipping_option['display_model']) ) { |
|
361 | - $display_model = $shipping_option['display_model']; |
|
359 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
360 | + if (!empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $address_type && !empty($shipping_option['display_model'])) { |
|
361 | + $display_model = $shipping_option['display_model']; |
|
362 | 362 | $has_model = true; |
363 | 363 | |
364 | 364 | } |
365 | 365 | else { |
366 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
367 | - if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type && !empty($billing_option['display_model']) ) { |
|
368 | - $display_model = $billing_option['display_model']; |
|
366 | + $billing_option = get_option('wpshop_billing_address'); |
|
367 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type && !empty($billing_option['display_model'])) { |
|
368 | + $display_model = $billing_option['display_model']; |
|
369 | 369 | $has_model = true; |
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | 374 | $has_model = false; |
375 | - if ( $has_model ) { |
|
376 | - foreach( $display_model as $group_id => $group ) { |
|
377 | - foreach( $group as $att_id => $att ) { |
|
378 | - if ( !empty($att) ) { |
|
375 | + if ($has_model) { |
|
376 | + foreach ($display_model as $group_id => $group) { |
|
377 | + foreach ($group as $att_id => $att) { |
|
378 | + if (!empty($att)) { |
|
379 | 379 | // Get attribute def |
380 | - $attribute_id = str_replace( 'attribute_', '' , $att ); |
|
381 | - if( !empty($attribute_id) ) { |
|
382 | - $attribute_def = wpshop_attributes::getElement( $attribute_id, '"valid"', 'id' ); |
|
383 | - if ( !empty($attribute_def) ) { |
|
384 | - if ( $attribute_def->frontend_input == 'select' ) { |
|
385 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d',$address[ $attribute_def->code] ); |
|
386 | - $output .= '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $wpdb->get_var( $query ), 'wpshop' ).' '; |
|
380 | + $attribute_id = str_replace('attribute_', '', $att); |
|
381 | + if (!empty($attribute_id)) { |
|
382 | + $attribute_def = wpshop_attributes::getElement($attribute_id, '"valid"', 'id'); |
|
383 | + if (!empty($attribute_def)) { |
|
384 | + if ($attribute_def->frontend_input == 'select') { |
|
385 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $address[$attribute_def->code]); |
|
386 | + $output .= '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . __($wpdb->get_var($query), 'wpshop') . ' '; |
|
387 | 387 | } |
388 | - elseif( $attribute_def->frontend_verification == 'country' ) { |
|
389 | - $output .= ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.__( $countries[ $address[ $attribute_def->code] ], 'wpshop' ).' ' : ''; |
|
388 | + elseif ($attribute_def->frontend_verification == 'country') { |
|
389 | + $output .= (!empty($countries[$address[$attribute_def->code]])) ? '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . __($countries[$address[$attribute_def->code]], 'wpshop') . ' ' : ''; |
|
390 | 390 | } |
391 | 391 | else { |
392 | - $output .= ( !empty($address[ $attribute_def->code]) ) ? '<strong>'.__( $attribute_def->frontend_label, 'wpshop').' :</strong> '.$address[ $attribute_def->code].' ' : ' '; |
|
392 | + $output .= (!empty($address[$attribute_def->code])) ? '<strong>' . __($attribute_def->frontend_label, 'wpshop') . ' :</strong> ' . $address[$attribute_def->code] . ' ' : ' '; |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | //End Line |
396 | - $next_element = next( $display_model[$group_id] ); |
|
397 | - $end_line = strstr( $next_element, '-end-line-', true ); |
|
398 | - if ( !empty($end_line) && $end_line == 'wps-attribute' ) { |
|
396 | + $next_element = next($display_model[$group_id]); |
|
397 | + $end_line = strstr($next_element, '-end-line-', true); |
|
398 | + if (!empty($end_line) && $end_line == 'wps-attribute') { |
|
399 | 399 | $output .= '<br/>'; |
400 | 400 | } |
401 | 401 | } |
@@ -404,29 +404,29 @@ discard block |
||
404 | 404 | } |
405 | 405 | } |
406 | 406 | else { |
407 | - if( !empty($address_type) ) { |
|
407 | + if (!empty($address_type)) { |
|
408 | 408 | $tmp_array = array(); |
409 | - $address_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS ); |
|
410 | - $query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type, $address_entity_id); |
|
411 | - $attributes_ids = $wpdb->get_results( $query ); |
|
412 | - if( !empty($attributes_ids) ) { |
|
413 | - foreach( $attributes_ids as $attributes_id ) { |
|
414 | - if ( !empty( $attributes_id->attribute_id ) ) { |
|
415 | - $attribute_def = wpshop_attributes::getElement( $attributes_id->attribute_id, '"valid"', 'id' ); |
|
416 | - if( $attribute_def->frontend_input != 'hidden') { |
|
417 | - if( !empty($attribute_def) && !empty($address[ $attribute_def->code ]) && $attribute_def->frontend_input != 'hidden' ) { |
|
418 | - $tmp_array[ $attribute_def->code]['label'] = stripslashes( __( $attribute_def->frontend_label , 'wpshop' ) ); |
|
419 | - |
|
420 | - if( $attribute_def->frontend_verification == 'country' ) { |
|
421 | - $tmp_array[ $attribute_def->code]['value'] = ( !empty($countries[ $address[ $attribute_def->code] ]) ) ? stripslashes( __( $countries[ $address[ $attribute_def->code] ], 'wpshop' ) ) : stripslashes( $address[ $attribute_def->code ] ); |
|
409 | + $address_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
410 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_set_id = %d AND entity_type_id = %d ORDER BY position', $address_type, $address_entity_id); |
|
411 | + $attributes_ids = $wpdb->get_results($query); |
|
412 | + if (!empty($attributes_ids)) { |
|
413 | + foreach ($attributes_ids as $attributes_id) { |
|
414 | + if (!empty($attributes_id->attribute_id)) { |
|
415 | + $attribute_def = wpshop_attributes::getElement($attributes_id->attribute_id, '"valid"', 'id'); |
|
416 | + if ($attribute_def->frontend_input != 'hidden') { |
|
417 | + if (!empty($attribute_def) && !empty($address[$attribute_def->code]) && $attribute_def->frontend_input != 'hidden') { |
|
418 | + $tmp_array[$attribute_def->code]['label'] = stripslashes(__($attribute_def->frontend_label, 'wpshop')); |
|
419 | + |
|
420 | + if ($attribute_def->frontend_verification == 'country') { |
|
421 | + $tmp_array[$attribute_def->code]['value'] = (!empty($countries[$address[$attribute_def->code]])) ? stripslashes(__($countries[$address[$attribute_def->code]], 'wpshop')) : stripslashes($address[$attribute_def->code]); |
|
422 | 422 | } |
423 | - elseif( in_array( $attribute_def->frontend_input, array('select', 'checkbox') ) ) { |
|
424 | - $query = $wpdb->prepare( 'SELECT label FROM '. WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE id = %d', $address[ $attribute_def->code] ); |
|
425 | - $value = $wpdb->get_var( $query ); |
|
426 | - $tmp_array[ $attribute_def->code]['value'] = ( !empty($value) ) ? stripslashes( __( $value, 'wpshop' ) ) : ''; |
|
423 | + elseif (in_array($attribute_def->frontend_input, array('select', 'checkbox'))) { |
|
424 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $address[$attribute_def->code]); |
|
425 | + $value = $wpdb->get_var($query); |
|
426 | + $tmp_array[$attribute_def->code]['value'] = (!empty($value)) ? stripslashes(__($value, 'wpshop')) : ''; |
|
427 | 427 | } |
428 | 428 | else { |
429 | - $tmp_array[ $attribute_def->code]['value'] = stripslashes( __( $address[ $attribute_def->code ], 'wpshop' ) ); |
|
429 | + $tmp_array[$attribute_def->code]['value'] = stripslashes(__($address[$attribute_def->code], 'wpshop')); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | } |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | $address = $tmp_array; |
436 | 436 | } |
437 | 437 | } |
438 | - foreach( $address as $element_code => $element_value ) { |
|
439 | - if( is_array($element_value) ) { |
|
440 | - $output .= '<span class="wps-'.$element_code.'"><strong>' .stripslashes( $element_value['label'] ). ' :</strong> ' .stripslashes( $element_value['value'] ). '</span>'; |
|
438 | + foreach ($address as $element_code => $element_value) { |
|
439 | + if (is_array($element_value)) { |
|
440 | + $output .= '<span class="wps-' . $element_code . '"><strong>' . stripslashes($element_value['label']) . ' :</strong> ' . stripslashes($element_value['value']) . '</span>'; |
|
441 | 441 | } |
442 | 442 | else { |
443 | - $output .= '<span class="wps-'.$element_code.'">' .stripslashes( $element_value ). '</span>'; |
|
443 | + $output .= '<span class="wps-' . $element_code . '">' . stripslashes($element_value) . '</span>'; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | } |
@@ -457,13 +457,13 @@ discard block |
||
457 | 457 | * |
458 | 458 | * @return string The complete html output for customer addresses |
459 | 459 | */ |
460 | - function get_addresses_by_type( $address_type_id, $address_type_title, $args = array() ) { |
|
460 | + function get_addresses_by_type($address_type_id, $address_type_title, $args = array()) { |
|
461 | 461 | global $wpdb; |
462 | 462 | /** Get current customer addresses list */ |
463 | - if ( is_admin() ) { |
|
464 | - $post = !empty( $_GET['post'] ) ? (array) $_GET['post'] : array(); |
|
465 | - $post = get_post( $post ); |
|
466 | - if ( !empty($post->post_parent) ) { |
|
463 | + if (is_admin()) { |
|
464 | + $post = !empty($_GET['post']) ? (array)$_GET['post'] : array(); |
|
465 | + $post = get_post($post); |
|
466 | + if (!empty($post->post_parent)) { |
|
467 | 467 | $customer_id = $post->post_parent; |
468 | 468 | } |
469 | 469 | else { |
@@ -482,85 +482,85 @@ discard block |
||
482 | 482 | AND ADDRESSES.post_parent = %d |
483 | 483 | AND ADDRESSES_META.meta_key = %s |
484 | 484 | AND ADDRESSES_META.meta_value = %d", |
485 | - WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $customer_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_attribute_set_id', $address_type_id); |
|
485 | + WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, $customer_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $address_type_id); |
|
486 | 486 | $addresses = $wpdb->get_results($query); |
487 | 487 | $addresses_list = ''; |
488 | 488 | |
489 | 489 | |
490 | 490 | /** Initialize */ |
491 | 491 | $tpl_component = array(); |
492 | - $tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = ( !empty($args) && !empty($args['first']) && $args['first'] ) ? __('Your address', 'wpshop') : $address_type_title; |
|
492 | + $tpl_component['CUSTOMER_ADDRESS_TYPE_TITLE'] = (!empty($args) && !empty($args['first']) && $args['first']) ? __('Your address', 'wpshop') : $address_type_title; |
|
493 | 493 | $tpl_component['LOADING_ICON'] = WPSHOP_LOADING_ICON; |
494 | 494 | $tpl_component['ADDRESS_BUTTONS'] = ''; |
495 | - if( count($addresses) > 0 ) { |
|
496 | - $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id; |
|
495 | + if (count($addresses) > 0) { |
|
496 | + $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=add_address&type=' . $address_type_id; |
|
497 | 497 | } |
498 | 498 | else { |
499 | - $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&'). 'action=add_address&type=' .$address_type_id .'&first'; |
|
499 | + $tpl_component['ADD_NEW_ADDRESS_LINK'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=add_address&type=' . $address_type_id . '&first'; |
|
500 | 500 | } |
501 | - $tpl_component['ADDRESS_TYPE'] = ( !empty($address_type_title) && ($address_type_title == __('Shipping address', 'wpshop'))) ? 'shipping_address' : 'billing_address'; |
|
502 | - $tpl_component['ADD_NEW_ADDRESS_TITLE'] = sprintf(__('Add a new %s', 'wpshop'), ( ( !empty($args) && !empty($args['first']) && $args['first'] ) ? __('address', 'wpshop') : $address_type_title )); |
|
501 | + $tpl_component['ADDRESS_TYPE'] = (!empty($address_type_title) && ($address_type_title == __('Shipping address', 'wpshop'))) ? 'shipping_address' : 'billing_address'; |
|
502 | + $tpl_component['ADD_NEW_ADDRESS_TITLE'] = sprintf(__('Add a new %s', 'wpshop'), ((!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : $address_type_title)); |
|
503 | 503 | |
504 | 504 | |
505 | 505 | /** Read customer list */ |
506 | - if( count($addresses) > 0 ) { |
|
506 | + if (count($addresses) > 0) { |
|
507 | 507 | /** Get the fields for addresses */ |
508 | 508 | $address_fields = wps_address::get_addresss_form_fields_by_type($address_type_id); |
509 | 509 | $first = true; |
510 | 510 | $tpl_component['ADDRESS_COMBOBOX_OPTION'] = ''; |
511 | 511 | $nb_of_addresses = 0; |
512 | - foreach ( $addresses as $address ) { |
|
512 | + foreach ($addresses as $address) { |
|
513 | 513 | // Display the addresses |
514 | 514 | /** If there isn't address in SESSION we display the first address of list by default */ |
515 | - if ( empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $first && !is_admin() ) { |
|
515 | + if (empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $first && !is_admin()) { |
|
516 | 516 | $address_id = $address->ID; |
517 | - if ( !is_admin() ) { |
|
517 | + if (!is_admin()) { |
|
518 | 518 | $_SESSION[$tpl_component['ADDRESS_TYPE']] = $address->ID; |
519 | 519 | } |
520 | 520 | } |
521 | 521 | else { |
522 | - $address_id = ( !empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) ) ? $_SESSION[$tpl_component['ADDRESS_TYPE']] : ''; |
|
522 | + $address_id = (!empty($_SESSION[$tpl_component['ADDRESS_TYPE']])) ? $_SESSION[$tpl_component['ADDRESS_TYPE']] : ''; |
|
523 | 523 | } |
524 | - $address_selected_infos = get_post_meta($address_id, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
525 | - $address_infos = get_post_meta($address->ID, '_'.WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS.'_metadata', true); |
|
524 | + $address_selected_infos = get_post_meta($address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
525 | + $address_infos = get_post_meta($address->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', true); |
|
526 | 526 | |
527 | 527 | |
528 | - if ( !empty($address_infos) ) { |
|
528 | + if (!empty($address_infos)) { |
|
529 | 529 | |
530 | 530 | $tpl_component['ADDRESS_ID'] = $address->ID; |
531 | 531 | /** If no address was selected, we select the first of the list **/ |
532 | 532 | $tpl_component['CUSTOMER_ADDRESS_CONTENT'] = self::display_an_address($address_fields, $address_selected_infos, $address_id); |
533 | 533 | $tpl_component['ADDRESS_BUTTONS'] = wpshop_display::display_template_element('addresses_box_actions_button_edit', $tpl_component); |
534 | - $tpl_component['choosen_address_LINK_EDIT'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?')===false ? '?' : '&') . 'action=editAddress&id='.$address_id; |
|
534 | + $tpl_component['choosen_address_LINK_EDIT'] = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))) . (strpos(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))), '?') === false ? '?' : '&') . 'action=editAddress&id=' . $address_id; |
|
535 | 535 | $tpl_component['DEFAULT_ADDRESS_ID'] = $address_id; |
536 | 536 | $tpl_component['ADRESS_CONTAINER_CLASS'] = ' wpshop_customer_adress_container_' . $address->ID; |
537 | 537 | $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = wpshop_display::display_template_element('display_address_container', $tpl_component); |
538 | - if ( empty($tpl_component['CUSTOMER_ADDRESS_CONTENT']) ) { |
|
539 | - $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = '<span style="color:red;">'.__('No data','wpshop').'</span>'; |
|
538 | + if (empty($tpl_component['CUSTOMER_ADDRESS_CONTENT'])) { |
|
539 | + $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = '<span style="color:red;">' . __('No data', 'wpshop') . '</span>'; |
|
540 | 540 | } |
541 | 541 | |
542 | - $tpl_component['ADDRESS_COMBOBOX_OPTION'] .= '<option value="' .$address->ID. '" ' .( ( !empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $_SESSION[$tpl_component['ADDRESS_TYPE']] == $address->ID) ? 'selected="selected"' : null). '>' . (!empty($address_infos['address_title']) ? $address_infos['address_title'] : $address_type_title) . '</option>'; |
|
542 | + $tpl_component['ADDRESS_COMBOBOX_OPTION'] .= '<option value="' . $address->ID . '" ' . ((!empty($_SESSION[$tpl_component['ADDRESS_TYPE']]) && $_SESSION[$tpl_component['ADDRESS_TYPE']] == $address->ID) ? 'selected="selected"' : null) . '>' . (!empty($address_infos['address_title']) ? $address_infos['address_title'] : $address_type_title) . '</option>'; |
|
543 | 543 | $nb_of_addresses++; |
544 | 544 | } |
545 | 545 | $first = false; |
546 | 546 | } |
547 | 547 | $tpl_component['ADDRESS_COMBOBOX'] = ''; |
548 | - if ( !is_admin() ) { |
|
548 | + if (!is_admin()) { |
|
549 | 549 | $tpl_component['ADDRESS_COMBOBOX'] = (!empty($tpl_component['ADDRESS_COMBOBOX_OPTION']) && ($nb_of_addresses > 1)) ? wpshop_display::display_template_element('addresses_type_combobox', $tpl_component) : ''; |
550 | 550 | } |
551 | 551 | } |
552 | 552 | else { |
553 | - if ( !empty($args) && !empty($args['first']) && $args['first'] ) { |
|
553 | + if (!empty($args) && !empty($args['first']) && $args['first']) { |
|
554 | 554 | $tpl_component['ADDRESS_TYPE'] = 'first_address'; |
555 | 555 | } |
556 | 556 | $tpl_component['ADDRESS_ID'] = 0; |
557 | 557 | $tpl_component['DEFAULT_ADDRESS_ID'] = 0; |
558 | 558 | $tpl_component['ADDRESS_COMBOBOX'] = ''; |
559 | - $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = sprintf( __('You don\'t have any %s, %splease create a new one%s', 'wpshop'), ( (!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : strtolower($address_type_title) ) , '<a href="' . $tpl_component['ADD_NEW_ADDRESS_LINK'] . '" >', '</a>' ); |
|
559 | + $tpl_component['CUSTOMER_CHOOSEN_ADDRESS'] = sprintf(__('You don\'t have any %s, %splease create a new one%s', 'wpshop'), ((!empty($args) && !empty($args['first']) && $args['first']) ? __('address', 'wpshop') : strtolower($address_type_title)), '<a href="' . $tpl_component['ADD_NEW_ADDRESS_LINK'] . '" >', '</a>'); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | $tpl_component['ADDRESS_BUTTONS'] .= wpshop_display::display_template_element('addresses_box_actions_button_new_address', $tpl_component); |
563 | - if ( !empty($args['only_display']) && ($args['only_display'] == 'yes') ) { |
|
563 | + if (!empty($args['only_display']) && ($args['only_display'] == 'yes')) { |
|
564 | 564 | $tpl_component['ADDRESS_BUTTONS'] = ''; |
565 | 565 | } |
566 | 566 | |
@@ -580,26 +580,26 @@ discard block |
||
580 | 580 | * |
581 | 581 | * @return array Un tableau contenant l'affihage du formulaire en premier index et le titre du forulaire en second index. |
582 | 582 | */ |
583 | - function loading_address_form( $address_type_id, $address_id = '', $customer_id = '' ) { |
|
583 | + function loading_address_form($address_type_id, $address_id = '', $customer_id = '') { |
|
584 | 584 | $first_address_checking = false; |
585 | 585 | // $customer_id = wps_customer_ctr::get_customer_id_by_author_id( $user_id ); |
586 | - if ( ! empty( $address_id ) ) { |
|
587 | - $title = __( 'Edit your address', 'wpshop' ); |
|
588 | - } elseif ( $address_type_id ) { |
|
589 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
586 | + if (!empty($address_id)) { |
|
587 | + $title = __('Edit your address', 'wpshop'); |
|
588 | + } elseif ($address_type_id) { |
|
589 | + $billing_option = get_option('wpshop_billing_address'); |
|
590 | 590 | |
591 | - $addresses = self::get_addresses_list( $customer_id ); |
|
592 | - $list_addresses = ( ! empty( $addresses[ $billing_option['choice'] ] ) ) ? $addresses[ $billing_option['choice'] ] : array(); |
|
593 | - $first_address_checking = ( empty( $list_addresses ) ) ? true : false; |
|
591 | + $addresses = self::get_addresses_list($customer_id); |
|
592 | + $list_addresses = (!empty($addresses[$billing_option['choice']])) ? $addresses[$billing_option['choice']] : array(); |
|
593 | + $first_address_checking = (empty($list_addresses)) ? true : false; |
|
594 | 594 | |
595 | - $title = __( 'Add a new address', 'wpshop' ); |
|
595 | + $title = __('Add a new address', 'wpshop'); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | ob_start(); |
599 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'common', 'address', 'form' ) ); |
|
599 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, 'common', 'address', 'form')); |
|
600 | 600 | $form = ob_get_clean(); |
601 | 601 | |
602 | - return array( $form, $title ); |
|
602 | + return array($form, $title); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -607,32 +607,32 @@ discard block |
||
607 | 607 | * @param $typeof |
608 | 608 | * @return array |
609 | 609 | */ |
610 | - public static function get_addresss_form_fields_by_type ( $typeof, $id ='' ) { |
|
611 | - $submit_billing_and_shipping_info = !empty( $_POST['submitbillingAndShippingInfo'] ) ? sanitize_key( $_POST['submitbillingAndShippingInfo'] ) : ''; |
|
610 | + public static function get_addresss_form_fields_by_type($typeof, $id = '') { |
|
611 | + $submit_billing_and_shipping_info = !empty($_POST['submitbillingAndShippingInfo']) ? sanitize_key($_POST['submitbillingAndShippingInfo']) : ''; |
|
612 | 612 | |
613 | 613 | $address = array(); |
614 | 614 | $all_addresses = ''; |
615 | - $attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array(); |
|
615 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
616 | 616 | /* Get the attribute set details in order to build the product interface */ |
617 | 617 | |
618 | 618 | $atribute_set_details = wpshop_attributes_set::getAttributeSetDetails($typeof, "'valid'"); |
619 | - if ( !empty($atribute_set_details) ) { |
|
619 | + if (!empty($atribute_set_details)) { |
|
620 | 620 | foreach ($atribute_set_details as $productAttributeSetDetail) { |
621 | 621 | $address = array(); |
622 | 622 | $group_name = $productAttributeSetDetail['name']; |
623 | 623 | |
624 | - if(count($productAttributeSetDetail['attribut']) >= 1){ |
|
625 | - foreach($productAttributeSetDetail['attribut'] as $attribute) { |
|
626 | - if(!empty($attribute->id)) { |
|
627 | - if ( !empty( $submit_billing_and_shipping_info ) ) { |
|
624 | + if (count($productAttributeSetDetail['attribut']) >= 1) { |
|
625 | + foreach ($productAttributeSetDetail['attribut'] as $attribute) { |
|
626 | + if (!empty($attribute->id)) { |
|
627 | + if (!empty($submit_billing_and_shipping_info)) { |
|
628 | 628 | $value = $attribute[$typeof][$attribute->data_type][$attribute->code]; |
629 | 629 | } |
630 | 630 | else { |
631 | 631 | $value = wpshop_attributes::getAttributeValueForEntityInSet($attribute->data_type, $attribute->id, wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS), (int)$id, array('intrinsic' => $attribute->is_intrinsic, 'backend_input' => $attribute->backend_input)); |
632 | 632 | } |
633 | - $attribute_output_def = wpshop_attributes::get_attribute_field_definition( $attribute, $value, array() ); |
|
634 | - $attribute_output_def['id'] = 'address_' . $typeof . '_' .$attribute_output_def['id']; |
|
635 | - $address[str_replace( '-', '_', sanitize_title($group_name) ).'_'.$attribute->code] = $attribute_output_def; |
|
633 | + $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute, $value, array()); |
|
634 | + $attribute_output_def['id'] = 'address_' . $typeof . '_' . $attribute_output_def['id']; |
|
635 | + $address[str_replace('-', '_', sanitize_title($group_name)) . '_' . $attribute->code] = $attribute_output_def; |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | } |
@@ -657,29 +657,29 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @return array [description] |
659 | 659 | */ |
660 | - public static function save_address_infos( $attribute_set_id, $address_id_to_copy = 0, $address_info_to_copy = array(), $customer_id = false, $post_id = false ) { |
|
661 | - if ( empty( $address_info_to_copy ) ) { |
|
662 | - $address_info_to_copy = (array) $_POST; |
|
660 | + public static function save_address_infos($attribute_set_id, $address_id_to_copy = 0, $address_info_to_copy = array(), $customer_id = false, $post_id = false) { |
|
661 | + if (empty($address_info_to_copy)) { |
|
662 | + $address_info_to_copy = (array)$_POST; |
|
663 | 663 | } |
664 | 664 | |
665 | - $adress_save_the_first = ! empty( $address_info_to_copy['wps-address-save-the-first'] ) ? sanitize_text_field( $address_info_to_copy['wps-address-save-the-first'] ) : ''; |
|
665 | + $adress_save_the_first = !empty($address_info_to_copy['wps-address-save-the-first']) ? sanitize_text_field($address_info_to_copy['wps-address-save-the-first']) : ''; |
|
666 | 666 | |
667 | - $attribute = (array) $address_info_to_copy['attribute']; |
|
667 | + $attribute = (array)$address_info_to_copy['attribute']; |
|
668 | 668 | |
669 | - $type_of_form = (int) $address_info_to_copy['type_of_form']; |
|
670 | - $current_item_edited = ! empty( $address_info_to_copy['attribute'][ $attribute_set_id ]['item_id'] ) ? (int) wpshop_tools::varSanitizer( $address_info_to_copy['attribute'][ $attribute_set_id ]['item_id'] ) : null; |
|
671 | - $current_attribute_set_id = ! empty( $address_info_to_copy['current_attribute_set_id'] ) ? (int) $address_info_to_copy['current_attribute_set_id'] : ''; |
|
672 | - $shipping_to_billing = ! empty( $address_info_to_copy['wps-shipping-to-billing'] ) ? sanitize_text_field( $address_info_to_copy['wps-shipping-to-billing'] ) : ''; |
|
673 | - $shipping_to_billing_id = ! empty( $address_info_to_copy['wps-shipping-to-billing-id'] ) ? (int) $address_info_to_copy['wps-shipping-to-billing-id'] : $address_id_to_copy; |
|
669 | + $type_of_form = (int)$address_info_to_copy['type_of_form']; |
|
670 | + $current_item_edited = !empty($address_info_to_copy['attribute'][$attribute_set_id]['item_id']) ? (int)wpshop_tools::varSanitizer($address_info_to_copy['attribute'][$attribute_set_id]['item_id']) : null; |
|
671 | + $current_attribute_set_id = !empty($address_info_to_copy['current_attribute_set_id']) ? (int)$address_info_to_copy['current_attribute_set_id'] : ''; |
|
672 | + $shipping_to_billing = !empty($address_info_to_copy['wps-shipping-to-billing']) ? sanitize_text_field($address_info_to_copy['wps-shipping-to-billing']) : ''; |
|
673 | + $shipping_to_billing_id = !empty($address_info_to_copy['wps-shipping-to-billing-id']) ? (int)$address_info_to_copy['wps-shipping-to-billing-id'] : $address_id_to_copy; |
|
674 | 674 | |
675 | 675 | // Create or update the post address |
676 | 676 | // @TODO : REQUEST. |
677 | - $customer_id_from_cookie = ! empty( $_COOKIE ) && ! empty( $_COOKIE['wps_current_connected_customer'] ) ? (int) $_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ); |
|
678 | - $customer_id = ( ! empty( $customer_id ) ? (int) $customer_id : ( ! empty( $_REQUEST['user']['customer_id'] ) ? (int) $_REQUEST['user']['customer_id'] : $customer_id_from_cookie ) ); |
|
679 | - $post_id = ! empty( $post_id ) ? (int) $post_id : ( ! empty( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0 ); |
|
677 | + $customer_id_from_cookie = !empty($_COOKIE) && !empty($_COOKIE['wps_current_connected_customer']) ? (int)$_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()); |
|
678 | + $customer_id = (!empty($customer_id) ? (int)$customer_id : (!empty($_REQUEST['user']['customer_id']) ? (int)$_REQUEST['user']['customer_id'] : $customer_id_from_cookie)); |
|
679 | + $post_id = !empty($post_id) ? (int)$post_id : (!empty($_REQUEST['post_ID']) ? (int)$_REQUEST['post_ID'] : 0); |
|
680 | 680 | |
681 | 681 | $post_address = array( |
682 | - 'post_title' => ! empty( $attribute ) && ! empty( $attribute[ $attribute_set_id ] ) && ! empty( $attribute[ $attribute_set_id ]['varchar'] ) && ! empty( $attribute[ $attribute_set_id ]['varchar']['address_title'] ) ? $attribute[ $attribute_set_id ]['varchar']['address_title'] : '', |
|
682 | + 'post_title' => !empty($attribute) && !empty($attribute[$attribute_set_id]) && !empty($attribute[$attribute_set_id]['varchar']) && !empty($attribute[$attribute_set_id]['varchar']['address_title']) ? $attribute[$attribute_set_id]['varchar']['address_title'] : '', |
|
683 | 683 | 'post_status' => 'draft', |
684 | 684 | 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
685 | 685 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
@@ -687,58 +687,58 @@ discard block |
||
687 | 687 | |
688 | 688 | $edit_other_thing = true; |
689 | 689 | |
690 | - if ( empty( $current_item_edited ) && ( empty( $current_attribute_set_id ) || $current_attribute_set_id != $attribute_set_id ) ) { |
|
690 | + if (empty($current_item_edited) && (empty($current_attribute_set_id) || $current_attribute_set_id != $attribute_set_id)) { |
|
691 | 691 | $post_address['post_author'] = get_current_user_id(); |
692 | - $post_address['post_parent'] = empty( $customer_id ) && ! empty( $post_id ) ? $post_id : $customer_id; |
|
693 | - $current_item_edited = wp_insert_post( $post_address ); |
|
694 | - if ( is_admin() ) { |
|
695 | - $attribute[ $attribute_set_id ]['item_id'] = $current_item_edited; |
|
692 | + $post_address['post_parent'] = empty($customer_id) && !empty($post_id) ? $post_id : $customer_id; |
|
693 | + $current_item_edited = wp_insert_post($post_address); |
|
694 | + if (is_admin()) { |
|
695 | + $attribute[$attribute_set_id]['item_id'] = $current_item_edited; |
|
696 | 696 | } |
697 | 697 | } else { |
698 | 698 | $post_address['ID'] = $current_item_edited; |
699 | - wp_update_post( $post_address ); |
|
699 | + wp_update_post($post_address); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /* Shipping to billing save */ |
703 | - if ( ! empty( $shipping_to_billing ) ) { |
|
704 | - $wps_shipping_to_billing = array( 'wps-shipping-to-billing' => $shipping_to_billing ); |
|
703 | + if (!empty($shipping_to_billing)) { |
|
704 | + $wps_shipping_to_billing = array('wps-shipping-to-billing' => $shipping_to_billing); |
|
705 | 705 | |
706 | - if ( ! empty( $shipping_to_billing_id ) ) { |
|
706 | + if (!empty($shipping_to_billing_id)) { |
|
707 | 707 | $wps_shipping_to_billing['wps-shipping-to-billing-id'] = $shipping_to_billing_id; |
708 | 708 | } |
709 | - update_post_meta( $current_item_edited, 'wps-shipping-to-billing', $wps_shipping_to_billing ); |
|
709 | + update_post_meta($current_item_edited, 'wps-shipping-to-billing', $wps_shipping_to_billing); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | // Update the post_meta of address. |
713 | - update_post_meta( $current_item_edited, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, $attribute_set_id ); |
|
713 | + update_post_meta($current_item_edited, WPSHOP_ADDRESS_ATTRIBUTE_SET_ID_META_KEY, $attribute_set_id); |
|
714 | 714 | |
715 | - foreach ( $attribute[ $attribute_set_id ] as $type => $type_content ) { |
|
715 | + foreach ($attribute[$attribute_set_id] as $type => $type_content) { |
|
716 | 716 | $attribute_not_to_do = array(); |
717 | - if ( is_array( $type_content ) ) { |
|
718 | - foreach ( $type_content as $code => $value ) { |
|
719 | - $attribute_def = wpshop_attributes::getElement( $code, "'valid'", 'code' ); |
|
720 | - if ( ! empty( $attribute_def->_need_verification ) && 'yes' === $attribute_def->_need_verification ) { |
|
717 | + if (is_array($type_content)) { |
|
718 | + foreach ($type_content as $code => $value) { |
|
719 | + $attribute_def = wpshop_attributes::getElement($code, "'valid'", 'code'); |
|
720 | + if (!empty($attribute_def->_need_verification) && 'yes' === $attribute_def->_need_verification) { |
|
721 | 721 | $code_verif = $code . '2'; |
722 | 722 | $attribute_not_to_do[] = $code_verif; |
723 | - if ( ! empty( $attributes[ $code_verif ] ) ) { |
|
724 | - unset( $attributes[ $code_verif ] ); |
|
723 | + if (!empty($attributes[$code_verif])) { |
|
724 | + unset($attributes[$code_verif]); |
|
725 | 725 | } |
726 | 726 | } |
727 | - if ( ! in_array( $code, $attribute_not_to_do, true ) ) { |
|
728 | - $attributes[ $code ] = $value; |
|
727 | + if (!in_array($code, $attribute_not_to_do, true)) { |
|
728 | + $attributes[$code] = $value; |
|
729 | 729 | } |
730 | 730 | } |
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | - $attributes = apply_filters( 'wps-address-coordinate-calculation', $attributes ); |
|
734 | + $attributes = apply_filters('wps-address-coordinate-calculation', $attributes); |
|
735 | 735 | |
736 | - $result = wpshop_attributes::setAttributesValuesForItem( $current_item_edited, $attributes, false, '' ); |
|
736 | + $result = wpshop_attributes::setAttributesValuesForItem($current_item_edited, $attributes, false, ''); |
|
737 | 737 | $result['current_id'] = $current_item_edited; |
738 | 738 | |
739 | - if ( ! empty( $result['current_id'] ) ) { |
|
740 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
741 | - if ( ! empty( $billing_option ) && ! empty( $billing_option['choice'] ) && $billing_option['choice'] === $attribute_set_id ) { |
|
739 | + if (!empty($result['current_id'])) { |
|
740 | + $billing_option = get_option('wpshop_billing_address'); |
|
741 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] === $attribute_set_id) { |
|
742 | 742 | $_SESSION['billing_address'] = $result['current_id']; |
743 | 743 | } else { |
744 | 744 | $_SESSION['shipping_address'] = $result['current_id']; |
@@ -755,27 +755,27 @@ discard block |
||
755 | 755 | * @param string $referer : Referer website page |
756 | 756 | * @param string $admin : Display this form in admin panel |
757 | 757 | */ |
758 | - public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '' ) { |
|
758 | + public static function display_form_fields($type, $id = '', $first = '', $referer = '', $special_values = array(), $options = array(), $display_for_admin = array(), $other_customer = '') { |
|
759 | 759 | global $wpshop, $wpshop_form, $wpdb; |
760 | 760 | |
761 | 761 | $choosen_address = get_option('wpshop_billing_address'); |
762 | 762 | $shipping_address = get_option('wpshop_shipping_address_choice'); |
763 | 763 | $output_form_fields = $form_model = ''; |
764 | 764 | |
765 | - $user_id = ( ! empty($other_customer) ) ? $other_customer : get_current_user_id(); |
|
765 | + $user_id = (!empty($other_customer)) ? $other_customer : get_current_user_id(); |
|
766 | 766 | |
767 | - if ( empty($type) ) { |
|
767 | + if (empty($type)) { |
|
768 | 768 | $type = $choosen_address['choice']; |
769 | 769 | } |
770 | 770 | |
771 | 771 | $result = wps_address::get_addresss_form_fields_by_type($type, $id); |
772 | 772 | |
773 | 773 | /** Check if it's shipping or billing **/ |
774 | - if ( $type == $choosen_address['choice'] ) { |
|
775 | - $form_model = ( !empty($choosen_address['display_model']) ) ? $choosen_address['display_model'] : null; |
|
774 | + if ($type == $choosen_address['choice']) { |
|
775 | + $form_model = (!empty($choosen_address['display_model'])) ? $choosen_address['display_model'] : null; |
|
776 | 776 | } |
777 | - elseif( $type == $shipping_address['choice'] ) { |
|
778 | - $form_model = ( !empty($shipping_address['display_model']) ) ? $shipping_address['display_model'] : null; |
|
777 | + elseif ($type == $shipping_address['choice']) { |
|
778 | + $form_model = (!empty($shipping_address['display_model'])) ? $shipping_address['display_model'] : null; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | |
@@ -785,17 +785,17 @@ discard block |
||
785 | 785 | // take the address informations |
786 | 786 | $current_item_edited = !empty($id) ? (int)$id : null; |
787 | 787 | |
788 | - foreach ( $form as $group_id => $group_fields) { |
|
789 | - if ( empty($options) || (!empty($options) && ($options['title']))) $output_form_fields .= '<h2>'.__( $group_fields['name'], 'wpshop' ).'</h2>'; |
|
788 | + foreach ($form as $group_id => $group_fields) { |
|
789 | + if (empty($options) || (!empty($options) && ($options['title']))) $output_form_fields .= '<h2>' . __($group_fields['name'], 'wpshop') . '</h2>'; |
|
790 | 790 | $end_line_indicator = 0; $fields_limit_per_line = -1; |
791 | - foreach ( $group_fields['content'] as $key => $field) { |
|
792 | - $attribute_def = wpshop_attributes::getElement( $field['name'], $element_status = "'valid'", $field_to_search = 'code' ); |
|
791 | + foreach ($group_fields['content'] as $key => $field) { |
|
792 | + $attribute_def = wpshop_attributes::getElement($field['name'], $element_status = "'valid'", $field_to_search = 'code'); |
|
793 | 793 | /** Grid opening **/ |
794 | - if ( !empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-'.$end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1 ) { |
|
795 | - $current_key = array_search( 'wps-attribute-end-line-'.$end_line_indicator, $form_model[$group_id] ); |
|
796 | - $current_attribute_key = array_search( 'attribute_'.$attribute_def->id, $form_model[$group_id] ); |
|
794 | + if (!empty($form_model) && !empty($form_model[$group_id]) && in_array('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]) && $fields_limit_per_line == -1) { |
|
795 | + $current_key = array_search('wps-attribute-end-line-' . $end_line_indicator, $form_model[$group_id]); |
|
796 | + $current_attribute_key = array_search('attribute_' . $attribute_def->id, $form_model[$group_id]); |
|
797 | 797 | |
798 | - if( $current_attribute_key > $current_key ) { |
|
798 | + if ($current_attribute_key > $current_key) { |
|
799 | 799 | // /** Define limit **/ |
800 | 800 | // if( in_array('wps-attribute-end-line-' . ($end_line_indicator + 1 ) , $form_model[$group_id]) ) { |
801 | 801 | // $next_key = array_search( 'wps-attribute-end-line-'.( $end_line_indicator + 1 ), $form_model[$group_id] ); |
@@ -808,121 +808,121 @@ discard block |
||
808 | 808 | // $fields_limit_per_line = $end_tab - $current_key - 1; |
809 | 809 | // $fields_limit_per_line = ( $fields_limit_per_line > 6 ) ? 6 : $fields_limit_per_line; |
810 | 810 | // } |
811 | - if ( !empty($fields_limit_per_line) && $fields_limit_per_line != -1 ) { |
|
812 | - if ( $fields_limit_per_line == 1 ) { |
|
811 | + if (!empty($fields_limit_per_line) && $fields_limit_per_line != -1) { |
|
812 | + if ($fields_limit_per_line == 1) { |
|
813 | 813 | $output_form_fields .= '<div class="wps-row">'; |
814 | 814 | } |
815 | 815 | else { |
816 | - $output_form_fields .= '<div class="wps-row wps-gridwrapper' .$fields_limit_per_line. '-padded">'; |
|
816 | + $output_form_fields .= '<div class="wps-row wps-gridwrapper' . $fields_limit_per_line . '-padded">'; |
|
817 | 817 | } |
818 | 818 | } |
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | - if ( empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array( $key, $options['field_to_hide'] ) ) { |
|
822 | + if (empty($options['field_to_hide']) || !is_array($options['field_to_hide']) || !in_array($key, $options['field_to_hide'])) { |
|
823 | 823 | $attributeInputDomain = 'attribute[' . $type . '][' . $field['data_type'] . ']'; |
824 | 824 | // Test if there is POST var or if user have already fill his address infos and fill the fields with these infos |
825 | - $referer = !empty($_POST['referer']) ? sanitize_text_field( $_POST['referer'] ) : ''; |
|
826 | - if( !empty($referer) ) { |
|
827 | - $value = !empty( $_POST[$form['id']."_".$field['name']] ) ? sanitize_text_field( $_POST[$form['id']."_".$field['name']] ) : ''; |
|
825 | + $referer = !empty($_POST['referer']) ? sanitize_text_field($_POST['referer']) : ''; |
|
826 | + if (!empty($referer)) { |
|
827 | + $value = !empty($_POST[$form['id'] . "_" . $field['name']]) ? sanitize_text_field($_POST[$form['id'] . "_" . $field['name']]) : ''; |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | |
831 | 831 | |
832 | 832 | // Fill Automaticly some fields when it's an address creation |
833 | - switch ( $field['name']) { |
|
833 | + switch ($field['name']) { |
|
834 | 834 | case 'address_title' : |
835 | - if( empty($field['value']) ) { |
|
835 | + if (empty($field['value'])) { |
|
836 | 836 | /** Count Billing and shipping address **/ |
837 | 837 | $billing_address_count = $shipping_address_count = 1; |
838 | - if ( get_current_user_id() != 0 ) { |
|
839 | - $addresses = get_posts( array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft') ); |
|
840 | - if ( !empty($addresses) ) { |
|
841 | - foreach( $addresses as $address ) { |
|
842 | - $address_type = get_post_meta( $address->ID, '_wpshop_address_attribute_set_id', true); |
|
843 | - if ( !empty($address_type) ){ |
|
844 | - if ( !empty( $shipping_address_choice['choice'] ) && $address_type == $shipping_address_choice['choice'] ) { |
|
838 | + if (get_current_user_id() != 0) { |
|
839 | + $addresses = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => get_current_user_id(), 'post_status' => 'draft')); |
|
840 | + if (!empty($addresses)) { |
|
841 | + foreach ($addresses as $address) { |
|
842 | + $address_type = get_post_meta($address->ID, '_wpshop_address_attribute_set_id', true); |
|
843 | + if (!empty($address_type)) { |
|
844 | + if (!empty($shipping_address_choice['choice']) && $address_type == $shipping_address_choice['choice']) { |
|
845 | 845 | $shipping_address_count++; |
846 | 846 | } |
847 | - else{ |
|
847 | + else { |
|
848 | 848 | $billing_address_count++; |
849 | 849 | } |
850 | 850 | } |
851 | 851 | } |
852 | 852 | } |
853 | 853 | } |
854 | - $field['value'] = ( $type == $choosen_address['choice'] ) ? __('Billing address', 'wpshop').( ($billing_address_count > 1) ? ' '.$billing_address_count : '' ) : __('Shipping address', 'wpshop').( ($shipping_address_count > 1) ? ' '.$shipping_address_count : ''); |
|
854 | + $field['value'] = ($type == $choosen_address['choice']) ? __('Billing address', 'wpshop') . (($billing_address_count > 1) ? ' ' . $billing_address_count : '') : __('Shipping address', 'wpshop') . (($shipping_address_count > 1) ? ' ' . $shipping_address_count : ''); |
|
855 | 855 | |
856 | 856 | } |
857 | 857 | break; |
858 | 858 | case 'address_last_name' : |
859 | - if( empty($field['value']) ) { |
|
860 | - $usermeta_last_name = get_user_meta( $user_id, 'last_name', true); |
|
861 | - $field['value'] = ( !empty($usermeta_last_name) ) ? $usermeta_last_name : ''; |
|
859 | + if (empty($field['value'])) { |
|
860 | + $usermeta_last_name = get_user_meta($user_id, 'last_name', true); |
|
861 | + $field['value'] = (!empty($usermeta_last_name)) ? $usermeta_last_name : ''; |
|
862 | 862 | } |
863 | 863 | break; |
864 | 864 | case 'address_first_name' : |
865 | - if( empty($field['value']) ) { |
|
866 | - $usermeta_first_name = get_user_meta( $user_id, 'first_name', true); |
|
867 | - $field['value'] = ( !empty($usermeta_first_name) ) ? $usermeta_first_name : ''; |
|
865 | + if (empty($field['value'])) { |
|
866 | + $usermeta_first_name = get_user_meta($user_id, 'first_name', true); |
|
867 | + $field['value'] = (!empty($usermeta_first_name)) ? $usermeta_first_name : ''; |
|
868 | 868 | } |
869 | 869 | break; |
870 | 870 | case 'address_user_email' : |
871 | - if( empty($field['value']) ) { |
|
872 | - $user_infos = get_userdata( $user_id ); |
|
873 | - $field['value'] = ( !empty($user_infos) && !empty($user_infos->user_email) ) ? $user_infos->user_email : ''; |
|
871 | + if (empty($field['value'])) { |
|
872 | + $user_infos = get_userdata($user_id); |
|
873 | + $field['value'] = (!empty($user_infos) && !empty($user_infos->user_email)) ? $user_infos->user_email : ''; |
|
874 | 874 | } |
875 | 875 | break; |
876 | 876 | default : |
877 | - $field['value'] = ( !empty($field['value']) ) ? $field['value'] : ''; |
|
877 | + $field['value'] = (!empty($field['value'])) ? $field['value'] : ''; |
|
878 | 878 | break; |
879 | 879 | } |
880 | 880 | |
881 | 881 | |
882 | 882 | |
883 | 883 | /** Fill fields if $_POST exist **/ |
884 | - if ( !empty( $attribute[$type][$field['data_type']][$field['name']] ) ) { |
|
885 | - $field['value'] = sanitize_text_field( $_POST['attribute'][$type][$field['data_type']][$field['name']] ); |
|
884 | + if (!empty($attribute[$type][$field['data_type']][$field['name']])) { |
|
885 | + $field['value'] = sanitize_text_field($_POST['attribute'][$type][$field['data_type']][$field['name']]); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | |
889 | - if( $field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop') ) { |
|
889 | + if ($field['name'] == 'address_title' && !empty($first) && $type == __('Billing address', 'wpshop')) { |
|
890 | 890 | $value = __('Billing address', 'wpshop'); |
891 | 891 | } |
892 | - elseif( $field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop') ) { |
|
892 | + elseif ($field['name'] == 'address_title' && !empty($first) && $type == __('Shipping address', 'wpshop')) { |
|
893 | 893 | $value = __('Shipping address', 'wpshop'); |
894 | 894 | } |
895 | 895 | |
896 | - if ( !empty($special_values[$field['name']]) ) { |
|
896 | + if (!empty($special_values[$field['name']])) { |
|
897 | 897 | $field['value'] = $special_values[$field['name']]; |
898 | 898 | } |
899 | 899 | |
900 | 900 | $template = 'wpshop_account_form_input'; |
901 | - if ( $field['type'] == 'hidden' ) { |
|
901 | + if ($field['type'] == 'hidden') { |
|
902 | 902 | $template = 'wpshop_account_form_hidden_input'; |
903 | 903 | } |
904 | 904 | |
905 | - if ( $field['frontend_verification'] == 'country' ) { |
|
905 | + if ($field['frontend_verification'] == 'country') { |
|
906 | 906 | $field['type'] = 'select'; |
907 | 907 | /** display a country list **/ |
908 | 908 | $countries_list = unserialize(WPSHOP_COUNTRY_LIST); |
909 | 909 | $possible_values = array_merge(array('' => __('Choose a country')), $countries_list); |
910 | 910 | |
911 | - $limit_countries_list = get_option( 'wpshop_limit_country_list' ); |
|
912 | - $default_country_choice = get_option( 'wpshop_country_default_choice' ); |
|
913 | - if ( !empty($limit_countries_list) ) { |
|
911 | + $limit_countries_list = get_option('wpshop_limit_country_list'); |
|
912 | + $default_country_choice = get_option('wpshop_country_default_choice'); |
|
913 | + if (!empty($limit_countries_list)) { |
|
914 | 914 | $possible_values = array(); |
915 | - if ( count($limit_countries_list) > 1 ) { |
|
915 | + if (count($limit_countries_list) > 1) { |
|
916 | 916 | $possible_values[''] = __('Choose a country'); |
917 | 917 | } |
918 | - foreach( $limit_countries_list as $country_code) { |
|
919 | - if ( !empty($countries_list) && !empty($countries_list[$country_code]) ) { |
|
918 | + foreach ($limit_countries_list as $country_code) { |
|
919 | + if (!empty($countries_list) && !empty($countries_list[$country_code])) { |
|
920 | 920 | $possible_values[$country_code] = $countries_list[$country_code]; |
921 | 921 | } |
922 | 922 | } |
923 | 923 | } |
924 | 924 | |
925 | - $field['value'] = ( !empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values ) ) ? $default_country_choice : ''; |
|
925 | + $field['value'] = (!empty($default_country_choice) && array_key_exists($default_country_choice, $possible_values)) ? $default_country_choice : ''; |
|
926 | 926 | $field['possible_value'] = $possible_values; |
927 | 927 | $field['valueToPut'] = 'index'; |
928 | 928 | |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | $input_tpl_component = array(); |
935 | 935 | |
936 | 936 | //$input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; |
937 | - $input_tpl_component['CUSTOMER_FORM_INPUT_NAME'] = ( !empty($field['name']) ) ? $field['name'] : ''; |
|
938 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = ( $field['type'] != 'hidden' ) ? stripslashes( __( $field['label'], 'wpshop' ) ) . ( ( $field['required'] == 'yes' ) ? ' <em>*</em>' : '') : ''; |
|
937 | + $input_tpl_component['CUSTOMER_FORM_INPUT_NAME'] = (!empty($field['name'])) ? $field['name'] : ''; |
|
938 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = ($field['type'] != 'hidden') ? stripslashes(__($field['label'], 'wpshop')) . (($field['required'] == 'yes') ? ' <em>*</em>' : '') : ''; |
|
939 | 939 | $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; |
940 | 940 | $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain); |
941 | 941 | //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); |
@@ -946,16 +946,16 @@ discard block |
||
946 | 946 | |
947 | 947 | unset($input_tpl_component); |
948 | 948 | |
949 | - if ( $field['_need_verification'] == 'yes' ) { |
|
949 | + if ($field['_need_verification'] == 'yes') { |
|
950 | 950 | $field['name'] = $field['name'] . '2'; |
951 | 951 | $field['id'] = $field['id'] . '2'; |
952 | 952 | $element_simple_class = str_replace('"', '', str_replace('class="', '', str_replace('wpshop_input_datetime', '', $field['option']))); |
953 | 953 | $input_tpl_component = array(); |
954 | 954 | $input_tpl_component['CUSTOMER_FORM_INPUT_NAME'] = $field['name']; |
955 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __( $field['label'], 'wpshop' ) . ( ( ($field['required'] == 'yes' && !is_admin()) || ($field['name'] == 'address_user_email' && is_admin()) ) ? ' <span class="required">*</span>' : ''); |
|
955 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = __($field['label'], 'wpshop') . ((($field['required'] == 'yes' && !is_admin()) || ($field['name'] == 'address_user_email' && is_admin())) ? ' <span class="required">*</span>' : ''); |
|
956 | 956 | $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL_OPTIONS'] = ' for="' . $field['id'] . '"'; |
957 | 957 | $input_tpl_component['CUSTOMER_FORM_INPUT_MAIN_CONTAINER_CLASS'] = ' wsphop_customer_account_form_container wsphop_customer_account_form_container_' . $field['name'] . $element_simple_class; |
958 | - $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf( __('Confirm %s', 'wpshop'), strtolower( __( $field['label'], 'wpshop' ) ) ). ( ($field['required'] == 'yes') && !is_admin() ? ' <span class="required">*</span>' : ''); |
|
958 | + $input_tpl_component['CUSTOMER_FORM_INPUT_LABEL'] = sprintf(__('Confirm %s', 'wpshop'), strtolower(__($field['label'], 'wpshop'))) . (($field['required'] == 'yes') && !is_admin() ? ' <span class="required">*</span>' : ''); |
|
959 | 959 | $input_tpl_component['CUSTOMER_FORM_INPUT_FIELD'] = wpshop_form::check_input_type($field, $attributeInputDomain) . $field['options']; |
960 | 960 | //$output_form_fields .= wpshop_display::display_template_element($template, $input_tpl_component); |
961 | 961 | $output_form_fields .= wpshop_display::display_template_element('wps_address_field', $input_tpl_component, array(), 'wpshop'); |
@@ -964,9 +964,9 @@ discard block |
||
964 | 964 | } |
965 | 965 | |
966 | 966 | /** Grid closing **/ |
967 | - if( $fields_limit_per_line != -1 && !empty($fields_limit_per_line) ) { |
|
967 | + if ($fields_limit_per_line != -1 && !empty($fields_limit_per_line)) { |
|
968 | 968 | $fields_limit_per_line--; |
969 | - if( $fields_limit_per_line == 0 ) { |
|
969 | + if ($fields_limit_per_line == 0) { |
|
970 | 970 | $output_form_fields .= '</div>'; |
971 | 971 | $fields_limit_per_line = -1; |
972 | 972 | $end_line_indicator++; |
@@ -975,18 +975,18 @@ discard block |
||
975 | 975 | } |
976 | 976 | } |
977 | 977 | |
978 | - if ( $type == $choosen_address['choice'] ) { |
|
979 | - $output_form_fields .= '<input type="hidden" name="billing_address" value="'.$choosen_address['choice'].'" />'; |
|
978 | + if ($type == $choosen_address['choice']) { |
|
979 | + $output_form_fields .= '<input type="hidden" name="billing_address" value="' . $choosen_address['choice'] . '" />'; |
|
980 | 980 | } |
981 | 981 | $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
982 | - if ( $type == $shipping_address_options['choice'] ) { |
|
983 | - $output_form_fields .= '<input type="hidden" name="shipping_address" value="' .$shipping_address_options['choice']. '" />'; |
|
982 | + if ($type == $shipping_address_options['choice']) { |
|
983 | + $output_form_fields .= '<input type="hidden" name="shipping_address" value="' . $shipping_address_options['choice'] . '" />'; |
|
984 | 984 | } |
985 | - $output_form_fields .= '<input type="hidden" name="type_of_form" value="' .$type. '" /><input type="hidden" name="attribute[' .$type. '][item_id]" value="' .$current_item_edited. '" />'; |
|
985 | + $output_form_fields .= '<input type="hidden" name="type_of_form" value="' . $type . '" /><input type="hidden" name="attribute[' . $type . '][item_id]" value="' . $current_item_edited . '" />'; |
|
986 | 986 | |
987 | - $output_form_fields .= ( $user_id != get_current_user_id() ) ? '<input type="hidden" name="user[customer_id]" value="' .$user_id. '" />' : ''; |
|
987 | + $output_form_fields .= ($user_id != get_current_user_id()) ? '<input type="hidden" name="user[customer_id]" value="' . $user_id . '" />' : ''; |
|
988 | 988 | |
989 | - if ( empty($first) ) $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
989 | + if (empty($first)) $output_form_fields = wpshop_display::display_template_element('wpshop_customer_addresses_form', array('CUSTOMER_ADDRESSES_FORM_CONTENT' => $output_form_fields, 'CUSTOMER_ADDRESSES_FORM_BUTTONS' => '')); |
|
990 | 990 | |
991 | 991 | return $output_form_fields; |
992 | 992 | } |
@@ -996,22 +996,22 @@ discard block |
||
996 | 996 | * @param integer $shipping_address_type_id |
997 | 997 | * @param integer $billing_address_type_id |
998 | 998 | */ |
999 | - function shipping_to_billing( $shipping_address_type_id, $billing_address_type_id ) { |
|
999 | + function shipping_to_billing($shipping_address_type_id, $billing_address_type_id) { |
|
1000 | 1000 | global $wpdb; |
1001 | 1001 | $tmp_array = array(); |
1002 | - $tmp_array = !empty( $_REQUEST ) ? (array)$_REQUEST : array(); |
|
1002 | + $tmp_array = !empty($_REQUEST) ? (array)$_REQUEST : array(); |
|
1003 | 1003 | |
1004 | 1004 | $billing_fields = array(); |
1005 | - if( !empty($tmp_array) && !empty($tmp_array['attribute']) && !empty($tmp_array['attribute'][$shipping_address_type_id]) ) { |
|
1006 | - foreach ($tmp_array['attribute'][$shipping_address_type_id] as $key => $attribute_group ) { |
|
1007 | - if ( is_array($attribute_group) ) { |
|
1008 | - foreach( $attribute_group as $field_name => $value ) { |
|
1009 | - $attribute_def = wpshop_attributes::getElement( sanitize_text_field( $field_name ), "'valid'", 'code' ); |
|
1010 | - if( !empty($attribute_def) ) { |
|
1011 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE status = %s AND attribute_id = %d AND attribute_set_id = %s', 'valid', (int)$attribute_def->id, sanitize_text_field( $billing_address_type_id ) ); |
|
1012 | - $attribute_exist = $wpdb->get_var( $query ); |
|
1013 | - if ( !empty($attribute_exist) ) { |
|
1014 | - $tmp_array['attribute'][$billing_address_type_id][$attribute_def->data_type][$field_name] = sanitize_text_field( $value ); |
|
1005 | + if (!empty($tmp_array) && !empty($tmp_array['attribute']) && !empty($tmp_array['attribute'][$shipping_address_type_id])) { |
|
1006 | + foreach ($tmp_array['attribute'][$shipping_address_type_id] as $key => $attribute_group) { |
|
1007 | + if (is_array($attribute_group)) { |
|
1008 | + foreach ($attribute_group as $field_name => $value) { |
|
1009 | + $attribute_def = wpshop_attributes::getElement(sanitize_text_field($field_name), "'valid'", 'code'); |
|
1010 | + if (!empty($attribute_def)) { |
|
1011 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND attribute_id = %d AND attribute_set_id = %s', 'valid', (int)$attribute_def->id, sanitize_text_field($billing_address_type_id)); |
|
1012 | + $attribute_exist = $wpdb->get_var($query); |
|
1013 | + if (!empty($attribute_exist)) { |
|
1014 | + $tmp_array['attribute'][$billing_address_type_id][$attribute_def->data_type][$field_name] = sanitize_text_field($value); |
|
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | } |
@@ -1029,9 +1029,9 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @param array $args Les arguments passés au shortcode. |
1031 | 1031 | */ |
1032 | - function shortcode_callback_display_addresses( $args ) { |
|
1033 | - $customer_id = ! empty( $args ) && ! empty( $args['cid'] ) ? (int) $args['cid'] : wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ); |
|
1034 | - return $this->display_addresses_interface( $customer_id ); |
|
1032 | + function shortcode_callback_display_addresses($args) { |
|
1033 | + $customer_id = !empty($args) && !empty($args['cid']) ? (int)$args['cid'] : wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()); |
|
1034 | + return $this->display_addresses_interface($customer_id); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | /** |
@@ -1043,27 +1043,27 @@ discard block |
||
1043 | 1043 | * |
1044 | 1044 | * @return string |
1045 | 1045 | */ |
1046 | - function display_addresses_interface( $customer_id = '', $admin_display = false, $order_id = '' ) { |
|
1046 | + function display_addresses_interface($customer_id = '', $admin_display = false, $order_id = '') { |
|
1047 | 1047 | $output = $extra_class = $billing_address_display = $shipping_address_display = $first_address_checking = ''; |
1048 | 1048 | |
1049 | - if ( $customer_id ) { |
|
1050 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
1051 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
1049 | + if ($customer_id) { |
|
1050 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
1051 | + $billing_option = get_option('wpshop_billing_address'); |
|
1052 | 1052 | |
1053 | 1053 | /** Shipping address */ |
1054 | 1054 | // Check if is only downloadable else display address. |
1055 | 1055 | $cart_is_downloadable = false; |
1056 | - if ( ! empty( $_SESSION['cart'] ) && ! empty( $_SESSION['cart']['order_items'] ) ) { |
|
1057 | - foreach ( $_SESSION['cart']['order_items'] as $c ) { |
|
1058 | - $product = wpshop_products::get_product_data( $c['item_id'] ); |
|
1056 | + if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
1057 | + foreach ($_SESSION['cart']['order_items'] as $c) { |
|
1058 | + $product = wpshop_products::get_product_data($c['item_id']); |
|
1059 | 1059 | // Check if it's a variation and check the parent product. |
1060 | - if ( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === get_post_type( $c['item_id'] ) ) { |
|
1061 | - $parent_def = wpshop_products::get_parent_variation( $c['item_id'] ); |
|
1062 | - if ( ! empty( $parent_def ) && ! empty( $parent_def['parent_post_meta'] ) && ! empty( $parent_def['parent_post_meta']['is_downloadable_'] ) ) { |
|
1060 | + if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === get_post_type($c['item_id'])) { |
|
1061 | + $parent_def = wpshop_products::get_parent_variation($c['item_id']); |
|
1062 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) { |
|
1063 | 1063 | $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_']; |
1064 | 1064 | } |
1065 | 1065 | } |
1066 | - if ( ! empty( $product['is_downloadable_'] ) && ( strtolower( __( $product['is_downloadable_'], 'wpshop' ) ) === strtolower( __( 'Yes', 'wpshop' ) ) ) ) { |
|
1066 | + if (!empty($product['is_downloadable_']) && (strtolower(__($product['is_downloadable_'], 'wpshop')) === strtolower(__('Yes', 'wpshop')))) { |
|
1067 | 1067 | $cart_is_downloadable = true; |
1068 | 1068 | } else { |
1069 | 1069 | $cart_is_downloadable = false; |
@@ -1073,15 +1073,15 @@ discard block |
||
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $checkout_address_type = array( |
1076 | - 'shipping' => __( 'Shipping address', 'wpshop' ), |
|
1077 | - 'billing' => __( 'Billing address', 'wpshop' ), |
|
1076 | + 'shipping' => __('Shipping address', 'wpshop'), |
|
1077 | + 'billing' => __('Billing address', 'wpshop'), |
|
1078 | 1078 | ); |
1079 | 1079 | $shipping_is_avalaible = true; |
1080 | - foreach ( $checkout_address_type as $address_type => $address_title ) { |
|
1080 | + foreach ($checkout_address_type as $address_type => $address_title) { |
|
1081 | 1081 | $display_address_of_type = true; |
1082 | - switch ( $address_type ) { |
|
1082 | + switch ($address_type) { |
|
1083 | 1083 | case 'shipping': |
1084 | - if ( empty( $shipping_option ) || empty( $shipping_option['activate'] ) || $cart_is_downloadable ) { |
|
1084 | + if (empty($shipping_option) || empty($shipping_option['activate']) || $cart_is_downloadable) { |
|
1085 | 1085 | $display_address_of_type = false; |
1086 | 1086 | $shipping_is_avalaible = false; |
1087 | 1087 | } else { |
@@ -1093,12 +1093,12 @@ discard block |
||
1093 | 1093 | break; |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - if ( $display_address_of_type ) { |
|
1097 | - $box_content = ! $admin_display ? self::display_address_interface_content( $address_type_id, $address_title, '', $address_type, $customer_id ) : ''; |
|
1098 | - $first_address_checking = ( empty( $box_content ) && ( 'shipping' === $address_type ) ) ? true : false; |
|
1096 | + if ($display_address_of_type) { |
|
1097 | + $box_content = !$admin_display ? self::display_address_interface_content($address_type_id, $address_title, '', $address_type, $customer_id) : ''; |
|
1098 | + $first_address_checking = (empty($box_content) && ('shipping' === $address_type)) ? true : false; |
|
1099 | 1099 | |
1100 | 1100 | ob_start(); |
1101 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ( $admin_display ? 'backend' : 'frontend' ), 'address', 'container' ) ); |
|
1101 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ($admin_display ? 'backend' : 'frontend'), 'address', 'container')); |
|
1102 | 1102 | $output .= ob_get_contents(); |
1103 | 1103 | ob_end_clean(); |
1104 | 1104 | } |
@@ -1121,22 +1121,22 @@ discard block |
||
1121 | 1121 | * |
1122 | 1122 | * @return [type] [description] |
1123 | 1123 | */ |
1124 | - public static function display_address_interface_content( $address_type_id, $address_title, $selected_address = null, $type, $customer_id = '', $admin_display = false, $order_id = '' ) { |
|
1125 | - $customer_id_from_cookie = ! empty( $_COOKIE ) && ! empty( $_COOKIE['wps_current_connected_customer'] ) ? (int) $_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ); |
|
1126 | - $customer_id = ! empty( $customer_id ) && ! empty( $customer_id ) && is_int( (int) $customer_id ) ? (int) $customer_id : $customer_id_from_cookie; |
|
1124 | + public static function display_address_interface_content($address_type_id, $address_title, $selected_address = null, $type, $customer_id = '', $admin_display = false, $order_id = '') { |
|
1125 | + $customer_id_from_cookie = !empty($_COOKIE) && !empty($_COOKIE['wps_current_connected_customer']) ? (int)$_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()); |
|
1126 | + $customer_id = !empty($customer_id) && !empty($customer_id) && is_int((int)$customer_id) ? (int)$customer_id : $customer_id_from_cookie; |
|
1127 | 1127 | |
1128 | - $select_id = ( ! empty( $type ) && ( 'shipping' === $type ) ) ? 'shipping_address_address_list' : 'billing_address_address_list'; |
|
1128 | + $select_id = (!empty($type) && ('shipping' === $type)) ? 'shipping_address_address_list' : 'billing_address_address_list'; |
|
1129 | 1129 | $output = ''; |
1130 | 1130 | |
1131 | - if ( ! empty( $address_type_id ) ) { |
|
1132 | - $addresses = self::get_addresses_list( $customer_id ); |
|
1133 | - $list_addresses = ( ! empty( $addresses[ $address_type_id ] ) ) ? $addresses[ $address_type_id ] : array(); |
|
1134 | - if ( empty( $list_addresses ) ) { |
|
1135 | - $form = self::display_form_fields( $address_type_id ); |
|
1131 | + if (!empty($address_type_id)) { |
|
1132 | + $addresses = self::get_addresses_list($customer_id); |
|
1133 | + $list_addresses = (!empty($addresses[$address_type_id])) ? $addresses[$address_type_id] : array(); |
|
1134 | + if (empty($list_addresses)) { |
|
1135 | + $form = self::display_form_fields($address_type_id); |
|
1136 | 1136 | } |
1137 | 1137 | |
1138 | 1138 | ob_start(); |
1139 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ( $admin_display ? 'backend' : 'frontend' ), 'address', 'content' ) ); |
|
1139 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, ($admin_display ? 'backend' : 'frontend'), 'address', 'content')); |
|
1140 | 1140 | $output .= ob_get_contents(); |
1141 | 1141 | ob_end_clean(); |
1142 | 1142 | } |
@@ -1151,14 +1151,14 @@ discard block |
||
1151 | 1151 | * @since 1.0 - WPShop 1.3.7.0 |
1152 | 1152 | */ |
1153 | 1153 | function display_addresses_list() { |
1154 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
1154 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
1155 | 1155 | |
1156 | - if ( !wp_verify_nonce( $_wpnonce, 'display_addresses_list' ) ) |
|
1156 | + if (!wp_verify_nonce($_wpnonce, 'display_addresses_list')) |
|
1157 | 1157 | die(); |
1158 | 1158 | |
1159 | - $post_id = (int) $_POST['post_id']; |
|
1160 | - $addresses = $this->get_addresses_list( $post_id ); |
|
1161 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses" ) ); |
|
1159 | + $post_id = (int)$_POST['post_id']; |
|
1160 | + $addresses = $this->get_addresses_list($post_id); |
|
1161 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses")); |
|
1162 | 1162 | die(); |
1163 | 1163 | } |
1164 | 1164 | |
@@ -1168,21 +1168,21 @@ discard block |
||
1168 | 1168 | * @since 1.0 - WPShop 1.3.7.0 |
1169 | 1169 | */ |
1170 | 1170 | function display_address() { |
1171 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
1171 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
1172 | 1172 | |
1173 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_display_an_address' ) ) |
|
1173 | + if (!wp_verify_nonce($_wpnonce, 'wps_address_display_an_address')) |
|
1174 | 1174 | die(); |
1175 | 1175 | |
1176 | - $adress_id = (int) $_POST['address_id']; |
|
1177 | - $address_post_meta = get_post_meta( $adress_id, '_wpshop_address_metadata', true); |
|
1178 | - $address_type_post_meta = get_post_meta( $adress_id, '_wpshop_address_attribute_set_id', true); |
|
1179 | - if( !empty($address_post_meta) && !empty($address_type_post_meta) ) { |
|
1180 | - $addresses_list[$address_type_post_meta][ $adress_id ] = $address_post_meta; |
|
1176 | + $adress_id = (int)$_POST['address_id']; |
|
1177 | + $address_post_meta = get_post_meta($adress_id, '_wpshop_address_metadata', true); |
|
1178 | + $address_type_post_meta = get_post_meta($adress_id, '_wpshop_address_attribute_set_id', true); |
|
1179 | + if (!empty($address_post_meta) && !empty($address_type_post_meta)) { |
|
1180 | + $addresses_list[$address_type_post_meta][$adress_id] = $address_post_meta; |
|
1181 | 1181 | } |
1182 | 1182 | $address_open = true; |
1183 | - foreach ( $addresses_list as $address_type => $addresses_list_by_type ) : |
|
1184 | - foreach ( $addresses_list_by_type as $address_id => $address ) : |
|
1185 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address" ) ); |
|
1183 | + foreach ($addresses_list as $address_type => $addresses_list_by_type) : |
|
1184 | + foreach ($addresses_list_by_type as $address_id => $address) : |
|
1185 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address")); |
|
1186 | 1186 | endforeach; |
1187 | 1187 | endforeach; |
1188 | 1188 | |
@@ -1197,29 +1197,29 @@ discard block |
||
1197 | 1197 | function display_address_adding_form() { |
1198 | 1198 | global $wpdb; |
1199 | 1199 | |
1200 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
1200 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
1201 | 1201 | |
1202 | - if ( !wp_verify_nonce( $_wpnonce, 'display_address_adding_form' ) ) |
|
1202 | + if (!wp_verify_nonce($_wpnonce, 'display_address_adding_form')) |
|
1203 | 1203 | die(); |
1204 | 1204 | |
1205 | 1205 | $address_id = 0; |
1206 | - $post_ID = (int)$_POST[ 'post_id' ]; |
|
1207 | - $element = get_post( $post_ID ); |
|
1208 | - $query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s ", $element->post_type); |
|
1209 | - $element_cpt = $wpdb->get_var( $query ); |
|
1210 | - $attached_addresses = get_post_meta( $element_cpt, '_wpshop_entity_attached_address', true ); |
|
1211 | - |
|
1212 | - if ( !empty( $attached_addresses ) ) { |
|
1213 | - if ( count( $attached_addresses ) == 1 ) { |
|
1214 | - $address_type_id = $attached_addresses[ 0 ]; |
|
1215 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form" ) ); |
|
1206 | + $post_ID = (int)$_POST['post_id']; |
|
1207 | + $element = get_post($post_ID); |
|
1208 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s ", $element->post_type); |
|
1209 | + $element_cpt = $wpdb->get_var($query); |
|
1210 | + $attached_addresses = get_post_meta($element_cpt, '_wpshop_entity_attached_address', true); |
|
1211 | + |
|
1212 | + if (!empty($attached_addresses)) { |
|
1213 | + if (count($attached_addresses) == 1) { |
|
1214 | + $address_type_id = $attached_addresses[0]; |
|
1215 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form")); |
|
1216 | 1216 | } |
1217 | 1217 | else { |
1218 | - require_once( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses", "types" ) ); |
|
1218 | + require_once(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "addresses", "types")); |
|
1219 | 1219 | } |
1220 | 1220 | } |
1221 | 1221 | else { |
1222 | - printf( __( 'No addresses are attached to this element type %s', 'wpeo_geoloc' ), $element->post_type); |
|
1222 | + printf(__('No addresses are attached to this element type %s', 'wpeo_geoloc'), $element->post_type); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | die(); |
@@ -1231,20 +1231,20 @@ discard block |
||
1231 | 1231 | * @since 1.0 - WPShop 1.3.7.0 |
1232 | 1232 | */ |
1233 | 1233 | function load_address_edition_form() { |
1234 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
1234 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
1235 | 1235 | |
1236 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_address_edition_form_load' ) ) |
|
1236 | + if (!wp_verify_nonce($_wpnonce, 'wps_address_edition_form_load')) |
|
1237 | 1237 | die(); |
1238 | 1238 | |
1239 | - $address_id = (int)$_POST[ 'element_id' ]; |
|
1240 | - $post_ID = (int)$_POST[ 'post_id' ]; |
|
1241 | - $address_type_id = get_post_meta( $address_id, '_wpshop_address_attribute_set_id', true); |
|
1242 | - $wpeogeo_adress = !empty( $_POST[ 'wpeogeo-address-type-chosen-for-creation' ] ) ? (int) $_POST[ 'wpeogeo-address-type-chosen-for-creation' ] : 0; |
|
1243 | - if ( empty( $address_id ) && empty( $address_type_id ) && !empty( $wpeogeo_adress ) ) { |
|
1239 | + $address_id = (int)$_POST['element_id']; |
|
1240 | + $post_ID = (int)$_POST['post_id']; |
|
1241 | + $address_type_id = get_post_meta($address_id, '_wpshop_address_attribute_set_id', true); |
|
1242 | + $wpeogeo_adress = !empty($_POST['wpeogeo-address-type-chosen-for-creation']) ? (int)$_POST['wpeogeo-address-type-chosen-for-creation'] : 0; |
|
1243 | + if (empty($address_id) && empty($address_type_id) && !empty($wpeogeo_adress)) { |
|
1244 | 1244 | $address_type_id = $wpeogeo_adress; |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - require( wpshop_tools::get_template_part( WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form" ) ); |
|
1247 | + require(wpshop_tools::get_template_part(WPS_ADDRESS_DIR, WPS_LOCALISATION_TEMPLATES_MAIN_DIR, "backend", "address", "form")); |
|
1248 | 1248 | die(); |
1249 | 1249 | } |
1250 | 1250 | |
@@ -1252,22 +1252,22 @@ discard block |
||
1252 | 1252 | * AJAX - Delete an address |
1253 | 1253 | */ |
1254 | 1254 | function wps_delete_an_address() { |
1255 | - $_wpnonce = ( !empty( $_REQUEST['_wpnonce'] ) ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
1255 | + $_wpnonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
1256 | 1256 | |
1257 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_delete_an_address' ) ) |
|
1257 | + if (!wp_verify_nonce($_wpnonce, 'wps_delete_an_address')) |
|
1258 | 1258 | die(); |
1259 | 1259 | |
1260 | 1260 | $status = false; $response = ''; |
1261 | - $address_id = ( !empty( $_POST['address_id']) ) ? (int) $_POST['address_id'] : null; |
|
1262 | - if( !empty($address_id) ) { |
|
1261 | + $address_id = (!empty($_POST['address_id'])) ? (int)$_POST['address_id'] : null; |
|
1262 | + if (!empty($address_id)) { |
|
1263 | 1263 | /** Check if user is author of address **/ |
1264 | - $address = get_post( $address_id ); |
|
1265 | - if( !empty($address) && !empty($address->post_type) && $address->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && !empty($address->post_author) && $address->post_author == get_current_user_id() ) { |
|
1266 | - wp_delete_post( $address_id, true ); |
|
1264 | + $address = get_post($address_id); |
|
1265 | + if (!empty($address) && !empty($address->post_type) && $address->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS && !empty($address->post_author) && $address->post_author == get_current_user_id()) { |
|
1266 | + wp_delete_post($address_id, true); |
|
1267 | 1267 | $status = true; |
1268 | 1268 | } |
1269 | 1269 | } |
1270 | - echo json_encode( array('status' => $status, 'response' => $response) ); |
|
1270 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
1271 | 1271 | die(); |
1272 | 1272 | } |
1273 | 1273 | |
@@ -1275,27 +1275,27 @@ discard block |
||
1275 | 1275 | * AJAX - Relad Address Interface in new checkout tunnel |
1276 | 1276 | */ |
1277 | 1277 | function wps_reload_address_interface() { |
1278 | - check_ajax_referer( 'wps_reload_address_interface' ); |
|
1278 | + check_ajax_referer('wps_reload_address_interface'); |
|
1279 | 1279 | |
1280 | 1280 | global $wpdb; |
1281 | 1281 | $status = false; $response = ''; |
1282 | - $address_type = !empty($_POST['address_type']) ? (int) $_POST['address_type'] : null; |
|
1283 | - $selected_address = !empty($_POST['address_id']) ? (int) $_POST['address_id'] : null; |
|
1282 | + $address_type = !empty($_POST['address_type']) ? (int)$_POST['address_type'] : null; |
|
1283 | + $selected_address = !empty($_POST['address_id']) ? (int)$_POST['address_id'] : null; |
|
1284 | 1284 | |
1285 | - if ( !empty( $address_type ) ) { |
|
1286 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
1287 | - if ( !empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type ) { |
|
1285 | + if (!empty($address_type)) { |
|
1286 | + $billing_option = get_option('wpshop_billing_address'); |
|
1287 | + if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $address_type) { |
|
1288 | 1288 | $type = 'billing'; |
1289 | 1289 | } |
1290 | 1290 | else { |
1291 | 1291 | $type = 'shipping'; |
1292 | 1292 | } |
1293 | - $query = $wpdb->prepare( 'SELECT name FROM '.WPSHOP_DBT_ATTRIBUTE_SET .' WHERE id = %d ', $address_type ); |
|
1294 | - $address_title = __( $wpdb->get_var( $query ), 'wpshop' ); |
|
1295 | - $response = self::display_address_interface_content( $address_type, $address_title, $selected_address, $type ); |
|
1293 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type); |
|
1294 | + $address_title = __($wpdb->get_var($query), 'wpshop'); |
|
1295 | + $response = self::display_address_interface_content($address_type, $address_title, $selected_address, $type); |
|
1296 | 1296 | $status = true; |
1297 | 1297 | } |
1298 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
1298 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
1299 | 1299 | die(); |
1300 | 1300 | } |
1301 | 1301 | |
@@ -1303,59 +1303,59 @@ discard block |
||
1303 | 1303 | * AJAX - Load address form in Modal Box |
1304 | 1304 | */ |
1305 | 1305 | function wps_load_address_form() { |
1306 | - $address_type_id = ( ! empty( $_POST['address_type_id'] ) ) ? sanitize_text_field( $_POST['address_type_id'] ) : ''; |
|
1307 | - check_ajax_referer( 'wps_load_address_form_' . $address_type_id ); |
|
1306 | + $address_type_id = (!empty($_POST['address_type_id'])) ? sanitize_text_field($_POST['address_type_id']) : ''; |
|
1307 | + check_ajax_referer('wps_load_address_form_' . $address_type_id); |
|
1308 | 1308 | |
1309 | - $address_id = ( ! empty( $_POST['address_id'] ) ) ? (int) $_POST['address_id'] : ''; |
|
1310 | - $customer_id_from_cookie = ! empty( $_COOKIE ) && ! empty( $_COOKIE['wps_current_connected_customer'] ) ? (int) $_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id( get_current_user_id() ); |
|
1309 | + $address_id = (!empty($_POST['address_id'])) ? (int)$_POST['address_id'] : ''; |
|
1310 | + $customer_id_from_cookie = !empty($_COOKIE) && !empty($_COOKIE['wps_current_connected_customer']) ? (int)$_COOKIE['wps_current_connected_customer'] : wps_customer_ctr::get_customer_id_by_author_id(get_current_user_id()); |
|
1311 | 1311 | |
1312 | - wp_die( wp_json_encode( self::loading_address_form( $address_type_id, $address_id, $customer_id_from_cookie ) ) ); |
|
1312 | + wp_die(wp_json_encode(self::loading_address_form($address_type_id, $address_id, $customer_id_from_cookie))); |
|
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | /** |
1316 | 1316 | * AJAX - Function for save address |
1317 | 1317 | */ |
1318 | 1318 | function wps_save_address() { |
1319 | - check_ajax_referer( 'wps_save_address' ); |
|
1319 | + check_ajax_referer('wps_save_address'); |
|
1320 | 1320 | global $wpshop, $wpdb; |
1321 | 1321 | |
1322 | 1322 | $status = false; |
1323 | 1323 | $result = $address_type = $same_address_type = ''; |
1324 | 1324 | |
1325 | - $adress_save_the_first = ! empty( $_POST['wps-address-save-the-first'] ) ? sanitize_text_field( $_POST['wps-address-save-the-first'] ) : ''; |
|
1326 | - $attribute = ! empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : ''; |
|
1325 | + $adress_save_the_first = !empty($_POST['wps-address-save-the-first']) ? sanitize_text_field($_POST['wps-address-save-the-first']) : ''; |
|
1326 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : ''; |
|
1327 | 1327 | |
1328 | - foreach ( $attribute as $id_group => $attribute_group ) { |
|
1328 | + foreach ($attribute as $id_group => $attribute_group) { |
|
1329 | 1329 | $address_type = $id_group; |
1330 | - $group = wps_address::get_addresss_form_fields_by_type( $id_group ); |
|
1331 | - foreach ( $group as $attribute_sets ) { |
|
1332 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
1333 | - $validate = $wpshop->validateForm( $attribute_set_field['content'], $attribute[ $id_group ], 'address_edition' ); |
|
1330 | + $group = wps_address::get_addresss_form_fields_by_type($id_group); |
|
1331 | + foreach ($group as $attribute_sets) { |
|
1332 | + foreach ($attribute_sets as $attribute_set_field) { |
|
1333 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute[$id_group], 'address_edition'); |
|
1334 | 1334 | } |
1335 | 1335 | |
1336 | - if ( $validate ) { |
|
1337 | - $shipping_save = self::save_address_infos( $id_group ); |
|
1336 | + if ($validate) { |
|
1337 | + $shipping_save = self::save_address_infos($id_group); |
|
1338 | 1338 | |
1339 | - $wps_shipping_to_billing = ! empty( $_POST['wps-shipping-to-billing'] ) ? sanitize_text_field( $_POST['wps-shipping-to-billing'] ) : ''; |
|
1340 | - if ( ! empty( $wps_shipping_to_billing ) ) { |
|
1341 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
1342 | - $shipping_option = get_option( 'wpshop_shipping_address_choice' ); |
|
1339 | + $wps_shipping_to_billing = !empty($_POST['wps-shipping-to-billing']) ? sanitize_text_field($_POST['wps-shipping-to-billing']) : ''; |
|
1340 | + if (!empty($wps_shipping_to_billing)) { |
|
1341 | + $billing_option = get_option('wpshop_billing_address'); |
|
1342 | + $shipping_option = get_option('wpshop_shipping_address_choice'); |
|
1343 | 1343 | |
1344 | - $address_info_to_copy = self::shipping_to_billing( $shipping_option['choice'], $billing_option['choice'] ); |
|
1345 | - self::save_address_infos( $billing_option['choice'], $shipping_save['current_id'], $address_info_to_copy ); |
|
1344 | + $address_info_to_copy = self::shipping_to_billing($shipping_option['choice'], $billing_option['choice']); |
|
1345 | + self::save_address_infos($billing_option['choice'], $shipping_save['current_id'], $address_info_to_copy); |
|
1346 | 1346 | $same_address_type = $billing_option['choice']; |
1347 | 1347 | } |
1348 | 1348 | |
1349 | 1349 | $status = true; |
1350 | - if ( ! empty( $adress_save_the_first ) ) { |
|
1351 | - $query = $wpdb->prepare( 'SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type ); |
|
1352 | - $address_title = __( $wpdb->get_var( $query ), 'wpshop' ); |
|
1353 | - $result = self::display_address_interface_content( $address_type, $address_title, $shipping_save['current_id'], $adress_save_the_first ); |
|
1350 | + if (!empty($adress_save_the_first)) { |
|
1351 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE id = %d ', $address_type); |
|
1352 | + $address_title = __($wpdb->get_var($query), 'wpshop'); |
|
1353 | + $result = self::display_address_interface_content($address_type, $address_title, $shipping_save['current_id'], $adress_save_the_first); |
|
1354 | 1354 | } |
1355 | 1355 | } else { |
1356 | - if ( ! empty( $wpshop->errors ) ) { |
|
1357 | - $result = '<div class="wps-alert wps-alert-error">' . __( 'Some errors have been detected', 'wpshop' ) . ' : <ul>'; |
|
1358 | - foreach ( $wpshop->errors as $error ) { |
|
1356 | + if (!empty($wpshop->errors)) { |
|
1357 | + $result = '<div class="wps-alert wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
1358 | + foreach ($wpshop->errors as $error) { |
|
1359 | 1359 | $result .= '<li>' . $error . '</li>'; |
1360 | 1360 | } |
1361 | 1361 | $result .= '</ul></div>'; |
@@ -1364,7 +1364,7 @@ discard block |
||
1364 | 1364 | } |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - wp_die( json_encode( array( $status, $result, $address_type, $same_address_type ) ) ); |
|
1367 | + wp_die(json_encode(array($status, $result, $address_type, $same_address_type))); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | } |
@@ -1,22 +1,22 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | |
3 | 3 | /** Get customer orders list for statistic displaying */ |
4 | 4 | $wps_orders_mdl = new wps_orders_mdl(); |
5 | - $orders = $wps_orders_mdl->get_customer_orders( $customer_post->ID ); |
|
6 | - $color_label = array( 'awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'pos' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge'); |
|
5 | + $orders = $wps_orders_mdl->get_customer_orders($customer_post->ID); |
|
6 | + $color_label = array('awaiting_payment' => 'jaune', 'canceled' => 'rouge', 'partially_paid' => 'orange', 'incorrect_amount' => 'orange', 'denied' => 'rouge', 'shipped' => 'bleu', 'pos' => 'bleu', 'payment_refused' => 'rouge', 'completed' => 'vert', 'refunded' => 'rouge'); |
|
7 | 7 | |
8 | -if ( !empty( $orders ) ) : |
|
9 | - $currency = wpshop_tools::wpshop_get_currency( false ); |
|
10 | - $orders_status = unserialize( WPSHOP_ORDER_STATUS ); |
|
8 | +if (!empty($orders)) : |
|
9 | + $currency = wpshop_tools::wpshop_get_currency(false); |
|
10 | + $orders_status = unserialize(WPSHOP_ORDER_STATUS); |
|
11 | 11 | $customer_order_total_amount = $customer_order_real_total_amount = 0; |
12 | 12 | $order_statuses = array(); |
13 | 13 | $ordered_products = array(); |
14 | - foreach( $orders as $order ) : |
|
15 | - $order_meta = get_post_meta( $order->ID, '_order_postmeta', true ); |
|
14 | + foreach ($orders as $order) : |
|
15 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
16 | 16 | ?> |
17 | - <a href="<?php echo admin_url( 'post.php?post=' . $order->ID . '&action=edit' ); ?>" ><strong>#<?php echo esc_attr( $order_meta['order_key'] ); ?></strong></a> |
|
18 | - <span style="margin-left: 20px; display:inline-block; width:65px;" ><?php echo wpshop_tools::formate_number( $order_meta['order_grand_total'] ).' '.$currency; ?></span> |
|
19 | - <span style="margin-left: 20px;" class="wps-label-<?php echo $color_label[ strtolower($order_meta['order_status']) ]; ?>"><?php _e( $orders_status[ strtolower($order_meta['order_status']) ], 'wpshop' ); ?></span> |
|
17 | + <a href="<?php echo admin_url('post.php?post=' . $order->ID . '&action=edit'); ?>" ><strong>#<?php echo esc_attr($order_meta['order_key']); ?></strong></a> |
|
18 | + <span style="margin-left: 20px; display:inline-block; width:65px;" ><?php echo wpshop_tools::formate_number($order_meta['order_grand_total']) . ' ' . $currency; ?></span> |
|
19 | + <span style="margin-left: 20px;" class="wps-label-<?php echo $color_label[strtolower($order_meta['order_status'])]; ?>"><?php _e($orders_status[strtolower($order_meta['order_status'])], 'wpshop'); ?></span> |
|
20 | 20 | <?php |
21 | 21 | break; |
22 | 22 | endforeach; |