|
@@ -8,7 +8,7 @@ discard block |
|
|
block discarded – undo |
|
8
|
8
|
* @subpackage modules |
|
9
|
9
|
*/ |
|
10
|
10
|
|
|
11
|
|
-if ( ! defined( 'ABSPATH' ) ) { |
|
|
11
|
+if (!defined('ABSPATH')) { |
|
12
|
12
|
exit; |
|
13
|
13
|
} |
|
14
|
14
|
|
|
@@ -29,26 +29,26 @@ discard block |
|
|
block discarded – undo |
|
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
|
34
|
// Appel du filtre permettant d'ajouter des informations dans la liste des méthodes de contacts dans les profil utilisateur. |
|
35
|
|
- add_filter( 'user_contactmethods', array( $this, 'add_contact_method_to_user' ), 20, 2 ); |
|
|
35
|
+ add_filter('user_contactmethods', array($this, 'add_contact_method_to_user'), 20, 2); |
|
36
|
36
|
|
|
37
|
|
- add_action( 'admin_enqueue_scripts', array( $this, 'callback_admin_enqueue_scripts' ), 11 ); |
|
38
|
|
- add_action( 'wp_enqueue_scripts', array( $this, 'callback_enqueue_scripts' ), 11 ); |
|
|
37
|
+ add_action('admin_enqueue_scripts', array($this, 'callback_admin_enqueue_scripts'), 11); |
|
|
38
|
+ add_action('wp_enqueue_scripts', array($this, 'callback_enqueue_scripts'), 11); |
|
39
|
39
|
|
|
40
|
40
|
/** 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 */ |
|
41
|
|
- add_action( 'wps_user_dashboard_header', array( $this, 'callback_customer_dashboard' ), 10, 2 ); |
|
|
41
|
+ add_action('wps_user_dashboard_header', array($this, 'callback_customer_dashboard'), 10, 2); |
|
42
|
42
|
|
|
43
|
43
|
// Association des utilisateurs à un client / Associate a user to a customer. |
|
44
|
|
- add_action( 'wp_ajax_wps_customer_contacts_associate', array( $this, 'ajax_callback_associate_user' ) ); |
|
|
44
|
+ add_action('wp_ajax_wps_customer_contacts_associate', array($this, 'ajax_callback_associate_user')); |
|
45
|
45
|
// Dissociation d'un utilisateur à un client / Dissociate a user from a customer. |
|
46
|
|
- add_action( 'wp_ajax_wps_customer_contacts_dissociate', array( $this, 'ajax_callback_dissociate_user' ) ); |
|
|
46
|
+ add_action('wp_ajax_wps_customer_contacts_dissociate', array($this, 'ajax_callback_dissociate_user')); |
|
47
|
47
|
// Changement de l'utilisateur par défaut (auteur) d'un client / Change the default user (author) for a customer. |
|
48
|
|
- add_action( 'wp_ajax_wps_customer_contacts_change_default', array( $this, 'ajax_callback_change_default_user' ) ); |
|
|
48
|
+ add_action('wp_ajax_wps_customer_contacts_change_default', array($this, 'ajax_callback_change_default_user')); |
|
49
|
49
|
|
|
50
|
50
|
// Changement de compte client dans le frontend pour l'utilisateur connecté / Switch between customer account for current connected user. |
|
51
|
|
- add_action( 'wp_ajax_wps_customer_switch_to', array( $this, 'ajax_callback_switch_customer' ) ); |
|
|
51
|
+ add_action('wp_ajax_wps_customer_switch_to', array($this, 'ajax_callback_switch_customer')); |
|
52
|
52
|
} |
|
53
|
53
|
|
|
54
|
54
|
/** |
|
@@ -56,8 +56,8 @@ discard block |
|
|
block discarded – undo |
|
56
|
56
|
* |
|
57
|
57
|
* @param string $post_type Le type d'élément sur lequel se trouve l'utilisateur / Element type where the user is. |
|
58
|
58
|
*/ |
|
59
|
|
- function add_meta_box( $post_type ) { |
|
60
|
|
- add_meta_box( 'wps_customer_contacts', __( 'Customer contact list', 'wpshop' ), array( $this, 'customer_contact_list_callback' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high' ); |
|
|
59
|
+ function add_meta_box($post_type) { |
|
|
60
|
+ add_meta_box('wps_customer_contacts', __('Customer contact list', 'wpshop'), array($this, 'customer_contact_list_callback'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high'); |
|
61
|
61
|
} |
|
62
|
62
|
|
|
63
|
63
|
/** |
|
@@ -67,15 +67,15 @@ discard block |
|
|
block discarded – undo |
|
67
|
67
|
*/ |
|
68
|
68
|
public function callback_admin_enqueue_scripts() { |
|
69
|
69
|
$screen = get_current_screen(); |
|
70
|
|
- if ( in_array( $screen->id, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
71
|
|
- wp_register_style( 'wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION ); |
|
72
|
|
- wp_enqueue_style( 'wps_customer_contacts-style' ); |
|
73
|
|
- 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 ); |
|
74
|
|
- wp_localize_script( 'wps_customer_contacts-script', 'wpshopCrm', array( |
|
75
|
|
- 'confirm_user_dissociation' => __( 'Are you sure you want to dissociate this user', 'wpshop' ), |
|
76
|
|
- 'confirm_change_default_user' => __( 'Are you sure you want to change default user for current customer?', 'wpshop' ), |
|
77
|
|
- ) ); |
|
78
|
|
- wp_enqueue_script( 'wps_customer_contacts-script' ); |
|
|
70
|
+ if (in_array($screen->id, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
|
71
|
+ wp_register_style('wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION); |
|
|
72
|
+ wp_enqueue_style('wps_customer_contacts-style'); |
|
|
73
|
+ 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); |
|
|
74
|
+ wp_localize_script('wps_customer_contacts-script', 'wpshopCrm', array( |
|
|
75
|
+ 'confirm_user_dissociation' => __('Are you sure you want to dissociate this user', 'wpshop'), |
|
|
76
|
+ 'confirm_change_default_user' => __('Are you sure you want to change default user for current customer?', 'wpshop'), |
|
|
77
|
+ )); |
|
|
78
|
+ wp_enqueue_script('wps_customer_contacts-script'); |
|
79
|
79
|
add_thickbox(); |
|
80
|
80
|
} |
|
81
|
81
|
} |
|
@@ -84,13 +84,13 @@ discard block |
|
|
block discarded – undo |
|
84
|
84
|
* Enqueue scripts and style in frontend |
|
85
|
85
|
*/ |
|
86
|
86
|
public function callback_enqueue_scripts() { |
|
87
|
|
- $pagename = get_query_var( 'pagename' ); |
|
88
|
|
- if ( in_array( $pagename, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
89
|
|
- wp_register_style( 'task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION ); |
|
90
|
|
- wp_enqueue_style( 'task-manager-frontend-style' ); |
|
|
87
|
+ $pagename = get_query_var('pagename'); |
|
|
88
|
+ if (in_array($pagename, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
|
89
|
+ wp_register_style('task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION); |
|
|
90
|
+ wp_enqueue_style('task-manager-frontend-style'); |
|
91
|
91
|
} |
|
92
|
|
- wp_register_script( 'wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION ); |
|
93
|
|
- wp_enqueue_script( 'wps_customer_contacts-frontend-script' ); |
|
|
92
|
+ wp_register_script('wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION); |
|
|
93
|
+ wp_enqueue_script('wps_customer_contacts-frontend-script'); |
|
94
|
94
|
} |
|
95
|
95
|
|
|
96
|
96
|
/** |
|
@@ -98,11 +98,11 @@ discard block |
|
|
block discarded – undo |
|
98
|
98
|
* |
|
99
|
99
|
* @param WP_Post $customer La définition principale du client actuellement en cours d'édition / Current edited customer definition. |
|
100
|
100
|
*/ |
|
101
|
|
- function customer_contact_list_callback( $customer ) { |
|
102
|
|
- $users = $this->get_customer_contact_list( $customer ); |
|
|
101
|
+ function customer_contact_list_callback($customer) { |
|
|
102
|
+ $users = $this->get_customer_contact_list($customer); |
|
103
|
103
|
|
|
104
|
104
|
/** Display user list for current customer */ |
|
105
|
|
- require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts' ) ); |
|
|
105
|
+ require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts')); |
|
106
|
106
|
} |
|
107
|
107
|
|
|
108
|
108
|
/** |
|
@@ -112,25 +112,25 @@ discard block |
|
|
block discarded – undo |
|
112
|
112
|
* |
|
113
|
113
|
* @return [type] [description] |
|
114
|
114
|
*/ |
|
115
|
|
- function get_customer_contact_list( $customer ) { |
|
|
115
|
+ function get_customer_contact_list($customer) { |
|
116
|
116
|
/** Define user list */ |
|
117
|
117
|
$users = array(); |
|
118
|
118
|
|
|
119
|
119
|
/** Get associated users' */ |
|
120
|
|
- $associated_users = (array) get_post_meta( $customer->ID, $this->user_contact_list_meta_key, true ); |
|
121
|
|
- $user_list = wp_parse_id_list( array_merge( $associated_users, array( $customer->post_author ) ) ); |
|
122
|
|
- if ( ! empty( $user_list ) ) { |
|
123
|
|
- foreach ( $user_list as $user_id ) { |
|
124
|
|
- if ( 0 !== $user_id ) { |
|
125
|
|
- $associated_user = get_user_by( 'ID', $user_id ); |
|
126
|
|
- $user_metas = get_user_meta( $user_id ); |
|
127
|
|
- if ( is_object( $associated_user ) ) { |
|
128
|
|
- $users[ $user_id ] = wp_parse_args( $associated_user->data, array( |
|
|
120
|
+ $associated_users = (array)get_post_meta($customer->ID, $this->user_contact_list_meta_key, true); |
|
|
121
|
+ $user_list = wp_parse_id_list(array_merge($associated_users, array($customer->post_author))); |
|
|
122
|
+ if (!empty($user_list)) { |
|
|
123
|
+ foreach ($user_list as $user_id) { |
|
|
124
|
+ if (0 !== $user_id) { |
|
|
125
|
+ $associated_user = get_user_by('ID', $user_id); |
|
|
126
|
+ $user_metas = get_user_meta($user_id); |
|
|
127
|
+ if (is_object($associated_user)) { |
|
|
128
|
+ $users[$user_id] = wp_parse_args($associated_user->data, array( |
|
129
|
129
|
'last_name' => $associated_user->last_name, |
|
130
|
130
|
'first_name' => $associated_user->first_name, |
|
131
|
|
- 'is_default' => ( $user_id === (int) $customer->post_author ? true : false ), |
|
|
131
|
+ 'is_default' => ($user_id === (int)$customer->post_author ? true : false), |
|
132
|
132
|
'metas' => $user_metas, |
|
133
|
|
- ) ); |
|
|
133
|
+ )); |
|
134
|
134
|
} |
|
135
|
135
|
} |
|
136
|
136
|
} |
|
@@ -145,20 +145,20 @@ discard block |
|
|
block discarded – undo |
|
145
|
145
|
* @param integer $user_id Identifiant de l'utilisateur actuellement connecté / User identifier currenly connected. |
|
146
|
146
|
* @param WP_User $account_user La définition du compte utilisateur / The user account definition. |
|
147
|
147
|
*/ |
|
148
|
|
- function callback_customer_dashboard( $user_id, $account_user ) { |
|
|
148
|
+ function callback_customer_dashboard($user_id, $account_user) { |
|
149
|
149
|
$customers = array(); |
|
150
|
150
|
|
|
151
|
|
- $customers_from_posts = new WP_Query( array( |
|
|
151
|
+ $customers_from_posts = new WP_Query(array( |
|
152
|
152
|
'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
153
|
153
|
'author' => $user_id, |
|
154
|
154
|
'posts_per_page' => -1, |
|
155
|
155
|
'post_status' => 'any', |
|
156
|
|
- ) ); |
|
157
|
|
- if ( $customers_from_posts->have_posts() ) { |
|
158
|
|
- $customers = array_merge( $customers, $customers_from_posts->posts ); |
|
|
156
|
+ )); |
|
|
157
|
+ if ($customers_from_posts->have_posts()) { |
|
|
158
|
+ $customers = array_merge($customers, $customers_from_posts->posts); |
|
159
|
159
|
} |
|
160
|
160
|
|
|
161
|
|
- $customers_from_meta = new WP_Query( array( |
|
|
161
|
+ $customers_from_meta = new WP_Query(array( |
|
162
|
162
|
'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
|
163
|
163
|
'posts_per_page' => -1, |
|
164
|
164
|
'post_status' => 'any', |
|
@@ -170,20 +170,20 @@ discard block |
|
|
block discarded – undo |
|
170
|
170
|
'type' => 'CHAR', |
|
171
|
171
|
), |
|
172
|
172
|
), |
|
173
|
|
- ) ); |
|
174
|
|
- if ( $customers_from_meta->have_posts() ) { |
|
175
|
|
- $customers = array_merge( $customers, $customers_from_meta->posts ); |
|
|
173
|
+ )); |
|
|
174
|
+ if ($customers_from_meta->have_posts()) { |
|
|
175
|
+ $customers = array_merge($customers, $customers_from_meta->posts); |
|
176
|
176
|
} |
|
177
|
|
- usort( $customers, function( $a, $b ) { |
|
178
|
|
- if ( $a->ID === $b->ID ) { |
|
|
177
|
+ usort($customers, function($a, $b) { |
|
|
178
|
+ if ($a->ID === $b->ID) { |
|
179
|
179
|
return 0; |
|
180
|
180
|
} |
|
181
|
181
|
return ($a < $b) ? -1 : 1; |
|
182
|
182
|
}); |
|
183
|
183
|
|
|
184
|
|
- if ( ! empty( $customers ) && ( 1 < count( $customers ) ) ) { |
|
|
184
|
+ if (!empty($customers) && (1 < count($customers))) { |
|
185
|
185
|
/** Display user list for current customer */ |
|
186
|
|
- require_once( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice' ) ); |
|
|
186
|
+ require_once(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice')); |
|
187
|
187
|
} |
|
188
|
188
|
} |
|
189
|
189
|
|
|
@@ -193,32 +193,32 @@ discard block |
|
|
block discarded – undo |
|
193
|
193
|
* @param array $contact_methods La liste actuelle des méthodes permettant de contacter l'utilisateur / The current method list to contact a user. |
|
194
|
194
|
* @param WP_user $user L'utilisateur en court d'édition / The current edited user. |
|
195
|
195
|
*/ |
|
196
|
|
- public function add_contact_method_to_user( $contact_methods, $user ) { |
|
|
196
|
+ public function add_contact_method_to_user($contact_methods, $user) { |
|
197
|
197
|
$wps_contact_method = array( |
|
198
|
|
- 'wps_phone' => __( 'Phone number', 'wpshop' ), |
|
|
198
|
+ 'wps_phone' => __('Phone number', 'wpshop'), |
|
199
|
199
|
); |
|
200
|
200
|
|
|
201
|
|
- return array_merge( $wps_contact_method, $contact_methods ); |
|
|
201
|
+ return array_merge($wps_contact_method, $contact_methods); |
|
202
|
202
|
} |
|
203
|
203
|
|
|
204
|
204
|
/** |
|
205
|
205
|
* Ajax callback - Associate a user to a customer |
|
206
|
206
|
*/ |
|
207
|
207
|
function ajax_callback_associate_user() { |
|
208
|
|
- check_ajax_referer( 'wps_customer_contacts_associate' ); |
|
|
208
|
+ check_ajax_referer('wps_customer_contacts_associate'); |
|
209
|
209
|
|
|
210
|
|
- $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
211
|
|
- $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
|
210
|
+ $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
|
211
|
+ $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
212
|
212
|
|
|
213
|
|
- $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
214
|
|
- if ( ! empty( $associated_users ) ) { |
|
215
|
|
- $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $user_id ) ) ); |
|
|
213
|
+ $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
|
214
|
+ if (!empty($associated_users)) { |
|
|
215
|
+ $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($user_id))); |
|
216
|
216
|
} else { |
|
217
|
|
- $new_associated_users = array( $user_id ); |
|
|
217
|
+ $new_associated_users = array($user_id); |
|
218
|
218
|
} |
|
219
|
219
|
|
|
220
|
|
- update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
221
|
|
- $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
|
220
|
+ update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
|
221
|
+ $this->customer_contact_list_callback(get_post($customer_id)); |
|
222
|
222
|
wp_die(); |
|
223
|
223
|
} |
|
224
|
224
|
|
|
@@ -226,20 +226,20 @@ discard block |
|
|
block discarded – undo |
|
226
|
226
|
* Ajax callback - Associate a user to a customer |
|
227
|
227
|
*/ |
|
228
|
228
|
function ajax_callback_dissociate_user() { |
|
229
|
|
- check_ajax_referer( 'wps_customer_contacts_dissociate' ); |
|
|
229
|
+ check_ajax_referer('wps_customer_contacts_dissociate'); |
|
230
|
230
|
|
|
231
|
|
- $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
232
|
|
- $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
|
231
|
+ $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
|
232
|
+ $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
233
|
233
|
|
|
234
|
|
- $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
235
|
|
- foreach ( $associated_users as $key => $id ) { |
|
236
|
|
- if ( $id === $user_id ) { |
|
237
|
|
- unset( $associated_users[ $key ] ); |
|
|
234
|
+ $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
|
235
|
+ foreach ($associated_users as $key => $id) { |
|
|
236
|
+ if ($id === $user_id) { |
|
|
237
|
+ unset($associated_users[$key]); |
|
238
|
238
|
} |
|
239
|
239
|
} |
|
240
|
240
|
|
|
241
|
|
- update_post_meta( $customer_id, $this->user_contact_list_meta_key, $associated_users ); |
|
242
|
|
- $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
|
241
|
+ update_post_meta($customer_id, $this->user_contact_list_meta_key, $associated_users); |
|
|
242
|
+ $this->customer_contact_list_callback(get_post($customer_id)); |
|
243
|
243
|
wp_die(); |
|
244
|
244
|
} |
|
245
|
245
|
|
|
@@ -247,30 +247,30 @@ discard block |
|
|
block discarded – undo |
|
247
|
247
|
* Ajax callback - Change the default user for a customer |
|
248
|
248
|
*/ |
|
249
|
249
|
function ajax_callback_change_default_user() { |
|
250
|
|
- check_ajax_referer( 'wps_customer_contacts_change_default' ); |
|
|
250
|
+ check_ajax_referer('wps_customer_contacts_change_default'); |
|
251
|
251
|
|
|
252
|
|
- $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
253
|
|
- $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
254
|
|
- $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; |
|
|
252
|
+ $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
|
253
|
+ $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
|
254
|
+ $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; |
|
255
|
255
|
|
|
256
|
|
- $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_author' => $user_id ), array( 'ID' => $customer_id ) ); |
|
257
|
|
- $customer_default_user_changes = get_post_meta( $customer_id, '_wps_customer_default_user_histo', true ); |
|
|
256
|
+ $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, array('post_author' => $user_id), array('ID' => $customer_id)); |
|
|
257
|
+ $customer_default_user_changes = get_post_meta($customer_id, '_wps_customer_default_user_histo', true); |
|
258
|
258
|
$customer_default_user_changes[] = array( |
|
259
|
|
- 'date' => current_time( 'mysql' ), |
|
|
259
|
+ 'date' => current_time('mysql'), |
|
260
|
260
|
'old_post_author' => $old_user_id, |
|
261
|
261
|
'update_author' => get_current_user_id(), |
|
262
|
262
|
); |
|
263
|
|
- update_post_meta( $customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes ); |
|
|
263
|
+ update_post_meta($customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes); |
|
264
|
264
|
|
|
265
|
|
- $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
266
|
|
- if ( ! empty( $associated_users ) ) { |
|
267
|
|
- $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $old_user_id ) ) ); |
|
|
265
|
+ $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
|
266
|
+ if (!empty($associated_users)) { |
|
|
267
|
+ $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($old_user_id))); |
|
268
|
268
|
} else { |
|
269
|
|
- $new_associated_users = array( $old_user_id ); |
|
|
269
|
+ $new_associated_users = array($old_user_id); |
|
270
|
270
|
} |
|
271
|
|
- update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
|
271
|
+ update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
272
|
272
|
|
|
273
|
|
- $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
|
273
|
+ $this->customer_contact_list_callback(get_post($customer_id)); |
|
274
|
274
|
wp_die(); |
|
275
|
275
|
} |
|
276
|
276
|
|
|
@@ -280,12 +280,12 @@ discard block |
|
|
block discarded – undo |
|
280
|
280
|
function ajax_callback_switch_customer() { |
|
281
|
281
|
// check_ajax_referer( 'wps-customer-switch-to' ); |
|
282
|
282
|
|
|
283
|
|
- $customer_id = ! empty( $_POST ) && ! empty( $_POST['cid'] ) && is_int( (int) $_POST['cid'] ) ? (int) $_POST['cid'] : null; |
|
|
283
|
+ $customer_id = !empty($_POST) && !empty($_POST['cid']) && is_int((int)$_POST['cid']) ? (int)$_POST['cid'] : null; |
|
284
|
284
|
|
|
285
|
|
- unset( $_COOKIE['wps_current_connected_customer'] ); |
|
286
|
|
- setcookie( 'wps_current_connected_customer', $customer_id, strtotime( '+30 days' ), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() ); |
|
|
285
|
+ unset($_COOKIE['wps_current_connected_customer']); |
|
|
286
|
+ setcookie('wps_current_connected_customer', $customer_id, strtotime('+30 days'), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl()); |
|
287
|
287
|
|
|
288
|
|
- wp_die( wp_json_encode( array( 'status' => true ) ) ); |
|
|
288
|
+ wp_die(wp_json_encode(array('status' => true))); |
|
289
|
289
|
} |
|
290
|
290
|
|
|
291
|
291
|
} |