Completed
Pull Request — master (#9)
by
unknown
40:20
created
includes/modules/wps_customer/controller/wps_customer_ctr.php 2 patches
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -334,8 +334,9 @@  discard block
 block discarded – undo
334 334
 			$user_details = get_user_by( 'email', $_REQUEST[ 'email' ] );
335 335
 			$user_id = $user_details->ID;
336 336
 
337
-			if( $location == 'users.php?update=add&id=' . $user_id )
338
-			return add_query_arg( array( 'user_id' => $user_id ), 'user-edit.php' );
337
+			if( $location == 'users.php?update=add&id=' . $user_id ) {
338
+						return add_query_arg( array( 'user_id' => $user_id ), 'user-edit.php' );
339
+			}
339 340
 		}
340 341
 
341 342
 		return $location;
@@ -529,8 +530,10 @@  discard block
 block discarded – undo
529 530
 				$last_login = get_user_meta( $customer_post_author, 'last_login_time', true );
530 531
 				if ( ! empty( $last_login ) ) :
531 532
 					echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $last_login, true );
532
-				else :
533
+				else {
534
+					:
533 535
 					_e( 'Never logged in', 'wpshop' );
536
+				}
534 537
 				endif;
535 538
 				$use_template = false;
536 539
 			break;
Please login to merge, or discard this patch.
Spacing   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @subpackage Customer
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -29,32 +29,32 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	public function __construct() {
31 31
 		/** Create customer entity type on wordpress initilisation */
32
-		add_action( 'init', array( $this, 'create_customer_entity' ) );
32
+		add_action('init', array($this, 'create_customer_entity'));
33 33
 
34 34
 		// Redirection vers la page d'édition d'un utilisateur après sa création.
35
-		add_filter( 'wp_redirect', array( $this, 'wp_redirect_after_user_new' ), 1 );
35
+		add_filter('wp_redirect', array($this, 'wp_redirect_after_user_new'), 1);
36 36
 
37
-		add_filter( 'wp_redirect', array( $this, 'wp_redirect_after_user_new' ), 1 );
37
+		add_filter('wp_redirect', array($this, 'wp_redirect_after_user_new'), 1);
38 38
 
39 39
 		/** When a wordpress user is created, create a customer (post type) */
40
-		add_action( 'user_register', array( $this, 'create_entity_customer_when_user_is_created' ) );
41
-		add_action( 'edit_user_profile_update', array( $this, 'update_entity_customer_when_profile_user_is_update' ) );
40
+		add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
41
+		add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
42 42
 
43 43
 		/** Add filters for customer list */
44
-		add_filter( 'bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array( $this, 'customer_list_table_bulk_actions' ) );
45
-		add_filter( 'manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array( $this, 'list_table_header' ) );
46
-		add_action( 'manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array( $this, 'list_table_column_content' ), 10, 2 );
47
-		add_action( 'restrict_manage_posts', array( &$this, 'list_table_filters' ) );
48
-		add_filter( 'parse_query', array( &$this, 'list_table_filter_parse_query' ) );
44
+		add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
45
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
46
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
47
+		add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
48
+		add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
49 49
 
50 50
 		/** Filter search for customers */
51 51
 		//add_filter( 'pre_get_posts', array( $this, 'customer_search' ) );
52 52
 
53 53
 		/** Customer options for the shop */
54
-		add_action( 'wsphop_options', array( &$this, 'declare_options' ), 8 );
55
-		add_action( 'wp_ajax_wps_customer_search', array( $this, 'ajax_search_customer' ) );
54
+		add_action('wsphop_options', array(&$this, 'declare_options'), 8);
55
+		add_action('wp_ajax_wps_customer_search', array($this, 'ajax_search_customer'));
56 56
 
57
-		add_action( 'wp_login', array( $this, 'hook_login_for_setting_customer_id' ), 10, 2 );
57
+		add_action('wp_login', array($this, 'hook_login_for_setting_customer_id'), 10, 2);
58 58
 	}
59 59
 
60 60
 	/**
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return string L'affichage de la lsite déroulanet contenant les clients de la boutique / THe select list of customers
68 68
 	 */
69
-	public static function customer_select( $selected_user = 0, $multiple = false, $disabled = false ) {
69
+	public static function customer_select($selected_user = 0, $multiple = false, $disabled = false) {
70 70
 		$content_output = '';
71 71
 
72 72
 		$wps_customer_mdl = new wps_customer_mdl();
73 73
 		$customers = $wps_customer_mdl->get_customer_list( -1 );
74 74
 
75
-		require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_TPL, 'common', 'customer', 'select' ) );
75
+		require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_TPL, 'common', 'customer', 'select'));
76 76
 
77 77
 		return $content_output;
78 78
 	}
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 * @param	string		$user_login le nom d'utilisateur de l'utilisateur actuellement connecté / Username of current connected user.
84 84
 	 * @param	WP_Object $user			 l'objet WP_User correspond à l'utilisateur actuellement connecté / Current connected user WP_Object definition.
