@@ -9,37 +9,37 @@ |
||
| 9 | 9 | * @version 3.0.0.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if (!defined('ABSPATH')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | ?> |
| 16 | -<?php foreach ( $users as $user_id => $user ) : ?> |
|
| 17 | - <?php if ( 0 !== $user_id ) : ?> |
|
| 18 | - <?php if ( true === $user['is_default'] ) : ?> |
|
| 16 | +<?php foreach ($users as $user_id => $user) : ?> |
|
| 17 | + <?php if (0 !== $user_id) : ?> |
|
| 18 | + <?php if (true === $user['is_default']) : ?> |
|
| 19 | 19 | <?php $default_user = $user_id; ?> |
| 20 | 20 | <?php endif; ?> |
| 21 | - <tr data-customer-id="<?php echo esc_attr( $customer->ID ); ?>" data-user-id="<?php echo esc_attr( $user_id ); ?>" > |
|
| 22 | - <td>#<?php echo esc_html( $user_id ); ?></td> |
|
| 23 | - <td><?php echo esc_html( $user['last_name'] . ' - ' . $user['first_name'] ); ?></td> |
|
| 24 | - <td><?php echo esc_html( $user['display_name'] ); ?></td> |
|
| 25 | - <td><?php echo esc_html( $user['user_email'] ); ?></td> |
|
| 26 | - <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 esc_html($user['last_name'] . ' - ' . $user['first_name']); ?></td> |
|
| 24 | + <td><?php echo esc_html($user['display_name']); ?></td> |
|
| 25 | + <td><?php echo esc_html($user['user_email']); ?></td> |
|
| 26 | + <td><?php echo (isset($user['metas']['wps_phone']) && !empty($user['metas']['wps_phone']) ? esc_html(implode(',', $user['metas']['wps_phone'])) : '—'); ?></td> |
|
| 27 | 27 | |
| 28 | 28 | <td class="wps-customer-contacts-actions" > |
| 29 | - <?php do_action( 'wps_customer_contacts_list_action', $user_id ); ?> |
|
| 29 | + <?php do_action('wps_customer_contacts_list_action', $user_id); ?> |
|
| 30 | 30 | |
| 31 | - <?php if ( true === $user['is_default'] ) : ?> |
|
| 32 | - <i title="<?php esc_attr_e( 'This is the main contact / customer creator', 'wpshop' ); ?>" class="dashicons dashicons-star-filled" ></i> |
|
| 31 | + <?php if (true === $user['is_default']) : ?> |
|
| 32 | + <i title="<?php esc_attr_e('This is the main contact / customer creator', 'wpshop'); ?>" class="dashicons dashicons-star-filled" ></i> |
|
| 33 | 33 | <?php else : ?> |
| 34 | - <i title="<?php esc_attr_e( 'Change to default customer', 'wpshop' ); ?>" class="dashicons dashicons-star-empty" ></i> |
|
| 34 | + <i title="<?php esc_attr_e('Change to default customer', 'wpshop'); ?>" class="dashicons dashicons-star-empty" ></i> |
|
| 35 | 35 | <?php endif; ?> |
| 36 | 36 | |
| 37 | - <a title="<?php esc_attr_e( 'User account edition', 'wpshop' ); ?>" href="<?php echo esc_url( get_edit_user_link( $user_id ) ); ?>" target="wps_contact_edition" ><i class="dashicons dashicons-edit" ></i></a> |
|
| 37 | + <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> |
|
| 38 | 38 | |
| 39 | - <?php if ( true === $user['is_default'] ) : ?> |
|
| 40 | - <i title="<?php esc_attr_e( 'This is the main contact, you can\'t unlink it', 'wpshop' ); ?>" class="dashicons dashicons-lock" ></i> |
|
| 39 | + <?php if (true === $user['is_default']) : ?> |
|
| 40 | + <i title="<?php esc_attr_e('This is the main contact, you can\'t unlink it', 'wpshop'); ?>" class="dashicons dashicons-lock" ></i> |
|
| 41 | 41 | <?php else : ?> |
| 42 | - <i title="<?php esc_attr_e( 'Unlink this user', 'wpshop' ); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
| 42 | + <i title="<?php esc_attr_e('Unlink this user', 'wpshop'); ?>" class="dashicons dashicons-editor-unlink" ></i> |
|
| 43 | 43 | <?php endif; ?> |
| 44 | 44 | </td> |
| 45 | 45 | </tr> |
@@ -9,27 +9,27 @@ discard block |
||
| 9 | 9 | * @version 3.0.0.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if (!defined('ABSPATH')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | $default_user = 0; |
| 17 | 17 | ob_start(); |
| 18 | -require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contact' ) ); |
|
| 18 | +require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contact')); |
|
| 19 | 19 | $output = ob_get_clean(); |
| 20 | 20 | |
| 21 | 21 | ?><table class="wp-list-table widefat fixed striped users" |
| 22 | - data-dissociate-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_dissociate' ) ); ?>" |
|
| 23 | - data-change-default-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_change_default' ) ); ?>" |
|
| 24 | - data-default-user-id="<?php echo esc_attr( $default_user ); ?>" > |
|
| 22 | + data-dissociate-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_dissociate')); ?>" |
|
| 23 | + data-change-default-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_change_default')); ?>" |
|
| 24 | + data-default-user-id="<?php echo esc_attr($default_user); ?>" > |
|
| 25 | 25 | |
| 26 | 26 | <thead> |
| 27 | - <tr data-customer-id="<?php echo esc_attr( $customer->ID ); ?>" data-user-id="<?php echo esc_attr( $user_id ); ?>" > |
|
| 28 | - <td><?php esc_html_e( 'ID', 'wpshop' ); ?></td> |
|
| 29 | - <td><?php echo esc_html( 'Last Name' ) . ' - ' . esc_html( 'First Name' ); ?></td> |
|
| 30 | - <td><?php esc_html_e( 'Display name' ); ?></td> |
|
| 31 | - <td><?php esc_html_e( 'Email' ); ?></td> |
|
| 32 | - <td><?php esc_html_e( 'Phone', 'wpshop' ); ?></td> |
|
| 27 | + <tr data-customer-id="<?php echo esc_attr($customer->ID); ?>" data-user-id="<?php echo esc_attr($user_id); ?>" > |
|
| 28 | + <td><?php esc_html_e('ID', 'wpshop'); ?></td> |
|
| 29 | + <td><?php echo esc_html('Last Name') . ' - ' . esc_html('First Name'); ?></td> |
|
| 30 | + <td><?php esc_html_e('Display name'); ?></td> |
|
| 31 | + <td><?php esc_html_e('Email'); ?></td> |
|
| 32 | + <td><?php esc_html_e('Phone', 'wpshop'); ?></td> |
|
| 33 | 33 | <td class="wps-customer-contacts-actions" > </td> |
| 34 | 34 | </tr> |
| 35 | 35 | </thead> |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | <tr> |
| 43 | 43 | <td colspan="6" class="wps-customer-associate-contact-container" > |
| 44 | 44 | <span class="wps-customer-contact-association-opener" ><i class="dashicons dashicons-plus" ></i></span> |
| 45 | - <input type="text" class="wps-customer-autocomplete-input hidden" placeholder="<?php esc_html_e( 'Start typing for user searching', 'wpshop' ); ?>" |
|
| 46 | - data-search-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_search' ) ); ?>" |
|
| 45 | + <input type="text" class="wps-customer-autocomplete-input hidden" placeholder="<?php esc_html_e('Start typing for user searching', 'wpshop'); ?>" |
|
| 46 | + data-search-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_search')); ?>" |
|
| 47 | 47 | data-types="users" |
| 48 | - data-customer="<?php echo esc_attr( $customer->ID ); ?>" |
|
| 49 | - data-associate-nonce="<?php echo esc_attr( wp_create_nonce( 'wps_customer_contacts_associate' ) ); ?>" /> |
|
| 48 | + data-customer="<?php echo esc_attr($customer->ID); ?>" |
|
| 49 | + data-associate-nonce="<?php echo esc_attr(wp_create_nonce('wps_customer_contacts_associate')); ?>" /> |
|
| 50 | 50 | </td> |
| 51 | 51 | </tr> |
| 52 | 52 | </tfoot> |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @subpackage modules |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if (!defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -29,23 +29,23 @@ 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 | |
| 51 | 51 | /** |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @param string $post_type Le type d'élément sur lequel se trouve l'utilisateur / Element type where the user is. |
| 55 | 55 | */ |
| 56 | - function add_meta_box( $post_type ) { |
|
| 57 | - add_meta_box( 'wps_customer_contacts', __( 'Customer contact list', 'wpshop' ), array( $this, 'customer_contact_list_callback' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high' ); |
|
| 56 | + function add_meta_box($post_type) { |
|
| 57 | + add_meta_box('wps_customer_contacts', __('Customer contact list', 'wpshop'), array($this, 'customer_contact_list_callback'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'normal', 'high'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -64,15 +64,15 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function callback_admin_enqueue_scripts() { |
| 66 | 66 | $screen = get_current_screen(); |
| 67 | - if ( in_array( $screen->id, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
| 68 | - wp_register_style( 'wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION ); |
|
| 69 | - wp_enqueue_style( 'wps_customer_contacts-style' ); |
|
| 70 | - 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 ); |
|
| 71 | - wp_localize_script( 'wps_customer_contacts-script', 'wpshopCrm', array( |
|
| 72 | - 'confirm_user_dissociation' => __( 'Are you sure you want to dissociate this user', 'wpshop' ), |
|
| 73 | - 'confirm_change_default_user' => __( 'Are you sure you want to change default user for current customer?', 'wpshop' ), |
|
| 74 | - ) ); |
|
| 75 | - wp_enqueue_script( 'wps_customer_contacts-script' ); |
|
| 67 | + if (in_array($screen->id, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
| 68 | + wp_register_style('wps_customer_contacts-style', WPS_CUST_CONTACT_URL . 'assets/css/wps_customer_contacts.backend.css', array(), WPSHOP_VERSION); |
|
| 69 | + wp_enqueue_style('wps_customer_contacts-style'); |
|
| 70 | + 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); |
|
| 71 | + wp_localize_script('wps_customer_contacts-script', 'wpshopCrm', array( |
|
| 72 | + 'confirm_user_dissociation' => __('Are you sure you want to dissociate this user', 'wpshop'), |
|
| 73 | + 'confirm_change_default_user' => __('Are you sure you want to change default user for current customer?', 'wpshop'), |
|
| 74 | + )); |
|
| 75 | + wp_enqueue_script('wps_customer_contacts-script'); |
|
| 76 | 76 | add_thickbox(); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | * Enqueue scripts and style in frontend |
| 82 | 82 | */ |
| 83 | 83 | public function callback_enqueue_scripts() { |
| 84 | - $pagename = get_query_var( 'pagename' ); |
|
| 85 | - if ( in_array( $pagename, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) ) { |
|
| 86 | - wp_register_style( 'task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION ); |
|
| 87 | - wp_enqueue_style( 'task-manager-frontend-style' ); |
|
| 84 | + $pagename = get_query_var('pagename'); |
|
| 85 | + if (in_array($pagename, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true)) { |
|
| 86 | + wp_register_style('task-manager-frontend-style', WPS_CUST_CONTACT_URL . 'assets/css/frontend.css', array(), WPSHOP_VERSION); |
|
| 87 | + wp_enqueue_style('task-manager-frontend-style'); |
|
| 88 | 88 | } |
| 89 | - wp_register_script( 'wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION ); |
|
| 90 | - wp_enqueue_script( 'wps_customer_contacts-frontend-script' ); |
|
| 89 | + wp_register_script('wps_customer_contacts-frontend-script', WPS_CUST_CONTACT_URL . 'assets/js/wps_customer_contacts.frontend.js', array(), WPSHOP_VERSION); |
|
| 90 | + wp_enqueue_script('wps_customer_contacts-frontend-script'); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @param WP_Post $customer La définition principale du client actuellement en cours d'édition / Current edited customer definition. |
| 97 | 97 | */ |
| 98 | - function customer_contact_list_callback( $customer ) { |
|
| 99 | - $users = $this->get_customer_contact_list( $customer ); |
|
| 98 | + function customer_contact_list_callback($customer) { |
|
| 99 | + $users = $this->get_customer_contact_list($customer); |
|
| 100 | 100 | |
| 101 | 101 | /** Display user list for current customer */ |
| 102 | - require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts' ) ); |
|
| 102 | + require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'backend', 'contacts')); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -109,25 +109,25 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @return [type] [description] |
| 111 | 111 | */ |
| 112 | - function get_customer_contact_list( $customer ) { |
|
| 112 | + function get_customer_contact_list($customer) { |
|
| 113 | 113 | /** Define user list */ |
| 114 | 114 | $users = array(); |
| 115 | 115 | |
| 116 | 116 | /** Get associated users' */ |
| 117 | - $associated_users = (array) get_post_meta( $customer->ID, $this->user_contact_list_meta_key, true ); |
|
| 118 | - $user_list = wp_parse_id_list( array_merge( $associated_users, array( $customer->post_author ) ) ); |
|
| 119 | - if ( ! empty( $user_list ) ) { |
|
| 120 | - foreach ( $user_list as $user_id ) { |
|
| 121 | - if ( 0 !== $user_id ) { |
|
| 122 | - $associated_user = get_user_by( 'ID', $user_id ); |
|
| 123 | - $user_metas = get_user_meta( $user_id ); |
|
| 124 | - if ( is_object( $associated_user ) ) { |
|
| 125 | - $users[ $user_id ] = wp_parse_args( $associated_user->data, array( |
|
| 117 | + $associated_users = (array)get_post_meta($customer->ID, $this->user_contact_list_meta_key, true); |
|
| 118 | + $user_list = wp_parse_id_list(array_merge($associated_users, array($customer->post_author))); |
|
| 119 | + if (!empty($user_list)) { |
|
| 120 | + foreach ($user_list as $user_id) { |
|
| 121 | + if (0 !== $user_id) { |
|
| 122 | + $associated_user = get_user_by('ID', $user_id); |
|
| 123 | + $user_metas = get_user_meta($user_id); |
|
| 124 | + if (is_object($associated_user)) { |
|
| 125 | + $users[$user_id] = wp_parse_args($associated_user->data, array( |
|
| 126 | 126 | 'last_name' => $associated_user->last_name, |
| 127 | 127 | 'first_name' => $associated_user->first_name, |
| 128 | - 'is_default' => ( $user_id === (int) $customer->post_author ? true : false ), |
|
| 128 | + 'is_default' => ($user_id === (int)$customer->post_author ? true : false), |
|
| 129 | 129 | 'metas' => $user_metas, |
| 130 | - ) ); |
|
| 130 | + )); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -142,20 +142,20 @@ discard block |
||
| 142 | 142 | * @param integer $user_id Identifiant de l'utilisateur actuellement connecté / User identifier currenly connected. |
| 143 | 143 | * @param WP_User $account_user La définition du compte utilisateur / The user account definition. |
| 144 | 144 | */ |
| 145 | - function callback_customer_dashboard( $user_id, $account_user ) { |
|
| 145 | + function callback_customer_dashboard($user_id, $account_user) { |
|
| 146 | 146 | $customers = array(); |
| 147 | 147 | |
| 148 | - $customers_from_posts = new WP_Query( array( |
|
| 148 | + $customers_from_posts = new WP_Query(array( |
|
| 149 | 149 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
| 150 | 150 | 'author' => $user_id, |
| 151 | 151 | 'posts_per_page' => -1, |
| 152 | 152 | 'post_status' => 'any', |
| 153 | - ) ); |
|
| 154 | - if ( $customers_from_posts->have_posts() ) { |
|
| 155 | - $customers = array_merge( $customers, $customers_from_posts->posts ); |
|
| 153 | + )); |
|
| 154 | + if ($customers_from_posts->have_posts()) { |
|
| 155 | + $customers = array_merge($customers, $customers_from_posts->posts); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $customers_from_meta = new WP_Query( array( |
|
| 158 | + $customers_from_meta = new WP_Query(array( |
|
| 159 | 159 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
| 160 | 160 | 'posts_per_page' => -1, |
| 161 | 161 | 'post_status' => 'any', |
@@ -167,20 +167,20 @@ discard block |
||
| 167 | 167 | 'type' => 'CHAR', |
| 168 | 168 | ), |
| 169 | 169 | ), |
| 170 | - ) ); |
|
| 171 | - if ( $customers_from_meta->have_posts() ) { |
|
| 172 | - $customers = array_merge( $customers, $customers_from_meta->posts ); |
|
| 170 | + )); |
|
| 171 | + if ($customers_from_meta->have_posts()) { |
|
| 172 | + $customers = array_merge($customers, $customers_from_meta->posts); |
|
| 173 | 173 | } |
| 174 | - usort( $customers, function( $a, $b ) { |
|
| 175 | - if ( $a->ID === $b->ID ) { |
|
| 174 | + usort($customers, function($a, $b) { |
|
| 175 | + if ($a->ID === $b->ID) { |
|
| 176 | 176 | return 0; |
| 177 | 177 | } |
| 178 | 178 | return ($a < $b) ? -1 : 1; |
| 179 | 179 | }); |
| 180 | 180 | |
| 181 | - if ( ! empty( $customers ) && ( 1 < count( $customers ) ) ) { |
|
| 181 | + if (!empty($customers) && (1 < count($customers))) { |
|
| 182 | 182 | /** Display user list for current customer */ |
| 183 | - require( wpshop_tools::get_template_part( WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice' ) ); |
|
| 183 | + require(wpshop_tools::get_template_part(WPS_CUST_CONTACT_DIR, WPS_CUST_CONTACT_TPL, 'frontend', 'customer', 'choice')); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
@@ -190,32 +190,32 @@ discard block |
||
| 190 | 190 | * @param array $contact_methods La liste actuelle des méthodes permettant de contacter l'utilisateur / The current method list to contact a user. |
| 191 | 191 | * @param WP_user $user L'utilisateur en court d'édition / The current edited user. |
| 192 | 192 | */ |
| 193 | - public function add_contact_method_to_user( $contact_methods, $user ) { |
|
| 193 | + public function add_contact_method_to_user($contact_methods, $user) { |
|
| 194 | 194 | $wps_contact_method = array( |
| 195 | - 'wps_phone' => __( 'Phone number', 'wpshop' ), |
|
| 195 | + 'wps_phone' => __('Phone number', 'wpshop'), |
|
| 196 | 196 | ); |
| 197 | 197 | |
| 198 | - return array_merge( $wps_contact_method, $contact_methods ); |
|
| 198 | + return array_merge($wps_contact_method, $contact_methods); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Ajax callback - Associate a user to a customer |
| 203 | 203 | */ |
| 204 | 204 | function ajax_callback_associate_user() { |
| 205 | - check_ajax_referer( 'wps_customer_contacts_associate' ); |
|
| 205 | + check_ajax_referer('wps_customer_contacts_associate'); |
|
| 206 | 206 | |
| 207 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 208 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 207 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 208 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 209 | 209 | |
| 210 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 211 | - if ( ! empty( $associated_users ) ) { |
|
| 212 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $user_id ) ) ); |
|
| 210 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 211 | + if (!empty($associated_users)) { |
|
| 212 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($user_id))); |
|
| 213 | 213 | } else { |
| 214 | - $new_associated_users = array( $user_id ); |
|
| 214 | + $new_associated_users = array($user_id); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
| 218 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 217 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
| 218 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 219 | 219 | wp_die(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -223,20 +223,20 @@ discard block |
||
| 223 | 223 | * Ajax callback - Associate a user to a customer |
| 224 | 224 | */ |
| 225 | 225 | function ajax_callback_dissociate_user() { |
| 226 | - check_ajax_referer( 'wps_customer_contacts_dissociate' ); |
|
| 226 | + check_ajax_referer('wps_customer_contacts_dissociate'); |
|
| 227 | 227 | |
| 228 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 229 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 228 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 229 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 230 | 230 | |
| 231 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 232 | - foreach ( $associated_users as $key => $id ) { |
|
| 233 | - if ( $id === $user_id ) { |
|
| 234 | - unset( $associated_users[ $key ] ); |
|
| 231 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 232 | + foreach ($associated_users as $key => $id) { |
|
| 233 | + if ($id === $user_id) { |
|
| 234 | + unset($associated_users[$key]); |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $associated_users ); |
|
| 239 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 238 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $associated_users); |
|
| 239 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 240 | 240 | wp_die(); |
| 241 | 241 | } |
| 242 | 242 | |
@@ -244,30 +244,30 @@ discard block |
||
| 244 | 244 | * Ajax callback - Change the default user for a customer |
| 245 | 245 | */ |
| 246 | 246 | function ajax_callback_change_default_user() { |
| 247 | - check_ajax_referer( 'wps_customer_contacts_change_default' ); |
|
| 247 | + check_ajax_referer('wps_customer_contacts_change_default'); |
|
| 248 | 248 | |
| 249 | - $customer_id = ! empty( $_POST ) && ! empty( $_POST['CID'] ) && is_int( (int) $_POST['CID'] ) ? (int) $_POST['CID'] : null; |
|
| 250 | - $user_id = ! empty( $_POST ) && ! empty( $_POST['UID'] ) && is_int( (int) $_POST['UID'] ) ? (int) $_POST['UID'] : null; |
|
| 251 | - $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; |
|
| 249 | + $customer_id = !empty($_POST) && !empty($_POST['CID']) && is_int((int)$_POST['CID']) ? (int)$_POST['CID'] : null; |
|
| 250 | + $user_id = !empty($_POST) && !empty($_POST['UID']) && is_int((int)$_POST['UID']) ? (int)$_POST['UID'] : null; |
|
| 251 | + $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 | 252 | |
| 253 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_author' => $user_id ), array( 'ID' => $customer_id ) ); |
|
| 254 | - $customer_default_user_changes = get_post_meta( $customer_id, '_wps_customer_default_user_histo', true ); |
|
| 253 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, array('post_author' => $user_id), array('ID' => $customer_id)); |
|
| 254 | + $customer_default_user_changes = get_post_meta($customer_id, '_wps_customer_default_user_histo', true); |
|
| 255 | 255 | $customer_default_user_changes[] = array( |
| 256 | - 'date' => current_time( 'mysql' ), |
|
| 256 | + 'date' => current_time('mysql'), |
|
| 257 | 257 | 'old_post_author' => $old_user_id, |
| 258 | 258 | 'update_author' => get_current_user_id(), |
| 259 | 259 | ); |
| 260 | - update_post_meta( $customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes ); |
|
| 260 | + update_post_meta($customer_id, '_wps_customer_default_user_histo', $customer_default_user_changes); |
|
| 261 | 261 | |
| 262 | - $associated_users = get_post_meta( $customer_id, $this->user_contact_list_meta_key, true ); |
|
| 263 | - if ( ! empty( $associated_users ) ) { |
|
| 264 | - $new_associated_users = wp_parse_id_list( array_merge( $associated_users, array( $old_user_id ) ) ); |
|
| 262 | + $associated_users = get_post_meta($customer_id, $this->user_contact_list_meta_key, true); |
|
| 263 | + if (!empty($associated_users)) { |
|
| 264 | + $new_associated_users = wp_parse_id_list(array_merge($associated_users, array($old_user_id))); |
|
| 265 | 265 | } else { |
| 266 | - $new_associated_users = array( $old_user_id ); |
|
| 266 | + $new_associated_users = array($old_user_id); |
|
| 267 | 267 | } |
| 268 | - update_post_meta( $customer_id, $this->user_contact_list_meta_key, $new_associated_users ); |
|
| 268 | + update_post_meta($customer_id, $this->user_contact_list_meta_key, $new_associated_users); |
|
| 269 | 269 | |
| 270 | - $this->customer_contact_list_callback( get_post( $customer_id ) ); |
|
| 270 | + $this->customer_contact_list_callback(get_post($customer_id)); |
|
| 271 | 271 | wp_die(); |
| 272 | 272 | } |
| 273 | 273 | |