@@ -9,35 +9,35 @@ |
||
| 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 | $wps_customers_contacts = new WPS_Customers_Contacts(); |
| 17 | -$contacts = $wps_customers_contacts->get_customer_contact_list( $customer_post ); |
|
| 17 | +$contacts = $wps_customers_contacts->get_customer_contact_list($customer_post); |
|
| 18 | 18 | |
| 19 | 19 | ?> |
| 20 | -<?php foreach ( $contacts as $user_id => $user ) : ?> |
|
| 21 | -<?php $current_user_datas = get_userdata( $user_id ); ?> |
|
| 20 | +<?php foreach ($contacts as $user_id => $user) : ?> |
|
| 21 | +<?php $current_user_datas = get_userdata($user_id); ?> |
|
| 22 | 22 | <div class="wps-customer-name-container" > |
| 23 | 23 | <div class="alignleft" > |
| 24 | - <a target="_wps_wpuser_edition_page" href="<?php echo esc_url( get_edit_user_link( $user_id ) ); ?>" ><?php echo esc_html( $current_user_datas->user_email ); ?></a> |
|
| 24 | + <a target="_wps_wpuser_edition_page" href="<?php echo esc_url(get_edit_user_link($user_id)); ?>" ><?php echo esc_html($current_user_datas->user_email); ?></a> |
|
| 25 | 25 | <?php |
| 26 | 26 | $contact_names = ''; |
| 27 | - if ( ! empty( $current_user_datas->last_name ) ) { |
|
| 28 | - $contact_names .= strtoupper( $current_user_datas->last_name ); |
|
| 27 | + if (!empty($current_user_datas->last_name)) { |
|
| 28 | + $contact_names .= strtoupper($current_user_datas->last_name); |
|
| 29 | 29 | } |
| 30 | - if ( ! empty( $current_user_datas->first_name ) ) { |
|
| 31 | - $contact_names .= empty( $contact_names ) ? '' : ' '; |
|
| 32 | - $contact_names .= ucfirst( strtolower( $current_user_datas->first_name ) ); |
|
| 30 | + if (!empty($current_user_datas->first_name)) { |
|
| 31 | + $contact_names .= empty($contact_names) ? '' : ' '; |
|
| 32 | + $contact_names .= ucfirst(strtolower($current_user_datas->first_name)); |
|
| 33 | 33 | } |
| 34 | - $contact_names = empty( $contact_names ) ? $contact_names : ' - ' . $contact_names; |
|
| 35 | - echo esc_html( $contact_names ); |
|
| 34 | + $contact_names = empty($contact_names) ? $contact_names : ' - ' . $contact_names; |
|
| 35 | + echo esc_html($contact_names); |
|
| 36 | 36 | ?></div> |
| 37 | 37 | <div class="wps-customer-contact-list-actions alignleft hidden" > |
| 38 | 38 | - |
| 39 | - <?php do_action( 'wps_customer_contacts_list_action', $user_id ); ?> |
|
| 40 | - <a title="<?php esc_attr_e( 'User account edition', 'wpshop' ); ?>" href="<?php echo esc_url( get_edit_user_link( $user_id ) ); ?>" target="wps_contact_edition" ><i class="dashicons dashicons-edit" ></i></a> |
|
| 39 | + <?php do_action('wps_customer_contacts_list_action', $user_id); ?> |
|
| 40 | + <a title="<?php esc_attr_e('User account edition', 'wpshop'); ?>" href="<?php echo esc_url(get_edit_user_link($user_id)); ?>" target="wps_contact_edition" ><i class="dashicons dashicons-edit" ></i></a> |
|
| 41 | 41 | </div> |
| 42 | 42 | </div> |
| 43 | 43 | <?php endforeach; ?> |
@@ -6,7 +6,7 @@ discard block |
||
| 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 |
||
| 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( 'set_current_user', array( $this, 'hook_login_for_setting_customer_id' ) ); |
|
| 57 | + add_action('set_current_user', array($this, 'hook_login_for_setting_customer_id')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -66,13 +66,13 @@ discard block |
||
| 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 | } |
@@ -82,25 +82,25 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function hook_login_for_setting_customer_id() { |
| 84 | 84 | $user_id = get_current_user_id(); |
| 85 | - $customer_id = wps_customer_ctr::get_customer_id_by_author_id( $user_id ); |
|
| 86 | - if ( empty( $customer_id ) ) { |
|
| 87 | - $query = $GLOBALS['wpdb']->prepare( "SELECT post_id FROM {$GLOBALS['wpdb']->postmeta} WHERE meta_key = %s AND meta_value LIKE %s ORDER BY meta_id LIMIT 1", '_wpscrm_associated_user', "%;i:$user_id;%" ); |
|
| 88 | - $customer_id = $GLOBALS['wpdb']->get_var( $query ); |
|
| 85 | + $customer_id = wps_customer_ctr::get_customer_id_by_author_id($user_id); |
|
| 86 | + if (empty($customer_id)) { |
|
| 87 | + $query = $GLOBALS['wpdb']->prepare("SELECT post_id FROM {$GLOBALS['wpdb']->postmeta} WHERE meta_key = %s AND meta_value LIKE %s ORDER BY meta_id LIMIT 1", '_wpscrm_associated_user', "%;i:$user_id;%"); |
|
| 88 | + $customer_id = $GLOBALS['wpdb']->get_var($query); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - setcookie( 'wps_current_connected_customer', $customer_id, strtotime( '+30 days' ), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() ); |
|
| 91 | + setcookie('wps_current_connected_customer', $customer_id, strtotime('+30 days'), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl()); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * AJAX callback for customer search |
| 96 | 96 | */ |
| 97 | 97 | public function ajax_search_customer() { |
| 98 | - check_ajax_referer( 'wps_customer_search' ); |
|
| 98 | + check_ajax_referer('wps_customer_search'); |
|
| 99 | 99 | |
| 100 | - $term = ! empty( $_GET ) && ! empty( $_GET['term'] ) && is_string( (string) $_GET['term'] ) ? (string) $_GET['term'] : $term; |
|
| 101 | - $list = $this->search_customer( $term ); |
|
| 100 | + $term = !empty($_GET) && !empty($_GET['term']) && is_string((string)$_GET['term']) ? (string)$_GET['term'] : $term; |
|
| 101 | + $list = $this->search_customer($term); |
|
| 102 | 102 | |
| 103 | - wp_die( wp_json_encode( $list ) ); |
|
| 103 | + wp_die(wp_json_encode($list)); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -108,23 +108,23 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @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. |
| 110 | 110 | */ |
| 111 | - public function search_customer( $term ) { |
|
| 111 | + public function search_customer($term) { |
|
| 112 | 112 | $users = array(); |
| 113 | - $search_users = new WP_User_Query( array( |
|
| 114 | - 'search' => '*' . esc_attr( $term ) . '*', |
|
| 115 | - 'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ), |
|
| 116 | - ) ); |
|
| 113 | + $search_users = new WP_User_Query(array( |
|
| 114 | + 'search' => '*' . esc_attr($term) . '*', |
|
| 115 | + 'search_columns' => array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'), |
|
| 116 | + )); |
|
| 117 | 117 | $user_query_results = $search_users->get_results(); |
| 118 | - if ( ! empty( $user_query_results ) ) { |
|
| 119 | - foreach ( $user_query_results as $user ) { |
|
| 120 | - $users[ $user->ID ]['id'] = $user->ID; |
|
| 121 | - $users[ $user->ID ]['display_name'] = $user->display_name; |
|
| 122 | - $users[ $user->ID ]['email'] = $user->user_email; |
|
| 123 | - $users[ $user->ID ]['last_name'] = $user->last_name; |
|
| 124 | - $users[ $user->ID ]['first_name'] = $user->first_name; |
|
| 118 | + if (!empty($user_query_results)) { |
|
| 119 | + foreach ($user_query_results as $user) { |
|
| 120 | + $users[$user->ID]['id'] = $user->ID; |
|
| 121 | + $users[$user->ID]['display_name'] = $user->display_name; |
|
| 122 | + $users[$user->ID]['email'] = $user->user_email; |
|
| 123 | + $users[$user->ID]['last_name'] = $user->last_name; |
|
| 124 | + $users[$user->ID]['first_name'] = $user->first_name; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | - $search_users_in_meta = new WP_User_Query( array( |
|
| 127 | + $search_users_in_meta = new WP_User_Query(array( |
|
| 128 | 128 | 'meta_query' => array( |
| 129 | 129 | 'relation' => 'OR', |
| 130 | 130 | array( |
@@ -138,21 +138,21 @@ discard block |
||
| 138 | 138 | 'compare' => 'LIKE', |
| 139 | 139 | ), |
| 140 | 140 | ), |
| 141 | - ) ); |
|
| 141 | + )); |
|
| 142 | 142 | $user_query_results_2 = $search_users_in_meta->get_results(); |
| 143 | - if ( ! empty( $user_query_results_2 ) ) { |
|
| 144 | - foreach ( $user_query_results_2 as $user ) { |
|
| 145 | - $users[ $user->ID ]['id'] = $user->ID; |
|
| 146 | - $users[ $user->ID ]['display_name'] = $user->display_name; |
|
| 147 | - $users[ $user->ID ]['email'] = $user->user_email; |
|
| 148 | - $users[ $user->ID ]['last_name'] = $user->last_name; |
|
| 149 | - $users[ $user->ID ]['first_name'] = $user->first_name; |
|
| 143 | + if (!empty($user_query_results_2)) { |
|
| 144 | + foreach ($user_query_results_2 as $user) { |
|
| 145 | + $users[$user->ID]['id'] = $user->ID; |
|
| 146 | + $users[$user->ID]['display_name'] = $user->display_name; |
|
| 147 | + $users[$user->ID]['email'] = $user->user_email; |
|
| 148 | + $users[$user->ID]['last_name'] = $user->last_name; |
|
| 149 | + $users[$user->ID]['first_name'] = $user->first_name; |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | - if ( empty( $users ) ) { |
|
| 152 | + if (empty($users)) { |
|
| 153 | 153 | $users[] = array( |
| 154 | 154 | 'id' => null, |
| 155 | - 'label' => __( 'Create a new user', 'wpshop' ), |
|
| 155 | + 'label' => __('Create a new user', 'wpshop'), |
|
| 156 | 156 | ); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return int $customer_id |
| 168 | 168 | */ |
| 169 | - public static function get_customer_id_by_author_id( $author_id ) { |
|
| 170 | - if ( ! isset( self::$customer_user_identifier_cache[ $author_id ] ) ) { |
|
| 171 | - $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 ); |
|
| 172 | - self::$customer_user_identifier_cache[ $author_id ] = $GLOBALS['wpdb']->get_var( $query ); |
|
| 169 | + public static function get_customer_id_by_author_id($author_id) { |
|
| 170 | + if (!isset(self::$customer_user_identifier_cache[$author_id])) { |
|
| 171 | + $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); |
|
| 172 | + self::$customer_user_identifier_cache[$author_id] = $GLOBALS['wpdb']->get_var($query); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - return self::$customer_user_identifier_cache[ $author_id ]; |
|
| 175 | + return self::$customer_user_identifier_cache[$author_id]; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -183,15 +183,15 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return int |
| 185 | 185 | */ |
| 186 | - public static function get_author_id_by_customer_id( $customer_id ) { |
|
| 187 | - $flipped = ! empty( self::$customer_user_identifier_cache ) ? array_flip( self::$customer_user_identifier_cache ) : ''; |
|
| 188 | - if ( ! isset( $flipped[ $customer_id ] ) ) { |
|
| 189 | - $author_id = $GLOBALS['wpdb']->get_var( $GLOBALS['wpdb']->prepare( "SELECT post_author FROM {$GLOBALS['wpdb']->posts} WHERE ID = %d", $customer_id ) ); |
|
| 190 | - self::$customer_user_identifier_cache[ $author_id ] = $customer_id; |
|
| 191 | - $flipped[ $customer_id ] = $author_id; |
|
| 186 | + public static function get_author_id_by_customer_id($customer_id) { |
|
| 187 | + $flipped = !empty(self::$customer_user_identifier_cache) ? array_flip(self::$customer_user_identifier_cache) : ''; |
|
| 188 | + if (!isset($flipped[$customer_id])) { |
|
| 189 | + $author_id = $GLOBALS['wpdb']->get_var($GLOBALS['wpdb']->prepare("SELECT post_author FROM {$GLOBALS['wpdb']->posts} WHERE ID = %d", $customer_id)); |
|
| 190 | + self::$customer_user_identifier_cache[$author_id] = $customer_id; |
|
| 191 | + $flipped[$customer_id] = $author_id; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - return $flipped[ $customer_id ]; |
|
| 194 | + return $flipped[$customer_id]; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -199,26 +199,26 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function create_customer_entity() { |
| 201 | 201 | global $wpdb; |
| 202 | - $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' ); |
|
| 203 | - $customer_entity_definition = $wpdb->get_row( $query ); // WPCS: unprepared sql ok. |
|
| 204 | - $current_entity_params = ! empty( $customer_entity_definition ) && ! empty( $customer_entity_definition->meta_value ) ? unserialize( $customer_entity_definition->meta_value ) : null; |
|
| 202 | + $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'); |
|
| 203 | + $customer_entity_definition = $wpdb->get_row($query); // WPCS: unprepared sql ok. |
|
| 204 | + $current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null; |
|
| 205 | 205 | |
| 206 | 206 | $post_type_params = array( |
| 207 | 207 | 'labels' => array( |
| 208 | - 'name' => __( 'Customers', 'wpshop' ), |
|
| 209 | - 'singular_name' => __( 'Customer', 'wpshop' ), |
|
| 210 | - 'add_new_item' => __( 'New customer', 'wpshop' ), |
|
| 211 | - 'add_new' => __( 'New customer', 'wpshop' ), |
|
| 212 | - 'edit_item' => __( 'Edit customer', 'wpshop' ), |
|
| 213 | - 'new_item' => __( 'New customer', 'wpshop' ), |
|
| 214 | - 'view_item' => __( 'View customer', 'wpshop' ), |
|
| 215 | - 'search_items' => __( 'Search in customers', 'wpshop' ), |
|
| 216 | - 'not_found' => __( 'No customer found', 'wpshop' ), |
|
| 217 | - 'not_found_in_trash' => __( 'No customer founded in trash', 'wpshop' ), |
|
| 208 | + 'name' => __('Customers', 'wpshop'), |
|
| 209 | + 'singular_name' => __('Customer', 'wpshop'), |
|
| 210 | + 'add_new_item' => __('New customer', 'wpshop'), |
|
| 211 | + 'add_new' => __('New customer', 'wpshop'), |
|
| 212 | + 'edit_item' => __('Edit customer', 'wpshop'), |
|
| 213 | + 'new_item' => __('New customer', 'wpshop'), |
|
| 214 | + 'view_item' => __('View customer', 'wpshop'), |
|
| 215 | + 'search_items' => __('Search in customers', 'wpshop'), |
|
| 216 | + 'not_found' => __('No customer found', 'wpshop'), |
|
| 217 | + 'not_found_in_trash' => __('No customer founded in trash', 'wpshop'), |
|
| 218 | 218 | 'parent_item_colon' => '', |
| 219 | 219 | ), |
| 220 | 220 | 'description' => '', |
| 221 | - 'supports' => ! empty( $current_entity_params['support'] ) ? $current_entity_params['support'] : array( 'title' ), |
|
| 221 | + 'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'), |
|
| 222 | 222 | 'hierarchical' => false, |
| 223 | 223 | 'public' => false, |
| 224 | 224 | 'show_ui' => true, |
@@ -243,22 +243,22 @@ discard block |
||
| 243 | 243 | ), |
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - register_post_type( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params ); |
|
| 246 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * Customer options for the shop |
| 251 | 251 | */ |
| 252 | 252 | public static function declare_options() { |
| 253 | - if ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) { |
|
| 254 | - $wpshop_shop_type = ! empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST['wpshop_shop_type'] ) : ''; |
|
| 255 | - $old_wpshop_shop_type = ! empty( $_POST['old_wpshop_shop_type'] ) ? sanitize_text_field( $_POST['old_wpshop_shop_type'] ) : ''; |
|
| 253 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 254 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 255 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 256 | 256 | |
| 257 | - if ( ( $wpshop_shop_type == '' || $wpshop_shop_type != 'presentation' ) |
|
| 258 | - && ( $old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation' ) ) { |
|
| 257 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 258 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 259 | 259 | /** Add module option to wpshop general options */ |
| 260 | - register_setting( 'wpshop_options', 'wpshop_cart_option', array( 'wps_customer_ctr', 'wpshop_options_validate_customers_newsleters' ) ); |
|
| 261 | - add_settings_field( 'display_newsletters_subscriptions', __( 'Display newsletters subscriptions', 'wpshop' ), array( 'wps_customer_ctr', 'display_newsletters_subscriptions' ), 'wpshop_cart_info', 'wpshop_cart_info' ); |
|
| 260 | + register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters')); |
|
| 261 | + add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info'); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return array Les réglages des clients qui ont été vérifiés |
| 272 | 272 | */ |
| 273 | - public static function wpshop_options_validate_customers_newsleters( $input ) { |
|
| 273 | + public static function wpshop_options_validate_customers_newsleters($input) { |
|
| 274 | 274 | return $input; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * Affichage des champs permettant les réglages concernant les newsletters des clients dans les réglages de la boutique |
| 279 | 279 | */ |
| 280 | 280 | public static function display_newsletters_subscriptions() { |
| 281 | - $cart_option = get_option( 'wpshop_cart_option', array() ); |
|
| 281 | + $cart_option = get_option('wpshop_cart_option', array()); |
|
| 282 | 282 | $output = ''; |
| 283 | 283 | |
| 284 | 284 | $input_def = array(); |
@@ -286,18 +286,18 @@ discard block |
||
| 286 | 286 | $input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription'; |
| 287 | 287 | $input_def['type'] = 'checkbox'; |
| 288 | 288 | $input_def['valueToPut'] = 'index'; |
| 289 | - $input_def['value'] = ! empty( $cart_option['display_newsletter']['site_subscription'] ) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no'; |
|
| 289 | + $input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no'; |
|
| 290 | 290 | $input_def['possible_value'] = 'yes'; |
| 291 | - $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>'; |
|
| 291 | + $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>'; |
|
| 292 | 292 | |
| 293 | 293 | $input_def = array(); |
| 294 | 294 | $input_def['name'] = ''; |
| 295 | 295 | $input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription'; |
| 296 | 296 | $input_def['type'] = 'checkbox'; |
| 297 | 297 | $input_def['valueToPut'] = 'index'; |
| 298 | - $input_def['value'] = ! empty( $cart_option['display_newsletter']['partner_subscription'] ) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no'; |
|
| 298 | + $input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no'; |
|
| 299 | 299 | $input_def['possible_value'] = 'yes'; |
| 300 | - $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>'; |
|
| 300 | + $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>'; |
|
| 301 | 301 | |
| 302 | 302 | echo $output; // WPCS: XSS ok. |
| 303 | 303 | } |
@@ -311,15 +311,15 @@ discard block |
||
| 311 | 311 | * |
| 312 | 312 | * @return string La nouvelle url pour la redirection. |
| 313 | 313 | */ |
| 314 | - public function wp_redirect_after_user_new( $location ) { |
|
| 314 | + public function wp_redirect_after_user_new($location) { |
|
| 315 | 315 | global $pagenow; |
| 316 | 316 | |
| 317 | - if ( is_admin() && $pagenow === 'user-new.php' ) { |
|
| 318 | - $user_details = get_user_by( 'email', $_REQUEST[ 'email' ] ); |
|
| 317 | + if (is_admin() && $pagenow === 'user-new.php') { |
|
| 318 | + $user_details = get_user_by('email', $_REQUEST['email']); |
|
| 319 | 319 | $user_id = $user_details->ID; |
| 320 | 320 | |
| 321 | - if( $location == 'users.php?update=add&id=' . $user_id ) |
|
| 322 | - return add_query_arg( array( 'user_id' => $user_id ), 'user-edit.php' ); |
|
| 321 | + if ($location == 'users.php?update=add&id=' . $user_id) |
|
| 322 | + return add_query_arg(array('user_id' => $user_id), 'user-edit.php'); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | return $location; |
@@ -337,25 +337,25 @@ discard block |
||
| 337 | 337 | * |
| 338 | 338 | * @param integer $user_id L'identifiant de l'utilisateur qui vient d'être créé et pour qui on va créer le client. |
| 339 | 339 | */ |
| 340 | - public static function create_entity_customer_when_user_is_created( $user_id ) { |
|
| 341 | - if ( ! is_admin() || strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) ) { |
|
| 342 | - $user_data = get_userdata( $user_id ); |
|
| 343 | - $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 ) ) ); |
|
| 344 | - $customer_post_ID = wp_insert_post( array( 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename ) ); |
|
| 345 | - self::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 340 | + public static function create_entity_customer_when_user_is_created($user_id) { |
|
| 341 | + if (!is_admin() || strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php')) { |
|
| 342 | + $user_data = get_userdata($user_id); |
|
| 343 | + $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))); |
|
| 344 | + $customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename)); |
|
| 345 | + self::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 346 | 346 | |
| 347 | 347 | /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox */ |
| 348 | - $usermeta = get_post_meta( $user_id, 'metaboxhidden_nav-menus', true ); |
|
| 349 | - if ( ! empty( $usermeta ) && is_array( $usermeta ) ) { |
|
| 350 | - $data_to_delete = array_search( 'add-wpshop_product_category', $usermeta ); |
|
| 351 | - if ( false !== $data_to_delete ) { |
|
| 352 | - unset( $usermeta[ $data_to_delete ] ); |
|
| 353 | - update_user_meta( $user_id, 'metaboxhidden_nav-menus', $usermeta ); |
|
| 348 | + $usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true); |
|
| 349 | + if (!empty($usermeta) && is_array($usermeta)) { |
|
| 350 | + $data_to_delete = array_search('add-wpshop_product_category', $usermeta); |
|
| 351 | + if (false !== $data_to_delete) { |
|
| 352 | + unset($usermeta[$data_to_delete]); |
|
| 353 | + update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | - private static function array_map_create_entity_customer_when_user_is_created( $a ) { |
|
| 358 | + private static function array_map_create_entity_customer_when_user_is_created($a) { |
|
| 359 | 359 | return $a[0]; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | * @param integer $user_id |
| 366 | 366 | */ |
| 367 | - public static function update_entity_customer_when_profile_user_is_update( $user_id ) { |
|
| 368 | - if ( ! is_admin() || strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) ) { |
|
| 367 | + public static function update_entity_customer_when_profile_user_is_update($user_id) { |
|
| 368 | + if (!is_admin() || strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php')) { |
|
| 369 | 369 | $user_data = get_userdata($user_id); |
| 370 | 370 | $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))); |
| 371 | 371 | $customer_post_ID = self::get_customer_id_by_author_id($user_id); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | return false; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - public static function save_customer_synchronize( $customer_post_ID, $user_id, $user_info ) { |
|
| 381 | + public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info) { |
|
| 382 | 382 | global $wpdb; |
| 383 | 383 | global $wpshop; |
| 384 | 384 | $exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name'); |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
| 388 | 388 | $attribute_set_id = $wpdb->get_var($query); |
| 389 | 389 | $attributes_default = array(); |
| 390 | - if (! empty($attribute_set_id)) { |
|
| 390 | + if (!empty($attribute_set_id)) { |
|
| 391 | 391 | $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
| 392 | 392 | foreach ($group as $attribute_sets) { |
| 393 | 393 | foreach ($attribute_sets as $attribute_set_field) { |
@@ -407,10 +407,10 @@ discard block |
||
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | $user_info = array_merge($attributes_default, $user_info); |
| 410 | - add_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) ); |
|
| 410 | + add_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress')); |
|
| 411 | 411 | foreach ($user_info as $user_meta => $user_meta_value) { |
| 412 | 412 | $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code'); |
| 413 | - if (! empty($attribute_def)) { |
|
| 413 | + if (!empty($attribute_def)) { |
|
| 414 | 414 | //Save data in user meta |
| 415 | 415 | if (in_array($user_meta, $exclude_user_meta)) { |
| 416 | 416 | if ($user_meta == 'user_pass') { |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
| 427 | 427 | $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); |
| 428 | 428 | $checking_attribute_exist = $wpdb->get_results($query); |
| 429 | - if (! empty($checking_attribute_exist)) { |
|
| 429 | + if (!empty($checking_attribute_exist)) { |
|
| 430 | 430 | $wpdb->update( |
| 431 | 431 | WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type), |
| 432 | 432 | array( |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | - remove_filter( 'send_password_change_email', array( get_class(), 'prevent_send_mail_from_wordpress' ) ); |
|
| 456 | + remove_filter('send_password_change_email', array(get_class(), 'prevent_send_mail_from_wordpress')); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -463,17 +463,17 @@ discard block |
||
| 463 | 463 | * |
| 464 | 464 | * @return array The new header to display |
| 465 | 465 | */ |
| 466 | - public function list_table_header( $current_header ) { |
|
| 467 | - unset( $current_header['title'] ); |
|
| 468 | - unset( $current_header['date'] ); |
|
| 466 | + public function list_table_header($current_header) { |
|
| 467 | + unset($current_header['title']); |
|
| 468 | + unset($current_header['date']); |
|
| 469 | 469 | |
| 470 | - $current_header['customer-identifier'] = __( 'Customer ID', 'wpshop' ); |
|
| 471 | - $current_header['customer-name'] = __( 'Customer name', 'wpshop' ); |
|
| 470 | + $current_header['customer-identifier'] = __('Customer ID', 'wpshop'); |
|
| 471 | + $current_header['customer-name'] = __('Customer name', 'wpshop'); |
|
| 472 | 472 | // $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>'; |
| 473 | 473 | // $current_header['customer_email'] = __('E-mail', 'wpshop'); |
| 474 | - $current_header['customer-orders'] = __( 'Customer last order', 'wpshop' ); |
|
| 475 | - $current_header['customer-contacts'] = __( 'Contacts', 'wpshop' ); |
|
| 476 | - $current_header['customer_date_subscription'] = __( 'Subscription', 'wpshop' ); |
|
| 474 | + $current_header['customer-orders'] = __('Customer last order', 'wpshop'); |
|
| 475 | + $current_header['customer-contacts'] = __('Contacts', 'wpshop'); |
|
| 476 | + $current_header['customer_date_subscription'] = __('Subscription', 'wpshop'); |
|
| 477 | 477 | // $current_header['customer_date_lastlogin'] = __( 'Last login date', 'wpshop' ); |
| 478 | 478 | |
| 479 | 479 | return $current_header; |
@@ -485,42 +485,42 @@ discard block |
||
| 485 | 485 | * @param string $column THe column identifier to modify output for. |
| 486 | 486 | * @param integer $post_id The current post identifier. |
| 487 | 487 | */ |
| 488 | - public function list_table_column_content( $column, $post_id ) { |
|
| 488 | + public function list_table_column_content($column, $post_id) { |
|
| 489 | 489 | global $wpdb; |
| 490 | 490 | /** Get wp_users identifier from customer id */ |
| 491 | - $customer_post_author = self::get_author_id_by_customer_id( $post_id ); |
|
| 491 | + $customer_post_author = self::get_author_id_by_customer_id($post_id); |
|
| 492 | 492 | |
| 493 | 493 | /** Get current post informations */ |
| 494 | - $customer_post = get_post( $post_id ); |
|
| 494 | + $customer_post = get_post($post_id); |
|
| 495 | 495 | |
| 496 | 496 | /** Switch current column for custom case */ |
| 497 | 497 | $use_template = true; |
| 498 | - switch ( $column ) { |
|
| 498 | + switch ($column) { |
|
| 499 | 499 | case 'customer-identifier' : |
| 500 | - echo esc_html( $post_id ); |
|
| 500 | + echo esc_html($post_id); |
|
| 501 | 501 | $use_template = false; |
| 502 | 502 | break; |
| 503 | 503 | |
| 504 | 504 | case 'customer_date_subscription' : |
| 505 | - echo mysql2date( get_option( 'date_format' ), $customer_post->post_date, true ); |
|
| 505 | + echo mysql2date(get_option('date_format'), $customer_post->post_date, true); |
|
| 506 | 506 | $use_template = false; |
| 507 | 507 | break; |
| 508 | 508 | |
| 509 | 509 | case 'customer_date_lastlogin' : |
| 510 | - $last_login = get_user_meta( $customer_post_author, 'last_login_time', true ); |
|
| 511 | - if ( ! empty( $last_login ) ) : |
|
| 512 | - echo mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $last_login, true ); |
|
| 510 | + $last_login = get_user_meta($customer_post_author, 'last_login_time', true); |
|
| 511 | + if (!empty($last_login)) : |
|
| 512 | + echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true); |
|
| 513 | 513 | else : |
| 514 | - _e( 'Never logged in', 'wpshop' ); |
|
| 514 | + _e('Never logged in', 'wpshop'); |
|
| 515 | 515 | endif; |
| 516 | 516 | $use_template = false; |
| 517 | 517 | break; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** Require the template for displaying the current column */ |
| 521 | - if ( $use_template ) { |
|
| 522 | - $template = wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column ); |
|
| 523 | - if ( is_file( $template ) ) { |
|
| 521 | + if ($use_template) { |
|
| 522 | + $template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column); |
|
| 523 | + if (is_file($template)) { |
|
| 524 | 524 | require $template; |
| 525 | 525 | } |
| 526 | 526 | } |
@@ -533,33 +533,33 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @return array The new action list to use into customer list table |
| 535 | 535 | */ |
| 536 | - public function customer_list_table_bulk_actions( $actions ) { |
|
| 537 | - unset( $actions['edit'] ); |
|
| 538 | - unset( $actions['trash'] ); |
|
| 536 | + public function customer_list_table_bulk_actions($actions) { |
|
| 537 | + unset($actions['edit']); |
|
| 538 | + unset($actions['trash']); |
|
| 539 | 539 | |
| 540 | 540 | return $actions; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | public function list_table_filters() { |
| 544 | - $post_type = ! empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 544 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 545 | 545 | if (isset($post_type)) { |
| 546 | 546 | if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) { |
| 547 | 547 | $filter_possibilities = array(); |
| 548 | 548 | $filter_possibilities[''] = __('-- Select Filter --', 'wpshop'); |
| 549 | 549 | $filter_possibilities['orders'] = __('List customers with orders', 'wpshop'); |
| 550 | 550 | $filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop'); |
| 551 | - echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (! empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index'); |
|
| 551 | + echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index'); |
|
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - public function list_table_filter_parse_query( $query ) { |
|
| 556 | + public function list_table_filter_parse_query($query) { |
|
| 557 | 557 | global $pagenow, $wpdb; |
| 558 | - $post_type = ! empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
| 559 | - $entity_filter = ! empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
| 560 | - if ( is_admin() && ( $pagenow == 'edit.php' ) && ! empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) && ! empty( $entity_filter ) ) { |
|
| 558 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
| 559 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
| 560 | + if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) { |
|
| 561 | 561 | $check = null; |
| 562 | - switch ( $entity_filter ) { |
|
| 562 | + switch ($entity_filter) { |
|
| 563 | 563 | case 'orders': |
| 564 | 564 | $sql_query = $wpdb->prepare( |
| 565 | 565 | "SELECT ID |
@@ -588,16 +588,16 @@ discard block |
||
| 588 | 588 | break; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if ( ! empty( $check ) ) { |
|
| 592 | - $results = $wpdb->get_results( $sql_query ); |
|
| 591 | + if (!empty($check)) { |
|
| 592 | + $results = $wpdb->get_results($sql_query); |
|
| 593 | 593 | $user_id_list = array(); |
| 594 | - foreach ( $results as $item ) { |
|
| 594 | + foreach ($results as $item) { |
|
| 595 | 595 | $user_id_list[] = $item->ID; |
| 596 | 596 | } |
| 597 | - if ( empty( $post_id_list ) ) { |
|
| 597 | + if (empty($post_id_list)) { |
|
| 598 | 598 | $post_id_list[] = 'no_result'; |
| 599 | 599 | } |
| 600 | - $query->query_vars[ $check ] = $user_id_list; |
|
| 600 | + $query->query_vars[$check] = $user_id_list; |
|
| 601 | 601 | } |
| 602 | 602 | $query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS; |
| 603 | 603 | $query->query_vars['post_status'] = 'any'; |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | * |
| 610 | 610 | * @return array |
| 611 | 611 | */ |
| 612 | - public static function get_all_customer( $post_status = 'publish' ) { |
|
| 612 | + public static function get_all_customer($post_status = 'publish') { |
|
| 613 | 613 | global $wpdb; |
| 614 | 614 | |
| 615 | 615 | $query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status); |
@@ -624,15 +624,15 @@ discard block |
||
| 624 | 624 | * @param array $form Passer directement le $_POST pour créer un client. |
| 625 | 625 | * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà |
| 626 | 626 | */ |
| 627 | - public static function quick_add_customer( $form ) { |
|
| 627 | + public static function quick_add_customer($form) { |
|
| 628 | 628 | $return = 1; |
| 629 | - if ( ! empty( $form ) ) { |
|
| 629 | + if (!empty($form)) { |
|
| 630 | 630 | global $wpdb; |
| 631 | 631 | $customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
| 632 | 632 | $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id); |
| 633 | 633 | $customer_entity_id = $wpdb->get_var($query); |
| 634 | 634 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 635 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails((! empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 635 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 636 | 636 | |
| 637 | 637 | $customer_attributes_to_save = $customer_attributes_to_save_temp = array(); |
| 638 | 638 | |
@@ -9,33 +9,33 @@ |
||
| 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 empty( $user['last_name'] ) ? '—' : esc_html( $user['last_name'] ); ?></td> |
|
| 24 | - <td><?php echo empty( $user['first_name'] ) ? '—' : esc_html( $user['first_name'] ); ?></td> |
|
| 25 | - <td><?php echo esc_html( $user['display_name'] ); ?></td> |
|
| 26 | - <td><?php echo esc_html( $user['user_email'] ); ?></td> |
|
| 27 | - <td><?php echo ( isset( $user['metas']['wps_phone'] ) && ! empty( $user['metas']['wps_phone'] ) ? esc_html( implode( ',', $user['metas']['wps_phone'] ) ) : '—' ); ?></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 empty($user['last_name']) ? '—' : esc_html($user['last_name']); ?></td> |
|
| 24 | + <td><?php echo empty($user['first_name']) ? '—' : esc_html($user['first_name']); ?></td> |
|
| 25 | + <td><?php echo esc_html($user['display_name']); ?></td> |
|
| 26 | + <td><?php echo esc_html($user['user_email']); ?></td> |
|
| 27 | + <td><?php echo (isset($user['metas']['wps_phone']) && !empty($user['metas']['wps_phone']) ? esc_html(implode(',', $user['metas']['wps_phone'])) : '—'); ?></td> |
|
| 28 | 28 | |
| 29 | 29 | <td class="wps-customer-contacts-actions" > |
| 30 | - <?php do_action( 'wps_customer_contacts_list_action', $user_id ); ?> |
|
| 31 | - <a title="<?php esc_attr_e( 'User account edition', 'wpshop' ); ?>" href="<?php echo esc_url( get_edit_user_link( $user_id ) ); ?>" target="wps_contact_edition" ><i class="dashicons dashicons-edit" ></i></a> |
|
| 30 | + <?php do_action('wps_customer_contacts_list_action', $user_id); ?> |
|
| 31 | + <a title="<?php esc_attr_e('User account edition', 'wpshop'); ?>" href="<?php echo esc_url(get_edit_user_link($user_id)); ?>" target="wps_contact_edition" ><i class="dashicons dashicons-edit" ></i></a> |
|
| 32 | 32 | |
| 33 | - <?php if ( true === $user['is_default'] ) : ?> |
|
| 34 | - <i title="<?php esc_attr_e( 'This is the main contact / customer creator', 'wpshop' ); ?>" class="dashicons dashicons-star-filled" ></i> |
|
| 35 | - <i title="<?php esc_attr_e( 'This is the main contact, you can\'t unlink it', 'wpshop' ); ?>" class="dashicons dashicons-lock" ></i> |
|
| 33 | + <?php if (true === $user['is_default']) : ?> |
|
| 34 | + <i title="<?php esc_attr_e('This is the main contact / customer creator', 'wpshop'); ?>" class="dashicons dashicons-star-filled" ></i> |
|
| 35 | + <i title="<?php esc_attr_e('This is the main contact, you can\'t unlink it', 'wpshop'); ?>" class="dashicons dashicons-lock" ></i> |
|
| 36 | 36 | <?php else : ?> |
| 37 | - <i title="<?php esc_attr_e( 'Change to default customer', 'wpshop' ); ?>" class="dashicons dashicons-star-empty" ></i> |
|
| 38 | - <i title="<?php esc_attr_e( 'Unlink this user', 'wpshop' ); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
| 37 | + <i title="<?php esc_attr_e('Change to default customer', 'wpshop'); ?>" class="dashicons dashicons-star-empty" ></i> |
|
| 38 | + <i title="<?php esc_attr_e('Unlink this user', 'wpshop'); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
| 39 | 39 | <?php endif; ?> |
| 40 | 40 | |
| 41 | 41 | </td> |
@@ -33,8 +33,11 @@ |
||
| 33 | 33 | <?php if ( true === $user['is_default'] ) : ?> |
| 34 | 34 | <i title="<?php esc_attr_e( 'This is the main contact / customer creator', 'wpshop' ); ?>" class="dashicons dashicons-star-filled" ></i> |
| 35 | 35 | <i title="<?php esc_attr_e( 'This is the main contact, you can\'t unlink it', 'wpshop' ); ?>" class="dashicons dashicons-lock" ></i> |
| 36 | - <?php else : ?> |
|
| 37 | - <i title="<?php esc_attr_e( 'Change to default customer', 'wpshop' ); ?>" class="dashicons dashicons-star-empty" ></i> |
|
| 36 | + <?php else { |
|
| 37 | + : ?> |
|
| 38 | + <i title="<?php esc_attr_e( 'Change to default customer', 'wpshop' ); |
|
| 39 | +} |
|
| 40 | +?>" class="dashicons dashicons-star-empty" ></i> |
|
| 38 | 41 | <i title="<?php esc_attr_e( 'Unlink this user', 'wpshop' ); ?>" class="dashicons dashicons-editor-unlink" ></i> |
| 39 | 42 | <?php endif; ?> |
| 40 | 43 | |
@@ -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,26 +29,26 @@ 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 | 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | /** |
@@ -113,25 +113,25 @@ discard block |
||
| 113 | 113 | * @return [type] [description] |
| 114 | 114 | */ |
| 115 | 115 | |
| 116 | - function get_customer_contact_list( $customer ) { |
|
| 116 | + function get_customer_contact_list($customer) { |
|
| 117 | 117 | /** Define user list */ |
| 118 | 118 | $users = array(); |
| 119 | 119 | |
| 120 | 120 | /** Get associated users' */ |
| 121 | - $associated_users = (array) get_post_meta( $customer->ID, $this->user_contact_list_meta_key, true ); |
|
| 122 | - $user_list = wp_parse_id_list( array_merge( $associated_users, array( $customer->post_author ) ) ); |
|
| 123 | - if ( ! empty( $user_list ) ) { |
|
| 124 | - foreach ( $user_list as $user_id ) { |
|
| 125 | - if ( 0 !== $user_id ) { |
|
| 126 | - $associated_user = get_user_by( 'ID', $user_id ); |
|
| 127 | - $user_metas = get_user_meta( $user_id ); |
|
| 128 | - if ( is_object( $associated_user ) ) { |
|
| 129 | - $users[ $user_id ] = wp_parse_args( $associated_user->data, array( |
|
| 121 | + $associated_users = (array)get_post_meta($customer->ID, $this->user_contact_list_meta_key, true); |
|
| 122 | + $user_list = wp_parse_id_list(array_merge($associated_users, array($customer->post_author))); |
|
| 123 | + if (!empty($user_list)) { |
|
| 124 | + foreach ($user_list as $user_id) { |
|
| 125 | + if (0 !== $user_id) { |
|
| 126 | + $associated_user = get_user_by('ID', $user_id); |
|
| 127 | + $user_metas = get_user_meta($user_id); |
|
| 128 | + if (is_object($associated_user)) { |
|
| 129 | + $users[$user_id] = wp_parse_args($associated_user->data, array( |
|
| 130 | 130 | 'last_name' => $associated_user->last_name, |
| 131 | 131 | 'first_name' => $associated_user->first_name, |
| 132 | - 'is_default' => ( $user_id === (int) $customer->post_author ? true : false ), |
|
| 132 | + 'is_default' => ($user_id === (int)$customer->post_author ? true : false), |
|
| 133 | 133 | 'metas' => $user_metas, |
| 134 | - ) ); |
|
| 134 | + )); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | * @param integer $user_id Identifiant de l'utilisateur actuellement connecté / User identifier currenly connected. |
| 147 | 147 | * @param WP_User $account_user La définition du compte utilisateur / The user account definition. |
| 148 | 148 | */ |
| 149 | - function callback_customer_dashboard( $user_id, $account_user ) { |
|
| 149 | + function callback_customer_dashboard($user_id, $account_user) { |
|
| 150 | 150 | $customers = array(); |
| 151 | 151 | |
| 152 | - $customers_from_posts = new WP_Query( array( |
|
| 152 | + $customers_from_posts = new WP_Query(array( |
|
| 153 | 153 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
| 154 | 154 | 'author' => $user_id, |
| 155 | 155 | 'posts_per_page' => -1, |
| 156 | 156 | 'post_status' => 'any', |
| 157 | - ) ); |
|
| 158 | - if ( $customers_from_posts->have_posts() ) { |
|
| 159 | - $customers = array_merge( $customers, $customers_from_posts->posts ); |
|
| 157 | + )); |
|
| 158 | + if ($customers_from_posts->have_posts()) { |
|
| 159 | + $customers = array_merge($customers, $customers_from_posts->posts); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $customers_from_meta = new WP_Query( array( |
|
| 162 | + $customers_from_meta = new WP_Query(array( |
|
| 163 | 163 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
| 164 | 164 | 'posts_per_page' => -1, |
| 165 | 165 | 'post_status' => 'any', |
@@ -171,20 +171,20 @@ discard block |
||
| 171 | 171 | 'type' => 'CHAR', |
| 172 | 172 | ), |
| 173 | 173 | ), |
| 174 | - ) ); |
|
| 175 | - if ( $customers_from_meta->have_posts() ) { |
|
| 176 | - $customers = array_merge( $customers, $customers_from_meta->posts ); |
|
| 174 | + )); |
|
| 175 | + if ($customers_from_meta->have_posts()) { |
|
| 176 | + $customers = array_merge($customers, $customers_from_meta->posts); |
|
| 177 | 177 | } |
| 178 | - usort( $customers, function( $a, $b ) { |
|
| 179 | - if ( $a->ID === $b->ID ) { |
|
| 178 | + usort($customers, function($a, $b) { |
|
| 179 | + if ($a->ID === $b->ID) { |
|
| 180 | 180 | return 0; |
| 181 | 181 | } |
| 182 | 182 | return ($a < $b) ? -1 : 1; |
| 183 | 183 | }); |
| 184 | 184 | |
| 185 | - if ( ! empty( $customers ) && ( 1 < count( $customers ) ) ) { |
|
| 185 | + if (!empty($customers) && (1 < count($customers))) { |
|
| 186 | 186 | /** Display user list for current customer */ |
| 187 | - require_once( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice' ) ); |
|
| 187 | + require_once(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice')); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,32 +194,32 @@ discard block |
||
| 194 | 194 | * @param array $contact_methods La liste actuelle des méthodes permettant de contacter l'utilisateur / The current method list to contact a user. |
| 195 | 195 | * @param WP_user $user L'utilisateur en court d'édition / The current edited user. |
| 196 | 196 | */ |
| 197 | - public function add_contact_method_to_user( $contact_methods, $user ) { |
|
| 197 | + public function add_contact_method_to_user($contact_methods, $user) { |
|
| 198 | 198 | $wps_contact_method = array( |
| 199 | - 'wps_phone' => __( 'Phone number', 'wpshop' ), |
|
| 199 | + 'wps_phone' => __('Phone number', 'wpshop'), |
|
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - return array_merge( $wps_contact_method, $contact_methods ); |
|
| 202 | + return array_merge($wps_contact_method, $contact_methods); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * Ajax callback - Associate a user to a customer |
| 207 | 207 | */ |
| 208 | 208 | function ajax_callback_associate_user() { |
| 209 | - check_ajax_referer( 'wps_customer_contacts_associate' ); |
|
| 209 | + check_ajax_referer('wps_customer_contacts_associate'); |
|
| 210 | 210 | |
| 211 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 212 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 211 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 212 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 213 | 213 | |
| 214 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 215 | - if ( ! empty( $associated_users ) ) { |
|
| 216 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $user_id ) ) ); |
|
| 214 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 215 | + if (!empty($associated_users)) { |
|
| 216 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($user_id))); |
|
| 217 | 217 | } else { |
| 218 | - $new_associated_users = array( $user_id ); |
|
| 218 | + $new_associated_users = array($user_id); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
| 222 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 221 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
| 222 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 223 | 223 | wp_die(); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -227,20 +227,20 @@ discard block |
||
| 227 | 227 | * Ajax callback - Associate a user to a customer |
| 228 | 228 | */ |
| 229 | 229 | function ajax_callback_dissociate_user() { |
| 230 | - check_ajax_referer( 'wps_customer_contacts_dissociate' ); |
|
| 230 | + check_ajax_referer('wps_customer_contacts_dissociate'); |
|
| 231 | 231 | |
| 232 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 233 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 232 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 233 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 234 | 234 | |
| 235 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 236 | - foreach ( $associated_users as $key => $id ) { |
|
| 237 | - if ( $id === $user_id ) { |
|
| 238 | - unset( $associated_users[ $key ] ); |
|
| 235 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 236 | + foreach ($associated_users as $key => $id) { |
|
| 237 | + if ($id === $user_id) { |
|
| 238 | + unset($associated_users[$key]); |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $associated_users ); |
|
| 243 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 242 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $associated_users); |
|
| 243 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 244 | 244 | wp_die(); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -248,30 +248,30 @@ discard block |
||
| 248 | 248 | * Ajax callback - Change the default user for a customer |
| 249 | 249 | */ |
| 250 | 250 | function ajax_callback_change_default_user() { |
| 251 | - check_ajax_referer( 'wps_customer_contacts_change_default' ); |
|
| 251 | + check_ajax_referer('wps_customer_contacts_change_default'); |
|
| 252 | 252 | |
| 253 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 254 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 255 | - $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; |
|
| 253 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 254 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 255 | + $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; |
|
| 256 | 256 | |
| 257 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_author' => $user_id ), array( 'ID' => $customer_id ) ); |
|
| 258 | - $customer_default_user_changes = get_post_meta( $customer_id, '_wps_customer_default_user_histo', true ); |
|
| 257 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, array('post_author' => $user_id), array('ID' => $customer_id)); |
|
| 258 | + $customer_default_user_changes = get_post_meta($customer_id, '_wps_customer_default_user_histo', true); |
|
| 259 | 259 | $customer_default_user_changes[] = array( |
| 260 | - 'date' => current_time( 'mysql' ), |
|
| 260 | + 'date' => current_time('mysql'), |
|
| 261 | 261 | 'old_post_author' => $old_user_id, |
| 262 | 262 | 'update_author' => get_current_user_id(), |
| 263 | 263 | ); |
| 264 | - update_post_meta( $customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes ); |
|
| 264 | + update_post_meta($customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes); |
|
| 265 | 265 | |
| 266 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 267 | - if ( ! empty( $associated_users ) ) { |
|
| 268 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $old_user_id ) ) ); |
|
| 266 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 267 | + if (!empty($associated_users)) { |
|
| 268 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($old_user_id))); |
|
| 269 | 269 | } else { |
| 270 | - $new_associated_users = array( $old_user_id ); |
|
| 270 | + $new_associated_users = array($old_user_id); |
|
| 271 | 271 | } |
| 272 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
| 272 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
| 273 | 273 | |
| 274 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 274 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 275 | 275 | wp_die(); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | function ajax_callback_switch_customer() { |
| 282 | 282 | // check_ajax_referer( 'wps-customer-switch-to' ); |
| 283 | 283 | |
| 284 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['cid'] ) && is_int( (int) $_POST['cid'] ) ? (int) $_POST['cid'] : null; |
|
| 284 | + $customer_id = !empty($_POST) && !empty($_POST['cid']) && is_int((int)$_POST['cid']) ? (int)$_POST['cid'] : null; |
|
| 285 | 285 | |
| 286 | - unset( $_COOKIE['wps_current_connected_customer'] ); |
|
| 287 | - setcookie( 'wps_current_connected_customer', $customer_id, strtotime( '+30 days' ), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() ); |
|
| 286 | + unset($_COOKIE['wps_current_connected_customer']); |
|
| 287 | + setcookie('wps_current_connected_customer', $customer_id, strtotime('+30 days'), SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl()); |
|
| 288 | 288 | |
| 289 | - wp_die( wp_json_encode( array( 'status' => true ) ) ); |
|
| 289 | + wp_die(wp_json_encode(array('status' => true))); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | } |