Passed
Pull Request — master (#782)
by Kiran
15:30
created
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -5,126 +5,126 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing' => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id' => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'    => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'        => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number' => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
104
-				return;
105
-			}
106
-
107
-			$show_fields = $this->get_customer_meta_fields();
108
-
109
-			$customer = getpaid_get_customer_by_user_id( (int) $user->ID );
110
-
111
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
112
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing' => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id' => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'    => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'        => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number' => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
104
+                return;
105
+            }
106
+
107
+            $show_fields = $this->get_customer_meta_fields();
108
+
109
+            $customer = getpaid_get_customer_by_user_id( (int) $user->ID );
110
+
111
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
112
+                ?>
113 113
 				<h2><?php echo esc_html( $fieldset['title'] ); ?></h2>
114 114
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
115 115
 					<?php foreach ( $fieldset['fields'] as $key => $field ) :
116
-						if ( ! empty( $customer ) ) {
117
-							if ( strpos( $key, '_wpinv_' ) === 0 ) {
118
-								$save_key = substr( $key , 7 );
119
-							} else {
120
-								$save_key = $key;
121
-							}
122
-
123
-							$value = $customer->get( $save_key );
124
-						} else {
125
-							$value = $this->get_user_meta( $user->ID, $key );
126
-						}
127
-						?>
116
+                        if ( ! empty( $customer ) ) {
117
+                            if ( strpos( $key, '_wpinv_' ) === 0 ) {
118
+                                $save_key = substr( $key , 7 );
119
+                            } else {
120
+                                $save_key = $key;
121
+                            }
122
+
123
+                            $value = $customer->get( $save_key );
124
+                        } else {
125
+                            $value = $this->get_user_meta( $user->ID, $key );
126
+                        }
127
+                        ?>
128 128
 						<tr>
129 129
 							<th>
130 130
 								<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
@@ -147,75 +147,75 @@  discard block
 block discarded – undo
147 147
 					<?php endforeach; ?>
148 148
 				</table>
149 149
 				<?php
150
-			endforeach;
151
-		}
152
-
153
-		/**
154
-		 * Save Address Fields on edit user pages.
155
-		 *
156
-		 * @param int $user_id User ID of the user being saved
157
-		 */
158
-		public function save_customer_meta_fields( $user_id ) {
159
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
160
-				return;
161
-			}
162
-
163
-			$save_fields = $this->get_customer_meta_fields();
164
-			$save_data = array();
165
-
166
-			foreach ( $save_fields as $fieldset ) {
167
-				foreach ( $fieldset['fields'] as $key => $field ) {
168
-					if ( strpos( $key, '_wpinv_' ) === 0 ) {
169
-						$save_key = substr( $key , 7 );
170
-					} else {
171
-						$save_key = $key;
172
-					}
173
-
174
-					if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
175
-						$save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false;
176
-					} else if ( $save_key && isset( $_POST[ $key ] ) ) {
177
-						$save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] );
178
-					}
179
-				}
180
-			}
181
-
182
-			if ( empty( $save_data ) ) {
183
-				return;
184
-			}
185
-
186
-			$customer = getpaid_get_customer_by_user_id( (int) $user_id );
187
-
188
-			if ( empty( $customer ) ) {
189
-				$customer = new GetPaid_Customer( 0 );
190
-				$customer->clone_user( (int) $user_id );
191
-			}
192
-
193
-			foreach ( $save_data as $key => $value ) {
194
-				$customer->set( $key, $value );
195
-			}
196
-
197
-			$customer->save();
198
-		}
199
-
200
-		/**
201
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
202
-		 *
203
-		 * @since 3.1.0
204
-		 * @param int    $user_id User ID of the user being edited
205
-		 * @param string $key     Key for user meta field
206
-		 * @return string
207
-		 */
208
-		protected function get_user_meta( $user_id, $key ) {
209
-			$value           = get_user_meta( $user_id, $key, true );
210
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
211
-
212
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
213
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
214
-			}
215
-
216
-			return $value;
217
-		}
218
-	}
150
+            endforeach;
151
+        }
152
+
153
+        /**
154
+         * Save Address Fields on edit user pages.
155
+         *
156
+         * @param int $user_id User ID of the user being saved
157
+         */
158
+        public function save_customer_meta_fields( $user_id ) {
159
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
160
+                return;
161
+            }
162
+
163
+            $save_fields = $this->get_customer_meta_fields();
164
+            $save_data = array();
165
+
166
+            foreach ( $save_fields as $fieldset ) {
167
+                foreach ( $fieldset['fields'] as $key => $field ) {
168
+                    if ( strpos( $key, '_wpinv_' ) === 0 ) {
169
+                        $save_key = substr( $key , 7 );
170
+                    } else {
171
+                        $save_key = $key;
172
+                    }
173
+
174
+                    if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
175
+                        $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false;
176
+                    } else if ( $save_key && isset( $_POST[ $key ] ) ) {
177
+                        $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] );
178
+                    }
179
+                }
180
+            }
181
+
182
+            if ( empty( $save_data ) ) {
183
+                return;
184
+            }
185
+
186
+            $customer = getpaid_get_customer_by_user_id( (int) $user_id );
187
+
188
+            if ( empty( $customer ) ) {
189
+                $customer = new GetPaid_Customer( 0 );
190
+                $customer->clone_user( (int) $user_id );
191
+            }
192
+
193
+            foreach ( $save_data as $key => $value ) {
194
+                $customer->set( $key, $value );
195
+            }
196
+
197
+            $customer->save();
198
+        }
199
+
200
+        /**
201
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
202
+         *
203
+         * @since 3.1.0
204
+         * @param int    $user_id User ID of the user being edited
205
+         * @param string $key     Key for user meta field
206
+         * @return string
207
+         */
208
+        protected function get_user_meta( $user_id, $key ) {
209
+            $value           = get_user_meta( $user_id, $key, true );
210
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
211
+
212
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
213
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
214
+            }
215
+
216
+            return $value;
217
+        }
218
+    }
219 219
 
220 220
 endif;
221 221
 
Please login to merge, or discard this patch.