PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-client-handler.php +609 -542 5.0.3 → 6.2.1 View file →
@@ -6,8 +6,13 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Client_Handler
12 17 *
13 18 * @package MainWP\Dashboard
@@ -13,613 +18,675 @@
13 18 * @package MainWP\Dashboard
14 19 *
15 20 * @uses \MainWP\Dashboard\MainWP_Client_Handler
16 21 */
17 -class MainWP_Client_Handler {
22 +class MainWP_Client_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18 23
19 - /**
20 - * Private static variable to hold the single instance of the class.
21 - *
22 - * @static
23 - *
24 - * @var mixed Default null
25 - */
26 - private static $instance = null;
24 + /**
25 + * Private static variable to hold the single instance of the class.
26 + *
27 + * @static
28 + *
29 + * @var mixed Default null
30 + */
31 + private static $instance = null;
27 32
28 - /**
29 - * Method instance()
30 - *
31 - * Create a public static instance.
32 - *
33 - * @static
34 - * @return MainWP_Client_Handler
35 - */
36 - public static function instance() {
37 - if ( null === self::$instance ) {
38 - self::$instance = new self();
39 - }
40 - return self::$instance;
41 - }
33 + /**
34 + * Method instance()
35 + *
36 + * Create a public static instance.
37 + *
38 + * @static
39 + * @return MainWP_Client_Handler
40 + */
41 + public static function instance() {
42 + if ( null === static::$instance ) {
43 + static::$instance = new self();
44 + }
45 + return static::$instance;
46 + }
42 47
43 48
44 - /**
45 - * Get default client fields.
46 - *
47 - * Get default client fields.
48 - */
49 - public static function get_default_client_fields() {
49 + /**
50 + * Get default client fields.
51 + *
52 + * Get default client fields.
53 + */
54 + public static function get_default_client_fields() {
50 55
51 - return array(
52 - 'client.name' => array(
53 - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ),
54 - 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
55 - 'db_field' => 'name',
56 - ),
57 - 'client.email' => array(
58 - 'title' => esc_html__( 'Client email', 'mainwp' ),
59 - 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
60 - 'db_field' => 'client_email',
61 - ),
62 - 'client.phone' => array(
63 - 'title' => esc_html__( 'Client phone', 'mainwp' ),
64 - 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ),
65 - 'db_field' => 'client_phone',
66 - ),
67 - 'client.facebook' => array(
68 - 'title' => esc_html__( 'Client Facebook', 'mainwp' ),
69 - 'desc' => esc_html__( 'Displays the client Facebook', 'mainwp' ),
70 - 'db_field' => 'client_facebook',
71 - ),
72 - 'client.twitter' => array(
73 - 'title' => esc_html__( 'Client Twitter', 'mainwp' ),
74 - 'desc' => esc_html__( 'Displays the client Twitter', 'mainwp' ),
75 - 'db_field' => 'client_twitter',
76 - ),
77 - 'client.instagram' => array(
78 - 'title' => esc_html__( 'Client Instagram', 'mainwp' ),
79 - 'desc' => esc_html__( 'Displays the client Instagram', 'mainwp' ),
80 - 'db_field' => 'client_instagram',
81 - ),
82 - 'client.linkedin' => array(
83 - 'title' => esc_html__( 'Client LinkedIn', 'mainwp' ),
84 - 'desc' => esc_html__( 'Displays the client LinkedIn', 'mainwp' ),
85 - 'db_field' => 'client_linkedin',
86 - ),
87 - 'client.contact.address.1' => array(
88 - 'title' => esc_html__( 'Client address 1', 'mainwp' ),
89 - 'desc' => esc_html__( 'Displays the client contact address 1', 'mainwp' ),
90 - 'db_field' => 'address_1',
91 - ),
92 - 'client.contact.address.2' => array(
93 - 'title' => esc_html__( 'Client address 2', 'mainwp' ),
94 - 'desc' => esc_html__( 'Displays the client contact address 2', 'mainwp' ),
95 - 'db_field' => 'address_2',
96 - ),
97 - 'client.city' => array(
98 - 'title' => esc_html__( 'Client city', 'mainwp' ),
99 - 'desc' => esc_html__( 'Displays the client city', 'mainwp' ),
100 - 'db_field' => 'city',
101 - ),
102 - 'client.state' => array(
103 - 'title' => esc_html__( 'Client state', 'mainwp' ),
104 - 'desc' => esc_html__( 'Displays the client state', 'mainwp' ),
105 - 'db_field' => 'state',
106 - ),
107 - 'client.zip' => array(
108 - 'title' => esc_html__( 'Client ZIP', 'mainwp' ),
109 - 'desc' => esc_html__( 'Displays the client ZIP code', 'mainwp' ),
110 - 'db_field' => 'zip',
111 - ),
112 - 'client.country' => array(
113 - 'title' => esc_html__( 'Client country', 'mainwp' ),
114 - 'desc' => esc_html__( 'Displays the client country', 'mainwp' ),
115 - 'db_field' => 'country',
116 - ),
117 - 'client.note' => array(
118 - 'title' => esc_html__( 'Client notes', 'mainwp' ),
119 - 'desc' => esc_html__( 'Displays the client note', 'mainwp' ),
120 - 'db_field' => 'note',
121 - ),
122 - 'client.suspended' => array(
123 - 'title' => esc_html__( 'Client status', 'mainwp' ),
124 - 'desc' => esc_html__( 'Displays the client suspended state', 'mainwp' ),
125 - 'db_field' => 'suspended',
126 - ),
127 - 'client.created' => array(
128 - 'title' => esc_html__( 'Added on', 'mainwp' ),
129 - 'desc' => esc_html__( 'Displays the client added on', 'mainwp' ),
130 - 'tooltip' => esc_html__( 'Set the date your client was added to your MainWP Dashboard.', 'mainwp' ),
131 - 'db_field' => 'created',
132 - ),
133 - );
134 - }
56 + return array(
57 + 'client.name' => array(
58 + 'title' => esc_html__( 'Client Name', 'mainwp' ),
59 + 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
60 + 'db_field' => 'name',
61 + 'required' => true,
62 + ),
63 + 'client.email' => array(
64 + 'title' => esc_html__( 'Client email', 'mainwp' ),
65 + 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
66 + 'db_field' => 'client_email',
67 + ),
68 + 'client.phone' => array(
69 + 'title' => esc_html__( 'Client phone', 'mainwp' ),
70 + 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ),
71 + 'db_field' => 'client_phone',
72 + ),
73 + 'client.facebook' => array(
74 + 'title' => esc_html__( 'Client Facebook', 'mainwp' ),
75 + 'desc' => esc_html__( 'Displays the client Facebook', 'mainwp' ),
76 + 'db_field' => 'client_facebook',
77 + ),
78 + 'client.twitter' => array(
79 + 'title' => esc_html__( 'Client X', 'mainwp' ),
80 + 'desc' => esc_html__( 'Displays the client X', 'mainwp' ),
81 + 'db_field' => 'client_twitter',
82 + ),
83 + 'client.instagram' => array(
84 + 'title' => esc_html__( 'Client Instagram', 'mainwp' ),
85 + 'desc' => esc_html__( 'Displays the client Instagram', 'mainwp' ),
86 + 'db_field' => 'client_instagram',
87 + ),
88 + 'client.linkedin' => array(
89 + 'title' => esc_html__( 'Client LinkedIn', 'mainwp' ),
90 + 'desc' => esc_html__( 'Displays the client LinkedIn', 'mainwp' ),
91 + 'db_field' => 'client_linkedin',
92 + ),
93 + 'client.contact.address.1' => array(
94 + 'title' => esc_html__( 'Client address 1', 'mainwp' ),
95 + 'desc' => esc_html__( 'Displays the client contact address 1', 'mainwp' ),
96 + 'db_field' => 'address_1',
97 + ),
98 + 'client.contact.address.2' => array(
99 + 'title' => esc_html__( 'Client address 2', 'mainwp' ),
100 + 'desc' => esc_html__( 'Displays the client contact address 2', 'mainwp' ),
101 + 'db_field' => 'address_2',
102 + ),
103 + 'client.city' => array(
104 + 'title' => esc_html__( 'Client city', 'mainwp' ),
105 + 'desc' => esc_html__( 'Displays the client city', 'mainwp' ),
106 + 'db_field' => 'city',
107 + ),
108 + 'client.state' => array(
109 + 'title' => esc_html__( 'Client state', 'mainwp' ),
110 + 'desc' => esc_html__( 'Displays the client state', 'mainwp' ),
111 + 'db_field' => 'state',
112 + ),
113 + 'client.zip' => array(
114 + 'title' => esc_html__( 'Client ZIP', 'mainwp' ),
115 + 'desc' => esc_html__( 'Displays the client ZIP code', 'mainwp' ),
116 + 'db_field' => 'zip',
117 + ),
118 + 'client.country' => array(
119 + 'title' => esc_html__( 'Client country', 'mainwp' ),
120 + 'desc' => esc_html__( 'Displays the client country', 'mainwp' ),
121 + 'db_field' => 'country',
122 + ),
123 + 'client.note' => array(
124 + 'title' => esc_html__( 'Client notes', 'mainwp' ),
125 + 'desc' => esc_html__( 'Displays the client note', 'mainwp' ),
126 + 'db_field' => 'note',
127 + ),
128 + 'client.suspended' => array(
129 + 'title' => esc_html__( 'Client status', 'mainwp' ),
130 + 'desc' => esc_html__( 'Displays the client suspended state', 'mainwp' ),
131 + 'db_field' => 'suspended',
132 + ),
133 + 'client.created' => array(
134 + 'title' => esc_html__( 'Added on', 'mainwp' ),
135 + 'desc' => esc_html__( 'Displays the client added on', 'mainwp' ),
136 + 'db_field' => 'created',
137 + ),
138 + );
139 + }
135 140
136 - /**
137 - * Get default client fields.
138 - *
139 - * Get default client fields.
140 - */
141 - public static function get_mini_default_client_fields() {
141 + /**
142 + * Get default client fields.
143 + *
144 + * Get default client fields.
145 + */
146 + public static function get_mini_default_client_fields() {
142 147
143 - return array(
144 - 'client.name' => array(
145 - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ),
146 - 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
147 - 'db_field' => 'name',
148 - ),
149 - 'client.email' => array(
150 - 'title' => esc_html__( 'Client email', 'mainwp' ),
151 - 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
152 - 'db_field' => 'client_email',
153 - ),
154 - 'client.phone' => array(
155 - 'title' => esc_html__( 'Client phone', 'mainwp' ),
156 - 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ),
157 - 'db_field' => 'client_phone',
158 - ),
159 - );
160 - }
148 + return array(
149 + 'client.name' => array(
150 + 'title' => esc_html__( 'Client Name', 'mainwp' ),
151 + 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
152 + 'db_field' => 'name',
153 + 'required' => true,
154 + ),
155 + 'client.email' => array(
156 + 'title' => esc_html__( 'Client email', 'mainwp' ),
157 + 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
158 + 'db_field' => 'client_email',
159 + 'required' => false,
160 + ),
161 + 'client.phone' => array(
162 + 'title' => esc_html__( 'Client phone', 'mainwp' ),
163 + 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ),
164 + 'db_field' => 'client_phone',
165 + 'required' => false,
166 + ),
167 + );
168 + }
161 169
162 170
163 - /**
164 - * Get default contact fields.
165 - *
166 - * Get default contact fields.
167 - */
168 - public static function get_default_contact_fields() {
169 - return array(
170 - 'client.contact.name' => array(
171 - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ),
172 - 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
173 - 'db_field' => 'contact_name',
174 - ),
175 - 'contact.role' => array(
176 - 'title' => esc_html__( 'Contact role', 'mainwp' ),
177 - 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
178 - 'db_field' => 'contact_role',
179 - ),
180 - 'contact.email' => array(
181 - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ),
182 - 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
183 - 'db_field' => 'contact_email',
184 - ),
185 - 'contact.phone' => array(
186 - 'title' => esc_html__( 'Contact phone', 'mainwp' ),
187 - 'desc' => esc_html__( 'Displays the contact phone', 'mainwp' ),
188 - 'db_field' => 'contact_phone',
189 - ),
190 - 'contact.facebook' => array(
191 - 'title' => esc_html__( 'Contact Facebook', 'mainwp' ),
192 - 'desc' => esc_html__( 'Displays the contact Facebook', 'mainwp' ),
193 - 'db_field' => 'facebook',
194 - ),
195 - 'contact.twitter' => array(
196 - 'title' => esc_html__( 'Contact Twitter', 'mainwp' ),
197 - 'desc' => esc_html__( 'Displays the contact Twitter', 'mainwp' ),
198 - 'db_field' => 'twitter',
199 - ),
200 - 'contact.instagram' => array(
201 - 'title' => esc_html__( 'Contact Instagram', 'mainwp' ),
202 - 'desc' => esc_html__( 'Displays the contact Instagram', 'mainwp' ),
203 - 'db_field' => 'instagram',
204 - ),
205 - 'contact.linkedin' => array(
206 - 'title' => esc_html__( 'Contact LinkedIn', 'mainwp' ),
207 - 'desc' => esc_html__( 'Displays the contact LinkedIn', 'mainwp' ),
208 - 'db_field' => 'linkedin',
209 - ),
210 - );
211 - }
171 + /**
172 + * Get default contact fields.
173 + *
174 + * Get default contact fields.
175 + */
176 + public static function get_default_contact_fields() {
177 + return array(
178 + 'client.contact.name' => array(
179 + 'title' => esc_html__( 'Contact name', 'mainwp' ),
180 + 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
181 + 'db_field' => 'contact_name',
182 + 'required' => true,
183 + ),
184 + 'contact.email' => array(
185 + 'title' => esc_html__( 'Contact email', 'mainwp' ),
186 + 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
187 + 'db_field' => 'contact_email',
188 + 'required' => true,
189 + ),
190 + 'contact.role' => array(
191 + 'title' => esc_html__( 'Contact role', 'mainwp' ),
192 + 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
193 + 'db_field' => 'contact_role',
194 + ),
195 + 'contact.phone' => array(
196 + 'title' => esc_html__( 'Contact phone', 'mainwp' ),
197 + 'desc' => esc_html__( 'Displays the contact phone', 'mainwp' ),
198 + 'db_field' => 'contact_phone',
199 + ),
200 + 'contact.facebook' => array(
201 + 'title' => esc_html__( 'Contact Facebook', 'mainwp' ),
202 + 'desc' => esc_html__( 'Displays the contact Facebook', 'mainwp' ),
203 + 'db_field' => 'facebook',
204 + ),
205 + 'contact.twitter' => array(
206 + 'title' => esc_html__( 'Contact X', 'mainwp' ),
207 + 'desc' => esc_html__( 'Displays the contact X', 'mainwp' ),
208 + 'db_field' => 'twitter',
209 + ),
210 + 'contact.instagram' => array(
211 + 'title' => esc_html__( 'Contact Instagram', 'mainwp' ),
212 + 'desc' => esc_html__( 'Displays the contact Instagram', 'mainwp' ),
213 + 'db_field' => 'instagram',
214 + ),
215 + 'contact.linkedin' => array(
216 + 'title' => esc_html__( 'Contact LinkedIn', 'mainwp' ),
217 + 'desc' => esc_html__( 'Displays the contact LinkedIn', 'mainwp' ),
218 + 'db_field' => 'linkedin',
219 + ),
220 + );
221 + }
212 222
213 - /**
214 - * Get default contact fields.
215 - *
216 - * Get default contact fields.
217 - */
218 - public static function get_mini_default_contact_fields() {
219 - return array(
220 - 'client.contact.name' => array(
221 - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ),
222 - 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
223 - 'db_field' => 'contact_name',
224 - ),
225 - 'contact.role' => array(
226 - 'title' => esc_html__( 'Contact role', 'mainwp' ),
227 - 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
228 - 'db_field' => 'contact_role',
229 - ),
230 - 'contact.email' => array(
231 - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ),
232 - 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
233 - 'db_field' => 'contact_email',
234 - ),
235 - );
236 - }
223 + /**
224 + * Get default contact fields.
225 + *
226 + * Get default contact fields.
227 + */
228 + public static function get_mini_default_contact_fields() {
229 + return array(
230 + 'client.contact.name' => array(
231 + 'title' => esc_html__( 'Contact name', 'mainwp' ),
232 + 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
233 + 'db_field' => 'contact_name',
234 + 'required' => true,
235 + ),
236 + 'contact.email' => array(
237 + 'title' => esc_html__( 'Contact email', 'mainwp' ),
238 + 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
239 + 'db_field' => 'contact_email',
240 + 'required' => true,
241 + ),
242 + 'contact.role' => array(
243 + 'title' => esc_html__( 'Contact role', 'mainwp' ),
244 + 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
245 + 'db_field' => 'contact_role',
246 + 'required' => false,
247 + ),
248 + );
249 + }
237 250
238 251
239 - /**
240 - * Method get_compatible_tokens().
241 - *
242 - * Get compatible tokens.
243 - */
244 - public static function get_compatible_tokens() {
245 - return array(
246 - 'client.contact.name' => 'client.contact.name',
247 - 'client.email' => 'contact.email',
248 - 'client.phone' => 'contact.phone',
249 - );
250 - }
251 - /**
252 - * Method rest_api_add_client().
253 - *
254 - * Rest API add client.
255 - *
256 - * @param array $data fields array.
257 - * @param bool $edit Is edit.
258 - *
259 - * $data fields.
260 - * 'client_email'.
261 - * 'name'.
262 - * 'client_facebook'.
263 - * 'client_twitter'.
264 - * 'client_instagram'.
265 - * 'client_linkedin'.
266 - * 'address_1'.
267 - * 'address_2'.
268 - * 'city'.
269 - * 'zip'.
270 - * 'state'.
271 - * 'note'.
272 - * 'selected_sites'.
273 - * 'client_id'. - to edit client.
274 - *
275 - * @throws \Exception Error message.
276 - * @return mixed Results.
277 - */
278 - public static function rest_api_add_client( $data, $edit = false ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
252 + /**
253 + * Method get_compatible_tokens().
254 + *
255 + * Get compatible tokens.
256 + */
257 + public static function get_compatible_tokens() {
258 + return array(
259 + 'client.contact.name' => 'client.contact.name',
260 + 'client.email' => 'contact.email',
261 + 'client.phone' => 'contact.phone',
262 + );
263 + }
264 + /**
265 + * Method rest_api_add_client().
266 + *
267 + * Rest API add client.
268 + *
269 + * @param array $data fields array.
270 + * @param bool $edit Is edit.
271 + *
272 + * $data fields.
273 + * 'client_email'.
274 + * 'name'.
275 + * 'client_facebook'.
276 + * 'client_twitter'.
277 + * 'client_instagram'.
278 + * 'client_linkedin'.
279 + * 'address_1'.
280 + * 'address_2'.
281 + * 'city'.
282 + * 'zip'.
283 + * 'state'.
284 + * 'note'.
285 + * 'selected_sites'.
286 + * 'client_id'. - to edit client.
287 + *
288 + * @throws \Exception Error message.
289 + * @return mixed Results.
290 + */
291 + public static function rest_api_add_client( $data, $edit = false ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
279 292
280 - $params = array();
293 + if ( empty( $data ) || ! is_array( $data ) ) {
294 + return array( 'error' => esc_html__( 'Invalid Client data. Please try again.', 'mainwp' ) );
295 + }
281 296
282 - if ( $edit ) {
297 + $params = array();
283 298
284 - $client_id = isset( $data['client_id'] ) ? intval( $data['client_id'] ) : 0;
299 + try {
285 300
286 - if ( empty( $client_id ) ) { // edit client.
287 - return array(
288 - 'error' => esc_html__( 'Client ID field is required! Please enter a Client ID.', 'mainwp' ),
289 - );
290 - }
301 + if ( $edit ) {
291 302
292 - $params['client_id'] = $client_id;
303 + $client_id = isset( $data['client_id'] ) ? intval( $data['client_id'] ) : 0;
293 304
294 - if ( isset( $data['name'] ) ) {
295 - $params['name'] = sanitize_text_field( wp_unslash( $data['name'] ) );
296 - }
305 + if ( empty( $client_id ) ) { // edit client.
306 + return array(
307 + 'error' => esc_html__( 'Client ID field is required! Please enter a Client ID.', 'mainwp' ),
308 + );
309 + }
297 310
298 - if ( isset( $data['address_1'] ) ) {
299 - $params['address_1'] = sanitize_text_field( wp_unslash( $data['address_1'] ) );
300 - }
301 - if ( isset( $data['address_2'] ) ) {
302 - $params['address_2'] = sanitize_text_field( wp_unslash( $data['address_2'] ) );
303 - }
304 - if ( isset( $data['city'] ) ) {
305 - $params['city'] = sanitize_text_field( wp_unslash( $data['city'] ) );
306 - }
307 - if ( isset( $data['zip'] ) ) {
308 - $params['zip'] = sanitize_text_field( wp_unslash( $data['zip'] ) );
309 - }
310 - if ( isset( $data['state'] ) ) {
311 - $params['state'] = sanitize_text_field( wp_unslash( $data['state'] ) );
312 - }
311 + $params['client_id'] = $client_id;
313 312
314 - if ( isset( $data['country'] ) ) {
315 - $params['country'] = sanitize_text_field( wp_unslash( $data['country'] ) );
316 - }
313 + if ( isset( $data['name'] ) && ! empty( trim( $data['name'] ) ) ) {
314 + $params['name'] = sanitize_text_field( wp_unslash( $data['name'] ) );
315 + }
317 316
318 - if ( isset( $data['note'] ) ) {
319 - $params['note'] = sanitize_text_field( wp_unslash( $data['note'] ) );
320 - }
317 + if ( isset( $data['address_1'] ) ) {
318 + $params['address_1'] = sanitize_text_field( wp_unslash( $data['address_1'] ) );
319 + }
320 + if ( isset( $data['address_2'] ) ) {
321 + $params['address_2'] = sanitize_text_field( wp_unslash( $data['address_2'] ) );
322 + }
323 + if ( isset( $data['city'] ) ) {
324 + $params['city'] = sanitize_text_field( wp_unslash( $data['city'] ) );
325 + }
326 + if ( isset( $data['zip'] ) ) {
327 + $params['zip'] = sanitize_text_field( wp_unslash( $data['zip'] ) );
328 + }
329 + if ( isset( $data['state'] ) ) {
330 + $params['state'] = sanitize_text_field( wp_unslash( $data['state'] ) );
331 + }
321 332
322 - if ( isset( $data['client_email'] ) ) {
323 - $params['client_email'] = sanitize_text_field( wp_unslash( $data['client_email'] ) );
324 - }
333 + if ( isset( $data['country'] ) ) {
334 + $params['country'] = sanitize_text_field( wp_unslash( $data['country'] ) );
335 + }
325 336
326 - if ( isset( $data['client_phone'] ) ) {
327 - $params['client_phone'] = sanitize_text_field( wp_unslash( $data['client_phone'] ) );
328 - }
337 + if ( isset( $data['note'] ) ) {
338 + $params['note'] = sanitize_text_field( wp_unslash( $data['note'] ) );
339 + }
329 340
330 - if ( isset( $data['client_facebook'] ) ) {
331 - $params['client_facebook'] = sanitize_text_field( wp_unslash( $data['client_facebook'] ) );
332 - }
341 + if ( isset( $data['client_email'] ) ) {
342 + $params['client_email'] = sanitize_text_field( wp_unslash( $data['client_email'] ) );
343 + }
333 344
334 - if ( isset( $data['client_twitter'] ) ) {
335 - $params['client_twitter'] = sanitize_text_field( wp_unslash( $data['client_twitter'] ) );
336 - }
345 + if ( isset( $data['client_phone'] ) ) {
346 + $params['client_phone'] = sanitize_text_field( wp_unslash( $data['client_phone'] ) );
347 + }
337 348
338 - if ( isset( $data['client_instagram'] ) ) {
339 - $params['client_instagram'] = sanitize_text_field( wp_unslash( $data['client_instagram'] ) );
340 - }
349 + if ( isset( $data['client_facebook'] ) ) {
350 + $params['client_facebook'] = sanitize_text_field( wp_unslash( $data['client_facebook'] ) );
351 + }
341 352
342 - if ( isset( $data['client_linkedin'] ) ) {
343 - $params['client_linkedin'] = sanitize_text_field( wp_unslash( $data['client_linkedin'] ) );
344 - }
353 + if ( isset( $data['client_twitter'] ) ) {
354 + $params['client_twitter'] = sanitize_text_field( wp_unslash( $data['client_twitter'] ) );
355 + }
345 356
346 - if ( isset( $data['created'] ) && is_numeric( $data['created'] ) ) {
347 - $params['created'] = intval( $data['created'] );
348 - }
357 + if ( isset( $data['client_instagram'] ) ) {
358 + $params['client_instagram'] = sanitize_text_field( wp_unslash( $data['client_instagram'] ) );
359 + }
349 360
350 - try {
351 - MainWP_DB_Client::instance()->update_client( $params, true );
352 - } catch ( \Exception $e ) {
353 - throw $e;
354 - }
361 + if ( isset( $data['client_linkedin'] ) ) {
362 + $params['client_linkedin'] = sanitize_text_field( wp_unslash( $data['client_linkedin'] ) );
363 + }
355 364
356 - if ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) {
357 - $selected_sites = array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) );
358 - MainWP_DB_Client::instance()->update_selected_sites_for_client( $client_id, $selected_sites );
359 - }
365 + if ( isset( $data['created'] ) && is_numeric( $data['created'] ) ) {
366 + $params['created'] = intval( $data['created'] );
367 + }
360 368
361 - if ( isset( $data['custom_fields'] ) && is_array( $data['custom_fields'] ) ) {
362 - $custom_fields = wp_unslash( $data['custom_fields'] );
363 - foreach ( $custom_fields as $field ) {
364 - $fie_name = isset( $field['field_name'] ) ? sanitize_text_field( wp_unslash( $field['field_name'] ) ) : '';
365 - $fie_value = isset( $field['field_value'] ) ? sanitize_text_field( wp_unslash( $field['field_value'] ) ) : '';
366 - $fie_desc = isset( $field['field_desc'] ) ? sanitize_text_field( wp_unslash( $field['field_desc'] ) ) : '';
367 - if ( ! empty( $fie_name ) && ! empty( $fie_value ) ) {
368 - $get_gen_field = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $fie_name, 0 );
369 - if ( $get_gen_field ) { // it is general field.
370 - if ( ! empty( $fie_desc ) ) {
371 - MainWP_DB_Client::instance()->update_client_field(
372 - $get_gen_field->field_id,
373 - array(
374 - 'field_desc' => $fie_desc,
375 - )
376 - );
377 - }
378 - MainWP_DB_Client::instance()->update_client_field_value( $get_gen_field->field_id, $fie_value, $client_id ); // add or update general field value for the client.
379 - } else {
380 - $indi_gen_field = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $fie_name, $client_id );
381 - if ( $indi_gen_field ) { // it is individual field.
369 + MainWP_DB_Client::instance()->update_client( $params, true );
382 370
383 - if ( ! empty( $fie_desc ) ) {
384 - MainWP_DB_Client::instance()->update_client_field(
385 - $indi_gen_field->field_id,
386 - array(
387 - 'field_desc' => $fie_desc,
388 - 'client_id' => $client_id,
389 - )
390 - );
391 - }
392 - MainWP_DB_Client::instance()->update_client_field_value( $indi_gen_field->field_id, $fie_value, $client_id ); // add or update individual field value for the client.
393 - }
394 - }
395 - }
396 - }
397 - }
371 + if ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) {
372 + $selected_sites = array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) );
373 + MainWP_DB_Client::instance()->update_selected_sites_for_client( $client_id, $selected_sites );
374 + }
398 375
399 - return array(
400 - 'success' => true,
401 - 'clientid' => $client_id,
402 - );
376 + if ( isset( $data['custom_fields'] ) && is_array( $data['custom_fields'] ) ) {
377 + $custom_fields = wp_unslash( $data['custom_fields'] );
378 + foreach ( $custom_fields as $field ) {
379 + $fie_name = isset( $field['field_name'] ) ? sanitize_text_field( wp_unslash( $field['field_name'] ) ) : '';
380 + $fie_value = isset( $field['field_value'] ) ? sanitize_text_field( wp_unslash( $field['field_value'] ) ) : '';
381 + $fie_desc = isset( $field['field_desc'] ) ? sanitize_text_field( wp_unslash( $field['field_desc'] ) ) : '';
382 + if ( ! empty( $fie_name ) && ! empty( $fie_value ) ) {
383 + $get_gen_field = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $fie_name, 0 );
384 + if ( $get_gen_field ) { // it is general field.
385 + if ( ! empty( $fie_desc ) ) {
386 + MainWP_DB_Client::instance()->update_client_field(
387 + $get_gen_field->field_id,
388 + array(
389 + 'field_desc' => $fie_desc,
390 + )
391 + );
392 + }
393 + MainWP_DB_Client::instance()->update_client_field_value( $get_gen_field->field_id, $fie_value, $client_id ); // add or update general field value for the client.
394 + } else {
395 + $indi_gen_field = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $fie_name, $client_id );
396 + if ( $indi_gen_field ) { // it is individual field.
403 397
404 - } else {
398 + if ( ! empty( $fie_desc ) ) {
399 + MainWP_DB_Client::instance()->update_client_field(
400 + $indi_gen_field->field_id,
401 + array(
402 + 'field_desc' => $fie_desc,
403 + 'client_id' => $client_id,
404 + )
405 + );
406 + }
407 + MainWP_DB_Client::instance()->update_client_field_value( $indi_gen_field->field_id, $fie_value, $client_id ); // add or update individual field value for the client.
408 + }
409 + }
410 + }
411 + }
412 + }
405 413
406 - $params['name'] = isset( $data['name'] ) ? sanitize_text_field( wp_unslash( $data['name'] ) ) : '';
414 + return array(
415 + 'success' => true,
416 + 'client_id' => $client_id,
417 + 'clientid' => $client_id, // Legacy key for backwards compatibility.
418 + );
407 419
408 - if ( empty( $params['name'] ) ) {
409 - return array(
410 - 'error' => esc_html__( 'Client name field is required! Please enter a Client name.', 'mainwp' ),
411 - );
412 - }
420 + } else {
413 421
414 - $params['address_1'] = isset( $data['address_1'] ) ? sanitize_text_field( wp_unslash( $data['address_1'] ) ) : '';
415 - $params['address_2'] = isset( $data['address_2'] ) ? sanitize_text_field( wp_unslash( $data['address_2'] ) ) : '';
416 - $params['city'] = isset( $data['city'] ) ? sanitize_text_field( wp_unslash( $data['city'] ) ) : '';
417 - $params['zip'] = isset( $data['zip'] ) ? sanitize_text_field( wp_unslash( $data['zip'] ) ) : '';
418 - $params['state'] = isset( $data['state'] ) ? sanitize_text_field( wp_unslash( $data['state'] ) ) : '';
419 - $params['country'] = isset( $data['country'] ) ? sanitize_text_field( wp_unslash( $data['country'] ) ) : '';
420 - $params['note'] = isset( $data['note'] ) ? sanitize_text_field( wp_unslash( $data['note'] ) ) : '';
421 - $params['client_email'] = isset( $data['client_email'] ) ? sanitize_text_field( wp_unslash( $data['client_email'] ) ) : '';
422 - $params['client_phone'] = isset( $data['client_phone'] ) ? sanitize_text_field( wp_unslash( $data['client_phone'] ) ) : '';
423 - $params['client_facebook'] = isset( $data['client_facebook'] ) ? sanitize_text_field( wp_unslash( $data['client_facebook'] ) ) : '';
424 - $params['client_twitter'] = isset( $data['client_twitter'] ) ? sanitize_text_field( wp_unslash( $data['client_twitter'] ) ) : '';
425 - $params['client_instagram'] = isset( $data['client_instagram'] ) ? sanitize_text_field( wp_unslash( $data['client_instagram'] ) ) : '';
426 - $params['client_linkedin'] = isset( $data['client_linkedin'] ) ? sanitize_text_field( wp_unslash( $data['client_linkedin'] ) ) : '';
422 + $params['name'] = isset( $data['name'] ) ? sanitize_text_field( wp_unslash( $data['name'] ) ) : '';
427 423
428 - $inserted = MainWP_DB_Client::instance()->update_client( $params );
424 + if ( empty( $params['name'] ) ) {
425 + return array(
426 + 'error' => esc_html__( 'Client name field is required! Please enter a Client name.', 'mainwp' ),
427 + );
428 + }
429 429
430 - if ( empty( $inserted ) ) {
431 - return array(
432 - 'error' => esc_html__( 'Undefined error. Please try again.', 'mainwp' ),
433 - );
434 - }
430 + $params['address_1'] = isset( $data['address_1'] ) ? sanitize_text_field( wp_unslash( $data['address_1'] ) ) : '';
431 + $params['address_2'] = isset( $data['address_2'] ) ? sanitize_text_field( wp_unslash( $data['address_2'] ) ) : '';
432 + $params['city'] = isset( $data['city'] ) ? sanitize_text_field( wp_unslash( $data['city'] ) ) : '';
433 + $params['zip'] = isset( $data['zip'] ) ? sanitize_text_field( wp_unslash( $data['zip'] ) ) : '';
434 + $params['state'] = isset( $data['state'] ) ? sanitize_text_field( wp_unslash( $data['state'] ) ) : '';
435 + $params['country'] = isset( $data['country'] ) ? sanitize_text_field( wp_unslash( $data['country'] ) ) : '';
436 + $params['note'] = isset( $data['note'] ) ? sanitize_text_field( wp_unslash( $data['note'] ) ) : '';
437 + $params['client_email'] = isset( $data['client_email'] ) ? sanitize_text_field( wp_unslash( $data['client_email'] ) ) : '';
438 + $params['client_phone'] = isset( $data['client_phone'] ) ? sanitize_text_field( wp_unslash( $data['client_phone'] ) ) : '';
439 + $params['client_facebook'] = isset( $data['client_facebook'] ) ? sanitize_text_field( wp_unslash( $data['client_facebook'] ) ) : '';
440 + $params['client_twitter'] = isset( $data['client_twitter'] ) ? sanitize_text_field( wp_unslash( $data['client_twitter'] ) ) : '';
441 + $params['client_instagram'] = isset( $data['client_instagram'] ) ? sanitize_text_field( wp_unslash( $data['client_instagram'] ) ) : '';
442 + $params['client_linkedin'] = isset( $data['client_linkedin'] ) ? sanitize_text_field( wp_unslash( $data['client_linkedin'] ) ) : '';
443 + $params['created'] = time();
435 444
436 - $selected_sites = ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) ) : array();
445 + $inserted = MainWP_DB_Client::instance()->update_client( $params, true );
437 446
438 - MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites );
447 + if ( empty( $inserted ) ) {
448 + return array(
449 + 'error' => esc_html__( 'Undefined error. Please try again.', 'mainwp' ),
450 + );
451 + }
439 452
440 - return array(
441 - 'success' => true,
442 - 'clientid' => $inserted->client_id,
443 - );
444 - }
445 - }
453 + $selected_sites = ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) ) : array();
446 454
455 + MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites );
447 456
448 - /**
449 - * Method get_website_client_tokens_data()
450 - *
451 - * Get website client tokens.
452 - *
453 - * @param int $websiteid Website ID.
454 - *
455 - * @return mixed $result Result of tokens.
456 - */
457 - public function get_website_client_tokens_data( $websiteid = false ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
458 - if ( empty( $websiteid ) ) {
459 - return false;
460 - }
461 - $website = MainWP_DB::instance()->get_website_by_id( $websiteid );
462 - if ( empty( $website ) ) {
463 - return false;
464 - }
457 + return array(
458 + 'success' => true,
459 + 'client_id' => $inserted->client_id,
460 + 'clientid' => $inserted->client_id, // Legacy key for backwards compatibility.
461 + );
462 + }
463 + } catch ( \Exception $e ) {
464 + return array( 'error' => $e->getMessage() );
465 + }
466 + }
465 467
466 - $client_tokens = array();
467 468
468 - $client_tokens['client.site.url'] = $website->url;
469 - $client_tokens['client.site.name'] = $website->name;
469 + /**
470 + * Method get_website_client_tokens_data()
471 + *
472 + * Get website client tokens.
473 + *
474 + * @param int $websiteid Website ID.
475 + *
476 + * @return mixed $result Result of tokens.
477 + */
478 + public function get_website_client_tokens_data( $websiteid = false ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
479 + if ( empty( $websiteid ) ) {
480 + return false;
481 + }
482 + $website = MainWP_DB::instance()->get_website_by_id( $websiteid );
483 + if ( empty( $website ) ) {
484 + return false;
485 + }
470 486
471 - // init values.
472 - $default_client_fields = self::get_default_client_fields();
473 - foreach ( $default_client_fields as $tok_name => $field ) {
474 - $client_tokens[ $tok_name ] = ''; // the tokens with empty value will be removed from the report.
475 - }
476 - $contact_fields = self::get_default_contact_fields();
477 - if ( ! empty( $contact_fields ) && is_array( $contact_fields ) ) {
478 - foreach ( $contact_fields as $tok_name => $field ) {
479 - $client_tokens[ $tok_name ] = ''; // the tokens with empty value will be removed from the report.
480 - }
481 - }
487 + $client_tokens = array();
482 488
483 - $custom_tokens_fields = MainWP_DB_Client::instance()->get_client_fields( true, $website->client_id );
484 - if ( ! empty( $custom_tokens_fields ) && is_array( $custom_tokens_fields ) ) {
485 - foreach ( $custom_tokens_fields as $fields ) {
486 - $client_tokens[ $fields->field_name ] = ''; // the tokens with empty value will be removed from the report.
487 - }
488 - }
489 + $client_tokens['client.site.url'] = $website->url;
490 + $client_tokens['client.site.name'] = $website->name;
489 491
490 - if ( empty( $website->client_id ) ) {
491 - return $client_tokens;
492 - }
492 + // init values.
493 + $default_client_fields = static::get_default_client_fields();
494 + foreach ( $default_client_fields as $tok_name => $field ) {
495 + $client_tokens[ $tok_name ] = ''; // the tokens with empty value will be removed from the report.
496 + }
497 + $contact_fields = static::get_default_contact_fields();
498 + if ( ! empty( $contact_fields ) && is_array( $contact_fields ) ) {
499 + foreach ( $contact_fields as $tok_name => $field ) {
500 + $client_tokens[ $tok_name ] = ''; // the tokens with empty value will be removed from the report.
501 + }
502 + }
493 503
494 - $clientid = $website->client_id;
504 + $custom_tokens_fields = MainWP_DB_Client::instance()->get_client_fields( true, $website->client_id );
505 + if ( ! empty( $custom_tokens_fields ) && is_array( $custom_tokens_fields ) ) {
506 + foreach ( $custom_tokens_fields as $fields ) {
507 + $client_tokens[ $fields->field_name ] = ''; // the tokens with empty value will be removed from the report.
508 + }
509 + }
495 510
496 - $client_info = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
511 + if ( empty( $website->client_id ) ) {
512 + return $client_tokens;
513 + }
497 514
498 - if ( empty( $client_info ) ) {
499 - return $client_tokens;
500 - }
515 + $clientid = $website->client_id;
501 516
502 - if ( ! empty( $custom_tokens_fields ) && is_array( $custom_tokens_fields ) ) {
503 - foreach ( $custom_tokens_fields as $fields ) {
504 - $client_tokens[ $fields->field_name ] = $fields->field_value;
505 - }
506 - }
517 + $client_info = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
507 518
508 - foreach ( $default_client_fields as $tok_name => $field ) {
509 - $db_field = $field['db_field'];
510 - if ( property_exists( $client_info, $db_field ) ) {
511 - $client_tokens[ $tok_name ] = $client_info->{$db_field};
512 - }
513 - }
519 + if ( empty( $client_info ) ) {
520 + return $client_tokens;
521 + }
514 522
515 - if ( ! empty( $contact_fields ) && is_array( $contact_fields ) ) {
516 - foreach ( $contact_fields as $tok_name => $field ) {
517 - $db_field = isset( $field['db_field'] ) ? $field['db_field'] : '';
518 - $val = '' !== $db_field && property_exists( $client_info, $db_field ) ? $client_info->{$db_field} : false;
519 - if ( false !== $val ) {
520 - $client_tokens[ $tok_name ] = $val;
521 - }
522 - }
523 - }
524 - $client_tokens = apply_filters( 'mainwp_clients_website_client_tokens', $client_tokens, $websiteid, $clientid );
525 - return $client_tokens;
526 - }
523 + if ( ! empty( $custom_tokens_fields ) && is_array( $custom_tokens_fields ) ) {
524 + foreach ( $custom_tokens_fields as $fields ) {
525 + $client_tokens[ $fields->field_name ] = $fields->field_value;
526 + }
527 + }
527 528
528 - /**
529 - * Method get_client_contact_image()
530 - *
531 - * Get client contact image.
532 - *
533 - * @param array $item client|contact array data.
534 - * @param string $type type of image.
535 - * @param string $what image for what.
536 - */
537 - public static function get_client_contact_image( $item, $type = 'client', $what = 'default' ) {
529 + foreach ( $default_client_fields as $tok_name => $field ) {
530 + $db_field = $field['db_field'];
531 + if ( property_exists( $client_info, $db_field ) ) {
532 + $client_tokens[ $tok_name ] = $client_info->{$db_field};
533 + }
534 + }
538 535
539 - if ( empty( $item ) ) {
540 - return '';
541 - }
536 + if ( ! empty( $contact_fields ) && is_array( $contact_fields ) ) {
537 + foreach ( $contact_fields as $tok_name => $field ) {
538 + $db_field = isset( $field['db_field'] ) ? $field['db_field'] : '';
539 + $val = '' !== $db_field && property_exists( $client_info, $db_field ) ? $client_info->{$db_field} : false;
540 + if ( false !== $val ) {
541 + $client_tokens[ $tok_name ] = $val;
542 + }
543 + }
544 + }
545 + $client_tokens = apply_filters( 'mainwp_clients_website_client_tokens', $client_tokens, $websiteid, $clientid );
546 + return $client_tokens;
547 + }
542 548
543 - $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
549 + /**
550 + * Method get_client_contact_image()
551 + *
552 + * Get client contact image.
553 + *
554 + * @param array $item client|contact array data.
555 + * @param string $type type of image.
556 + * @param string $what image for what.
557 + */
558 + public static function get_client_contact_image( $item, $type = 'client', $what = 'default' ) { // phpcs:ignore -- NOSONAR - complex
544 559
545 - if ( 'client' === $type ) {
546 - $image_path = $item['image'];
547 - $icon_info = $item['selected_icon_info'];
548 - } else {
549 - $image_path = $item['contact_image'];
550 - $icon_info = $item['contact_icon_info'];
551 - }
560 + if ( empty( $item ) ) {
561 + return '';
562 + }
552 563
553 - if ( 'uploaded_icon' === $what ) {
554 - $full_url = '';
555 - if ( ! empty( $image_path ) && file_exists( $dirs[0] . $image_path ) ) {
556 - $full_url = $dirs[1] . $image_path;
557 - }
558 - return $full_url; // return path to uploaded icon.
559 - }
564 + $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
560 565
561 - $img_cls = 'ui mini circular image';
562 - if ( 'card' === $what ) {
563 - $img_cls = 'ui medium circular image';
564 - }
566 + if ( 'client' === $type ) {
567 + $image_path = $item['image'];
568 + $icon_info = $item['selected_icon_info'];
569 + } else {
570 + $image_path = $item['contact_image'];
571 + $icon_info = $item['contact_icon_info'];
572 + }
565 573
566 - $icon_wrapper_attr = ' class="' . $img_cls . '" style="height:auto;display:inline-block;" ';
567 - if ( 'display_edit' === $what ) {
568 - $icon_wrapper_attr = ' id="mainwp_add_edit_client_upload_custom_icon" style="width:32px;height:auto;display:inline-block;" class="' . esc_attr( $img_cls ) . '" ';
569 - if ( 'contact' === $type ) {
570 - $icon_wrapper_attr = ' style="width:32px;height:auto;display:inline-block;" class="mainwp_add_edit_contact_upload_custom_icon ' . esc_attr( $img_cls ) . '" ';
571 - }
572 - }
574 + if ( 'uploaded_icon' === $what ) {
575 + $full_url = '';
576 + if ( ! empty( $image_path ) && file_exists( $dirs[0] . $image_path ) ) {
577 + $full_url = $dirs[1] . $image_path;
578 + }
579 + return $full_url; // return path to uploaded icon.
580 + }
573 581
574 - if ( ! empty( $image_path ) && file_exists( $dirs[0] . $image_path ) ) {
575 - $full_url = $dirs[1] . $image_path;
576 - return '<img ' . $icon_wrapper_attr . ' src="' . esc_attr( $full_url ) . '">';
577 - } elseif ( ! empty( $icon_info ) ) {
578 - return MainWP_Client::get_cust_client_icon( $icon_info, 'display', $what );
579 - }
580 - return '';
581 - }
582 + $img_cls = 'ui avatar image';
583 + if ( 'card' === $what ) {
584 + $img_cls = 'ui medium circular image';
585 + }
582 586
587 + if ( 'small' === $what ) {
588 + $img_cls = 'ui small circular image';
589 + }
583 590
584 - /**
585 - * Method get_client_image_url()
586 - *
587 - * Get client icon URL.
588 - *
589 - * @param string $image_path Client image url path.
590 - *
591 - * @return mixed $full_url Full image URL.
592 - */
593 - public static function get_client_image_url( $image_path ) {
594 - $full_url = '';
595 - if ( ! empty( $image_path ) ) {
596 - if ( false !== stripos( $image_path, 'assets/images/demo/clients/' ) || false !== stripos( $image_path, 'assets/images/demo/contacts/' ) ) {
597 - $full_url = MAINWP_PLUGIN_URL . $image_path;
598 - } else {
599 - $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
600 - if ( file_exists( $dirs[0] . $image_path ) ) {
601 - $full_url = $dirs[1] . $image_path;
602 - } else {
603 - $full_url = '';
604 - }
605 - }
606 - }
607 - return $full_url;
608 - }
591 + $icon_wrapper_attr = ' class="' . $img_cls . '" style="height:auto;display:inline-block;" ';
592 + if ( 'display_edit' === $what ) {
593 + $icon_wrapper_attr = ' id="mainwp_add_edit_client_upload_custom_icon" style="width:28px;height:auto;display:inline-block;" class="' . esc_attr( $img_cls ) . '" ';
594 + if ( 'contact' === $type ) {
595 + $icon_wrapper_attr = ' style="width:28px;height:auto;display:inline-block;" class="mainwp_add_edit_contact_upload_custom_icon ' . esc_attr( $img_cls ) . '" ';
596 + }
597 + }
609 598
610 - /**
611 - * Method show_notice_existed_contact_emails()
612 - */
613 - public static function show_notice_existed_contact_emails() {
614 - $existed_emails = MainWP_Utility::get_flash_message( 'contact_existed_emails' );
615 - if ( ! empty( $existed_emails ) ) {
616 - $existed_emails = esc_html( $existed_emails );
617 - $existed_emails = str_replace( '|', '<br/>', $existed_emails );
618 - ?>
619 - <div class="ui yellow message">
620 - <?php printf( esc_html__( 'Existed contact emails.%sPlease try again.', 'mainwp' ), '<br/>' . $existed_emails . '</br>' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
621 - </div>
622 - <?php
623 - }
624 - }
599 + $img = '';
600 +
601 + if ( ! empty( $image_path ) && file_exists( $dirs[0] . $image_path ) ) {
602 + $full_url = $dirs[1] . $image_path;
603 + $image_name = ! empty( $item['contact_name'] ) ? $item['contact_name'] : '';
604 + $img = '<img ' . $icon_wrapper_attr . ' src="' . esc_attr( $full_url ) . '" alt="' . esc_attr( $image_name ) . '">';
605 + } elseif ( ! empty( $icon_info ) ) {
606 + $img = MainWP_Client::get_cust_client_icon( $icon_info, 'display', $what );
607 + }
608 + return $img;
609 + }
610 +
611 + /**
612 + * Method get_client_avatar()
613 + *
614 + * Returns client avatar image.
615 + *
616 + * @param array $item client|contact array data.
617 + * @param string $type type of image.
618 + */
619 + public static function get_client_avatar( $item, $type = 'client' ) { // phpcs:ignore -- NOSONAR - complex
620 +
621 + if ( empty( $item ) ) {
622 + return '';
623 + }
624 +
625 + $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
626 +
627 + if ( 'client' === $type ) {
628 + $image_path = $item['image'];
629 + $icon_info = $item['selected_icon_info'];
630 + } else {
631 + $image_path = $item['contact_image'];
632 + $icon_info = $item['contact_icon_info'];
633 + }
634 +
635 + $img = '';
636 +
637 + if ( ! empty( $image_path ) && file_exists( $dirs[0] . $image_path ) ) {
638 + $full_url = $dirs[1] . $image_path;
639 + $image_name = ! empty( $item['contact_name'] ) ? $item['contact_name'] : '';
640 + $img = '<img class="ui avatar image" src="' . esc_attr( $full_url ) . '" alt="' . esc_attr( $image_name ) . '">';
641 + } elseif ( ! empty( $icon_info ) ) {
642 + $img = MainWP_Client::get_cust_client_icon( $icon_info, 'display' );
643 + }
644 + return $img;
645 + }
646 +
647 +
648 + /**
649 + * Method get_client_image_url()
650 + *
651 + * Get client icon URL.
652 + *
653 + * @param string $image_path Client image url path.
654 + *
655 + * @return mixed $full_url Full image URL.
656 + */
657 + public static function get_client_image_url( $image_path ) {
658 + $full_url = '';
659 + if ( ! empty( $image_path ) ) {
660 + if ( false !== stripos( $image_path, 'assets/images/demo/clients/' ) || false !== stripos( $image_path, 'assets/images/demo/contacts/' ) ) {
661 + $full_url = MAINWP_PLUGIN_URL . $image_path;
662 + } else {
663 + $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
664 + if ( file_exists( $dirs[0] . $image_path ) ) {
665 + $full_url = $dirs[1] . $image_path;
666 + } else {
667 + $full_url = '';
668 + }
669 + }
670 + }
671 + return $full_url;
672 + }
673 +
674 + /**
675 + * Method show_notice_existed_contact_emails()
676 + */
677 + public static function show_notice_existed_contact_emails() {
678 + $existed_emails = MainWP_Utility::get_flash_message( 'contact_existed_emails' );
679 + if ( ! empty( $existed_emails ) ) {
680 + $existed_emails = esc_html( $existed_emails );
681 + $existed_emails = str_replace( '|', '<br/>', $existed_emails );
682 + ?>
683 + <div class="ui yellow message">
684 + <?php
685 + /* translators: %s: Line break followed by existing email addresses */
686 + printf( esc_html__( 'Existed contact emails.%sPlease try again.', 'mainwp' ), '<br/>' . $existed_emails . '</br>' ); // phpcs:ignore WordPress.Security.EscapeOutput
687 + ?>
688 + </div>
689 + <?php
690 + }
691 + }
625 692 }