85 85
 	 */
86
-	public function hook_login_for_setting_customer_id( $user_login, $user ) {
87
-		 setcookie( 'wps_current_connected_customer', self::get_customer_id_by_author_id( $user->ID ), strtotime( '+30 days' ), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() );
86
+	public function hook_login_for_setting_customer_id($user_login, $user) {
87
+		 setcookie('wps_current_connected_customer', self::get_customer_id_by_author_id($user->ID), strtotime('+30 days'), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl());
88 88
 	}
89 89
 
90 90
 	/**
91 91
 	 * AJAX callback for customer search
92 92
 	 */
93 93
 	public function ajax_search_customer() {
94
-		check_ajax_referer( 'wps_customer_search' );
94
+		check_ajax_referer('wps_customer_search');
95 95
 
96
-		$term = ! empty( $_GET ) && ! empty( $_GET['term'] ) && is_string( (string) $_GET['term'] ) ? (string) $_GET['term'] : $term;
97
-		$list = $this->search_customer( $term );
96
+		$term = !empty($_GET) && !empty($_GET['term']) && is_string((string)$_GET['term']) ? (string)$_GET['term'] : $term;
97
+		$list = $this->search_customer($term);
98 98
 
99
-		wp_die( wp_json_encode( $list ) );
99
+		wp_die(wp_json_encode($list));
100 100
 	}
101 101
 
102 102
 	/**
@@ -104,23 +104,23 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données.
106 106
 	 */
107
-	public function search_customer( $term ) {
107
+	public function search_customer($term) {
108 108
 		$users = array();
109
-		$search_users = new WP_User_Query( array(
110
-			'search'				 => '*' . esc_attr( $term ) . '*',
111
-			'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ),
112
-		) );
109
+		$search_users = new WP_User_Query(array(
110
+			'search'				 => '*' . esc_attr($term) . '*',
111
+			'search_columns' => array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'),
112
+		));
113 113
 		$user_query_results = $search_users->get_results();
114
-		if ( ! empty( $user_query_results ) ) {
115
-			foreach ( $user_query_results as $user ) {
116
-				$users[ $user->ID ]['id'] = $user->ID;
117
-				$users[ $user->ID ]['display_name'] = $user->display_name;
118
-				$users[ $user->ID ]['email'] = $user->user_email;
119
-				$users[ $user->ID ]['last_name'] = $user->last_name;
120
-				$users[ $user->ID ]['first_name'] = $user->first_name;
114
+		if (!empty($user_query_results)) {
115
+			foreach ($user_query_results as $user) {
116
+				$users[$user->ID]['id'] = $user->ID;
117
+				$users[$user->ID]['display_name'] = $user->display_name;
118
+				$users[$user->ID]['email'] = $user->user_email;
119
+				$users[$user->ID]['last_name'] = $user->last_name;
120
+				$users[$user->ID]['first_name'] = $user->first_name;
121 121
 			}
122 122
 		}
123
-		$search_users_in_meta = new WP_User_Query( array(
123
+		$search_users_in_meta = new WP_User_Query(array(
124 124
 			'meta_query'		 => array(
125 125
 				'relation' => 'OR',
126 126
 				array(
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
 					'compare' => 'LIKE',
135 135
 				),
136 136
 			),
137
-		) );
137
+		));
138 138
 		$user_query_results_2 = $search_users_in_meta->get_results();
139
-		if ( ! empty( $user_query_results_2 ) ) {
140
-			foreach ( $user_query_results_2 as $user ) {
141
-				$users[ $user->ID ]['id'] = $user->ID;
142
-				$users[ $user->ID ]['display_name'] = $user->display_name;
143
-				$users[ $user->ID ]['email'] = $user->user_email;
144
-				$users[ $user->ID ]['last_name'] = $user->last_name;
145
-				$users[ $user->ID ]['first_name'] = $user->first_name;
139
+		if (!empty($user_query_results_2)) {
140
+			foreach ($user_query_results_2 as $user) {
141
+				$users[$user->ID]['id'] = $user->ID;
142
+				$users[$user->ID]['display_name'] = $user->display_name;
143
+				$users[$user->ID]['email'] = $user->user_email;
144
+				$users[$user->ID]['last_name'] = $user->last_name;
145
+				$users[$user->ID]['first_name'] = $user->first_name;
146 146
 			}
147 147
 		}
148
-		if ( empty( $users ) ) {
148
+		if (empty($users)) {
149 149
 			$users[] = array(
150 150
 				'id'		=> null,
151
-				'label'	=> __( 'Create a new user', 'wpshop' ),
151
+				'label'	=> __('Create a new user', 'wpshop'),
152 152
 			);
153 153
 		}
154 154
 
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @return int $customer_id
164 164
 	 */
165
-	public static function get_customer_id_by_author_id( $author_id ) {
166
-		if ( ! isset( self::$customer_user_identifier_cache[ $author_id ] ) ) {
167
-			$query = $GLOBALS['wpdb']->prepare( "SELECT ID FROM {$GLOBALS['wpdb']->posts} WHERE post_author = %d AND post_type = %s ORDER BY ID ASC", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS );
168
-			self::$customer_user_identifier_cache[ $author_id ] = $GLOBALS['wpdb']->get_var( $query );
165
+	public static function get_customer_id_by_author_id($author_id) {
166
+		if (!isset(self::$customer_user_identifier_cache[$author_id])) {
167
+			$query = $GLOBALS['wpdb']->prepare("SELECT ID FROM {$GLOBALS['wpdb']->posts} WHERE post_author = %d AND post_type = %s ORDER BY ID ASC", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
168
+			self::$customer_user_identifier_cache[$author_id] = $GLOBALS['wpdb']->get_var($query);
169 169
 		}
170 170
 
171
-		return self::$customer_user_identifier_cache[ $author_id ];
171
+		return self::$customer_user_identifier_cache[$author_id];
172 172
 	}
173 173
 
174 174
 	/**
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return int
181 181
 	 */
182
-	public static function get_author_id_by_customer_id( $customer_id ) {
183
-		$flipped = ! empty( self::$customer_user_identifier_cache ) ? array_flip( self::$customer_user_identifier_cache ) : '';
184
-		if ( ! isset( $flipped[ $customer_id ] ) ) {
185
-			$author_id = $GLOBALS['wpdb']->get_var( $GLOBALS['wpdb']->prepare( "SELECT post_author FROM {$GLOBALS['wpdb']->posts} WHERE ID = %d", $customer_id ) );
186
-			self::$customer_user_identifier_cache[ $author_id ] = $customer_id;
187
-			$flipped[ $customer_id ] = $author_id;
182
+	public static function get_author_id_by_customer_id($customer_id) {
183
+		$flipped = !empty(self::$customer_user_identifier_cache) ? array_flip(self::$customer_user_identifier_cache) : '';
184
+		if (!isset($flipped[$customer_id])) {
185
+			$author_id = $GLOBALS['wpdb']->get_var($GLOBALS['wpdb']->prepare("SELECT post_author FROM {$GLOBALS['wpdb']->posts} WHERE ID = %d", $customer_id));
186
+			self::$customer_user_identifier_cache[$author_id] = $customer_id;
187
+			$flipped[$customer_id] = $author_id;
188 188
 		}
189 189
 
190
-		return $flipped[ $customer_id ];
190
+		return $flipped[$customer_id];
191 191
 	}
192 192
 
193 193
 	/**
@@ -195,26 +195,26 @@  discard block
 block discarded – undo
195 195
 	 */
196 196
 	public function create_customer_entity() {
197 197
 		global $wpdb;
198
-		$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_CUSTOMERS, '_wpshop_entity_params' );
199
-		$customer_entity_definition = $wpdb->get_row( $query ); // WPCS: unprepared sql ok.
200
-		$current_entity_params = ! empty( $customer_entity_definition ) && ! empty( $customer_entity_definition->meta_value ) ? unserialize( $customer_entity_definition->meta_value ) : null;
198
+		$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_CUSTOMERS, '_wpshop_entity_params');
199
+		$customer_entity_definition = $wpdb->get_row($query); // WPCS: unprepared sql ok.
200
+		$current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null;
201 201
 
202 202
 		$post_type_params = array(
203 203
 			'labels' => array(
204
-				'name' => __( 'Customers', 'wpshop' ),
205
-				'singular_name' => __( 'Customer', 'wpshop' ),
206
-				'add_new_item' => __( 'New customer', 'wpshop' ),
207
-				'add_new' => __( 'New customer', 'wpshop' ),
208
-				'edit_item' => __( 'Edit customer', 'wpshop' ),
209
-				'new_item' => __( 'New customer', 'wpshop' ),
210
-				'view_item' => __( 'View customer', 'wpshop' ),
211
-				'search_items' => __( 'Search in customers', 'wpshop' ),
212
-				'not_found' => __( 'No customer found', 'wpshop' ),
213
-				'not_found_in_trash' => __( 'No customer founded in trash', 'wpshop' ),
204
+				'name' => __('Customers', 'wpshop'),
205
+				'singular_name' => __('Customer', 'wpshop'),
206
+				'add_new_item' => __('New customer', 'wpshop'),
207
+				'add_new' => __('New customer', 'wpshop'),
208
+				'edit_item' => __('Edit customer', 'wpshop'),
209
+				'new_item' => __('New customer', 'wpshop'),
210
+				'view_item' => __('View customer', 'wpshop'),
211
+				'search_items' => __('Search in customers', 'wpshop'),
212
+				'not_found' => __('No customer found', 'wpshop'),
213
+				'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
214 214
 				'parent_item_colon' => '',
215 215
 			),
216 216
 			'description' => '',
217
-			'supports' => ! empty( $current_entity_params['support'] ) ? $current_entity_params['support'] : array( 'title' ),
217
+			'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
218 218
 			'hierarchical' => false,
219 219
 			'public' => false,
220 220
 			'show_ui' => true,
@@ -239,22 +239,22 @@  discard block
 block discarded – undo
239 239
 			),
240 240
 		);
241 241
 
242
-		register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params );
242
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params);
243 243
 	}
244 244
 
245 245
 	/**
246 246
 	 * Customer options for the shop
247 247
 	 */
248 248
 	public static function declare_options() {
249
-		if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) {
250
-			$wpshop_shop_type = ! empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : '';
251
-			$old_wpshop_shop_type = ! empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : '';
249
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
250
+			$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
251
+			$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
252 252
 
253
-			if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' )
254
-					&& ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) {
253
+			if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
254
+					&& ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
255 255
 					/**		Add module option to wpshop general options		*/
256
-					register_setting( 'wpshop_options', 'wpshop_cart_option', array( 'wps_customer_ctr', 'wpshop_options_validate_customers_newsleters' ) );
257
-					add_settings_field( 'display_newsletters_subscriptions', __( 'Display newsletters subscriptions', 'wpshop' ), array( 'wps_customer_ctr', 'display_newsletters_subscriptions' ), 'wpshop_cart_info', 'wpshop_cart_info' );
256
+					register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
257
+					add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
258 258
 			}
259 259
 		}
260 260
 	}
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 * @return array Les réglages des clients qui ont été vérifiés
268 268
 	 */
269
-	public static function wpshop_options_validate_customers_newsleters( $input ) {
269
+	public static function wpshop_options_validate_customers_newsleters($input) {
270 270
 			return $input;
271 271
 	}
272 272
 
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * Affichage des champs permettant les réglages concernant les newsletters des clients dans les réglages de la boutique
275 275
 	 */
276 276
 	public static function display_newsletters_subscriptions() {
277
-		$cart_option = get_option( 'wpshop_cart_option', array() );
277
+		$cart_option = get_option('wpshop_cart_option', array());
278 278
 		$output = '';
279 279
 
280 280
 		$input_def = array();
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
 		$input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription';
283 283
 		$input_def['type'] = 'checkbox';
284 284
 		$input_def['valueToPut'] = 'index';
285
-		$input_def['value'] = ! empty( $cart_option['display_newsletter']['site_subscription'] ) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
285
+		$input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
286 286
 		$input_def['possible_value'] = 'yes';
287
-		$output .= wpshop_form::check_input_type( $input_def, 'wpshop_cart_option[display_newsletter][site_subscription]' ) . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the site', 'wpshop' ) . '</label><a href="#" title="' . __( 'Check this box if you want display newsletter site subscription', 'wpshop' ) . '" class="wpshop_infobulle_marker">?</a><br>';
287
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label><a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a><br>';
288 288
 
289 289
 		$input_def = array();
290 290
 		$input_def['name'] = '';
291 291
 		$input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription';
292 292
 		$input_def['type'] = 'checkbox';
293 293
 		$input_def['valueToPut'] = 'index';
294
-		$input_def['value'] = ! empty( $cart_option['display_newsletter']['partner_subscription'] ) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
294
+		$input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
295 295
 		$input_def['possible_value'] = 'yes';
296
-		$output .= wpshop_form::check_input_type( $input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]' ) . '<label for="' . $input_def['id'] . '">' . __( 'Newsletters of the partners', 'wpshop' ) . '</label><a href="#" title="' . __( 'Check this box if you want display newsletter partners subscription', 'wpshop' ) . '" class="wpshop_infobulle_marker">?</a><br>';
296
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label><a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a><br>';
297 297
 
298 298
 		echo $output; // WPCS: XSS ok.
299 299
 	}
@@ -307,30 +307,30 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @return string           La nouvelle url pour la redirection.
309 309
 	 */
310
-	public function wp_redirect_after_user_new( $location ) {
310
+	public function wp_redirect_after_user_new($location) {
311 311
 		global $pagenow;
312 312
 
313
-		if ( is_admin() && 'user-new.php' === $pagenow ) {
314
-			$user_details = get_user_by( 'email', $_REQUEST['email'] );
313
+		if (is_admin() && 'user-new.php' === $pagenow) {
314
+			$user_details = get_user_by('email', $_REQUEST['email']);
315 315
 			$user_id = $user_details->ID;
316 316
 
317
-			if ( 'users.php?update=add&id=' . $user_id === $location ) {
318
-				return add_query_arg( array( 'user_id' => $user_id ), 'user-edit.php' );
317
+			if ('users.php?update=add&id=' . $user_id === $location) {
318
+				return add_query_arg(array('user_id' => $user_id), 'user-edit.php');
319 319
 			}
320 320
 		}
321 321
 
322 322
 		return $location;
323 323
 	}
324 324
 
325
-	public function wp_redirect_after_user_new( $location ) {
325
+	public function wp_redirect_after_user_new($location) {
326 326
 		global $pagenow;
327 327
 
328
-		if ( is_admin() && $pagenow === 'user-new.php' ) {
329
-			$user_details = get_user_by( 'email', $_REQUEST[ 'email' ] );
328
+		if (is_admin() && $pagenow === 'user-new.php') {
329
+			$user_details = get_user_by('email', $_REQUEST['email']);
330 330
 			$user_id = $user_details->ID;
331 331
 
332
-			if( $location == 'users.php?update=add&id=' . $user_id )
333
-			return add_query_arg( array( 'user_id' => $user_id ), 'user-edit.php' );
332
+			if ($location == 'users.php?update=add&id=' . $user_id)
333
+			return add_query_arg(array('user_id' => $user_id), 'user-edit.php');
334 334
 		}
335 335
 
336 336
 		return $location;
@@ -348,25 +348,25 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @param integer $user_id L'identifiant de l'utilisateur qui vient d'être créé et pour qui on va créer le client.
350 350
 	 */
351
-	public static function create_entity_customer_when_user_is_created( $user_id ) {
352
-		if ( ! is_admin() || strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' )  ) {
353
-			$user_data = get_userdata( $user_id );
354
-			$user_info = array_merge( get_object_vars( $user_data->data ), array_map( 'self::array_map_create_entity_customer_when_user_is_created', get_user_meta( $user_id ) ) );
355
-			$customer_post_ID = wp_insert_post( array( 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename ) );
356
-			self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info );
351
+	public static function create_entity_customer_when_user_is_created($user_id) {
352
+		if (!is_admin() || strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php')) {
353
+			$user_data = get_userdata($user_id);
354
+			$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
355
+			$customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
356
+			self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
357 357
 
358 358
 			/** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox */
359
-			$usermeta = get_post_meta( $user_id, 'metaboxhidden_nav-menus', true );
360
-			if ( ! empty( $usermeta ) && is_array( $usermeta ) ) {
361
-				$data_to_delete = array_search( 'add-wpshop_product_category', $usermeta );
362
-				if ( false !== $data_to_delete ) {
363
-					unset( $usermeta[ $data_to_delete ] );
364
-					update_user_meta( $user_id, 'metaboxhidden_nav-menus', $usermeta );
359
+			$usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true);
360
+			if (!empty($usermeta) && is_array($usermeta)) {
361
+				$data_to_delete = array_search('add-wpshop_product_category', $usermeta);
362
+				if (false !== $data_to_delete) {
363
+					unset($usermeta[$data_to_delete]);
364
+					update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta);
365 365
 				}
366 366
 			}
367 367
 		}
368 368
 	}
369
-	private static function array_map_create_entity_customer_when_user_is_created( $a ) {
369
+	private static function array_map_create_entity_customer_when_user_is_created($a) {
370 370
 			return $a[0];
371 371
 	}
372 372
 
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 	 *
376 376
 	 * @param integer $user_id
377 377
 	 */
378
-	public static function update_entity_customer_when_profile_user_is_update( $user_id ) {
378
+	public static function update_entity_customer_when_profile_user_is_update($user_id) {
379 379
 			$user_data = get_userdata($user_id);
380 380
 			$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
381 381
 			$customer_post_ID = self::get_customer_id_by_author_id($user_id);
382 382
 			self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
383 383
 	}
384 384
 
385
-	private static function array_map_update_entity_customer_when_profile_user_is_update( $a ) {
385
+	private static function array_map_update_entity_customer_when_profile_user_is_update($a) {
386 386
 			return $a[0];
387 387
 	}
388 388
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 		return false;
392 392
 	}
393 393
 
394
-	public static function save_customer_synchronize( $customer_post_ID, $user_id, $user_info ) {
394
+	public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info) {
395 395
 		global $wpdb;
396 396
 		global $wpshop;
397 397
 		$exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
401 401
 		$attribute_set_id = $wpdb->get_var($query);
402 402
 		$attributes_default = array();
403
-		if (! empty($attribute_set_id)) {
403
+		if (!empty($attribute_set_id)) {
404 404
 			$group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
405 405
 			foreach ($group as $attribute_sets) {
406 406
 				foreach ($attribute_sets as $attribute_set_field) {
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
 			}
421 421
 		}
422 422
 		$user_info = array_merge($attributes_default, $user_info);
423
-		add_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
423
+		add_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress'));
424 424
 		foreach ($user_info as $user_meta => $user_meta_value) {
425 425
 			$attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
426
-			if (! empty($attribute_def)) {
426
+			if (!empty($attribute_def)) {
427 427
 				//Save data in user meta
428 428
 				if (in_array($user_meta, $exclude_user_meta)) {
429 429
 					if ($user_meta == 'user_pass') {
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 				//Save data in attribute tables, ckeck first if exist to know if Insert or Update
440 440
 				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
441 441
 				$checking_attribute_exist = $wpdb->get_results($query);
442
-				if (! empty($checking_attribute_exist)) {
442
+				if (!empty($checking_attribute_exist)) {
443 443
 					$wpdb->update(
444 444
 						WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
445 445
 						array(
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 				}
467 467
 			}
468 468
 		}
469
-		remove_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) );
469
+		remove_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress'));
470 470
 	}
471 471
 
472 472
 	/**
@@ -476,17 +476,17 @@  discard block
 block discarded – undo
476 476
 	 *
477 477
 	 * @return array The new header to display
478 478
 	 */
479
-	public function list_table_header( $current_header ) {
480
-		unset( $current_header['title'] );
481
-		unset( $current_header['date'] );
479
+	public function list_table_header($current_header) {
480
+		unset($current_header['title']);
481
+		unset($current_header['date']);
482 482
 
483
-		$current_header['customer_identifier'] = __( 'Customer ID', 'wpshop' );
484
-		$current_header['customer-name'] = __( 'Customer name', 'wpshop' );
483
+		$current_header['customer_identifier'] = __('Customer ID', 'wpshop');
484
+		$current_header['customer-name'] = __('Customer name', 'wpshop');
485 485
 		// $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
486 486
 		// $current_header['customer_email'] = __('E-mail', 'wpshop');
487
-		$current_header['customer-contacts'] = __( 'Contacts', 'wpshop' );
488
-		$current_header['customer-orders'] = __( 'Customer last order', 'wpshop' );
489
-		$current_header['customer_date_subscription'] = __( 'Subscription', 'wpshop' );
487
+		$current_header['customer-contacts'] = __('Contacts', 'wpshop');
488
+		$current_header['customer-orders'] = __('Customer last order', 'wpshop');
489
+		$current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
490 490
 		// $current_header['customer_date_lastlogin'] = __( 'Last login date', 'wpshop' );
491 491
 
492 492
 		return $current_header;
@@ -498,43 +498,43 @@  discard block
 block discarded – undo
498 498
 	 * @param string  $column THe column identifier to modify output for.
499 499
 	 * @param integer $post_id The current post identifier.
500 500
 	 */
501
-	public function list_table_column_content( $column, $post_id ) {
501
+	public function list_table_column_content($column, $post_id) {
502 502
 		global $wpdb;
503 503
 
504 504
 		/**		Get wp_users identifier from customer id		*/
505
-		$customer_post_author = self::get_author_id_by_customer_id( $post_id );
505
+		$customer_post_author = self::get_author_id_by_customer_id($post_id);
506 506
 
507 507
 		/**		Get current post informations		*/
508
-		$customer_post = get_post( $post_id );
508
+		$customer_post = get_post($post_id);
509 509
 
510 510
 		/**		Switch current column for custom case		*/
511 511
 		$use_template = true;
512
-		switch ( $column ) {
512
+		switch ($column) {
513 513
 			case 'customer_identifier' :
514 514
 				echo $post_id;
515 515
 				$use_template = false;
516 516
 			break;
517 517
 
518 518
 			case 'customer_date_subscription' :
519
-				echo mysql2date( get_option( 'date_format' ), $customer_post->post_date, true );
519
+				echo mysql2date(get_option('date_format'), $customer_post->post_date, true);
520 520
 				$use_template = false;
521 521
 			break;
522 522
 
523 523
 			case 'customer_date_lastlogin' :
524
-				$last_login = get_user_meta( $customer_post_author, 'last_login_time', true );
525
-				if ( ! empty( $last_login ) ) :
526
-					echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $last_login, true );
524
+				$last_login = get_user_meta($customer_post_author, 'last_login_time', true);
525
+				if (!empty($last_login)) :
526
+					echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
527 527
 				else :
528
-					_e( 'Never logged in', 'wpshop' );
528
+					_e('Never logged in', 'wpshop');
529 529
 				endif;
530 530
 				$use_template = false;
531 531
 			break;
532 532
 		}
533 533
 
534 534
 		/**		Require the template for displaying the current column		*/
535
-		if ( $use_template ) {
536
-			$template = wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column );
537
-			if ( is_file( $template ) ) {
535
+		if ($use_template) {
536
+			$template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column);
537
+			if (is_file($template)) {
538 538
 				require $template;
539 539
 			}
540 540
 		}
@@ -547,33 +547,33 @@  discard block
 block discarded – undo
547 547
 	 *
548 548
 	 * @return array The new action list to use into customer list table
549 549
 	 */
550
-	public function customer_list_table_bulk_actions( $actions ) {
551
-		unset( $actions['edit'] );
552
-		unset( $actions['trash'] );
550
+	public function customer_list_table_bulk_actions($actions) {
551
+		unset($actions['edit']);
552
+		unset($actions['trash']);
553 553
 
554 554
 		return $actions;
555 555
 	}
556 556
 
557 557
 	public function list_table_filters() {
558
-		$post_type = ! empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
558
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
559 559
 		if (isset($post_type)) {
560 560
 			if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
561 561
 				$filter_possibilities = array();
562 562
 				$filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
563 563
 				$filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
564 564
 				$filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
565
-				echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (! empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
565
+				echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
566 566
 			}
567 567
 		}
568 568
 	}
569 569
 
570
-	public function list_table_filter_parse_query( $query ) {
570
+	public function list_table_filter_parse_query($query) {
571 571
 		global $pagenow, $wpdb;
572
-		$post_type = ! empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
573
-		$entity_filter = ! empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : '';
574
-		if ( is_admin() && ( $pagenow == 'edit.php' ) && ! empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) && ! empty( $entity_filter ) ) {
572
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
573
+		$entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
574
+		if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
575 575
 			$check = null;
576
-			switch ( $entity_filter ) {
576
+			switch ($entity_filter) {
577 577
 				case 'orders':
578 578
 					$sql_query = $wpdb->prepare(
579 579
 						"SELECT ID
@@ -602,16 +602,16 @@  discard block
 block discarded – undo
602 602
 				break;
603 603
 			}
604 604
 
605
-			if ( ! empty( $check ) ) {
606
-				$results = $wpdb->get_results( $sql_query );
605
+			if (!empty($check)) {
606
+				$results = $wpdb->get_results($sql_query);
607 607
 				$user_id_list = array();
608
-				foreach ( $results as $item ) {
608
+				foreach ($results as $item) {
609 609
 					$user_id_list[] = $item->ID;
610 610
 				}
611
-				if ( empty( $post_id_list ) ) {
611
+				if (empty($post_id_list)) {
612 612
 					$post_id_list[] = 'no_result';
613 613
 				}
614
-				$query->query_vars[ $check ] = $user_id_list;
614
+				$query->query_vars[$check] = $user_id_list;
615 615
 			}
616 616
 			$query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
617 617
 			$query->query_vars['post_status'] = 'any';
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 	 *
624 624
 	 * @return array
625 625
 	 */
626
-	public static function get_all_customer( $post_status = 'publish' ) {
626
+	public static function get_all_customer($post_status = 'publish') {
627 627
 		global $wpdb;
628 628
 
629 629
 		$query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
@@ -638,15 +638,15 @@  discard block
 block discarded – undo
638 638
 	 * @param array $form Passer directement le $_POST pour créer un client.
639 639
 	 * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà
640 640
 	 */
641
-	public static function quick_add_customer( $form ) {
641
+	public static function quick_add_customer($form) {
642 642
 		$return = 1;
643
-		if ( ! empty( $form ) ) {
643
+		if (!empty($form)) {
644 644
 			global $wpdb;
645 645
 			$customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
646 646
 			$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
647 647
 			$customer_entity_id = $wpdb->get_var($query);
648 648
 			$attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
649
-			$account_attributes = wpshop_attributes_set::getAttributeSetDetails((! empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
649
+			$account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
650 650
 
651 651
 			$customer_attributes_to_save = $customer_attributes_to_save_temp = array();
652 652
 
Please login to merge, or discard this patch.
modules/wps_customer_contacts/templates/frontend/customer-choice.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
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
-$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() );
15
+$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());
16 16
 
17
-?><?php esc_html_e( 'Customer account', 'wpshop' ); ?><select id="wps-customer-contacts-user-selection" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wps-customer-switch-to' ) ); ?>" >
18
-<?php foreach ( $customers as $customer ) : ?>
19
-	<option value="<?php echo esc_attr( $customer->ID ); ?>" <?php selected( $customer->ID, $customer_id_from_cookie, true ); ?>><?php echo esc_html( $customer->post_title ); ?></option>
17
+?><?php esc_html_e('Customer account', 'wpshop'); ?><select id="wps-customer-contacts-user-selection" data-nonce="<?php echo esc_attr(wp_create_nonce('wps-customer-switch-to')); ?>" >
18
+<?php foreach ($customers as $customer) : ?>
19
+	<option value="<?php echo esc_attr($customer->ID); ?>" <?php selected($customer->ID, $customer_id_from_cookie, true); ?>><?php echo esc_html($customer->post_title); ?></option>
20 20
 <?php endforeach; ?>
21 21
 </select>
Please login to merge, or discard this patch.
modules/wps_customer_contacts/controller/wps-customer-contact.action.php 1 patch
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -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( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice' ) );
186
+			require(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
 
@@ -278,14 +278,14 @@  discard block
 block discarded – undo
278 278
 	 * Ajax callback - Change le cookie de l'utilisateur pour passer sur un autre client
279 279
 	 */
280 280
 	function ajax_callback_switch_customer() {
281
-		check_ajax_referer( 'wps-customer-switch-to' );
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
 }
Please login to merge, or discard this patch.