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