PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
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 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-client-handler.php +73 -15 5.3trunk 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
@@ -49,11 +54,12 @@
49 54 public static function get_default_client_fields() {
50 55
51 56 return array(
52 57 'client.name' => array(
53 - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ),
58 + 'title' => esc_html__( 'Client Name', 'mainwp' ),
54 59 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
55 60 'db_field' => 'name',
61 + 'required' => true,
56 62 ),
57 63 'client.email' => array(
58 64 'title' => esc_html__( 'Client email', 'mainwp' ),
59 65 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
@@ -126,9 +132,8 @@
126 132 ),
127 133 'client.created' => array(
128 134 'title' => esc_html__( 'Added on', 'mainwp' ),
129 135 '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 136 'db_field' => 'created',
132 137 ),
133 138 );
134 139 }
@@ -141,21 +146,24 @@
141 146 public static function get_mini_default_client_fields() {
142 147
143 148 return array(
144 149 'client.name' => array(
145 - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ),
150 + 'title' => esc_html__( 'Client Name', 'mainwp' ),
146 151 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ),
147 152 'db_field' => 'name',
153 + 'required' => true,
148 154 ),
149 155 'client.email' => array(
150 156 'title' => esc_html__( 'Client email', 'mainwp' ),
151 157 'desc' => esc_html__( 'Displays the client email', 'mainwp' ),
152 158 'db_field' => 'client_email',
159 + 'required' => false,
153 160 ),
154 161 'client.phone' => array(
155 162 'title' => esc_html__( 'Client phone', 'mainwp' ),
156 163 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ),
157 164 'db_field' => 'client_phone',
165 + 'required' => false,
158 166 ),
159 167 );
160 168 }
161 169
@@ -167,16 +175,18 @@
167 175 */
168 176 public static function get_default_contact_fields() {
169 177 return array(
170 178 'client.contact.name' => array(
171 - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ),
179 + 'title' => esc_html__( 'Contact name', 'mainwp' ),
172 180 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
173 181 'db_field' => 'contact_name',
182 + 'required' => true,
174 183 ),
175 184 'contact.email' => array(
176 - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ),
185 + 'title' => esc_html__( 'Contact email', 'mainwp' ),
177 186 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
178 187 'db_field' => 'contact_email',
188 + 'required' => true,
179 189 ),
180 190 'contact.role' => array(
181 191 'title' => esc_html__( 'Contact role', 'mainwp' ),
182 192 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
@@ -217,21 +227,24 @@
217 227 */
218 228 public static function get_mini_default_contact_fields() {
219 229 return array(
220 230 'client.contact.name' => array(
221 - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ),
231 + 'title' => esc_html__( 'Contact name', 'mainwp' ),
222 232 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ),
223 233 'db_field' => 'contact_name',
234 + 'required' => true,
224 235 ),
225 236 'contact.email' => array(
226 - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ),
237 + 'title' => esc_html__( 'Contact email', 'mainwp' ),
227 238 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ),
228 239 'db_field' => 'contact_email',
240 + 'required' => true,
229 241 ),
230 242 'contact.role' => array(
231 243 'title' => esc_html__( 'Contact role', 'mainwp' ),
232 244 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ),
233 245 'db_field' => 'contact_role',
246 + 'required' => false,
234 247 ),
235 248 );
236 249 }
237 250
@@ -398,10 +411,11 @@
398 411 }
399 412 }
400 413
401 414 return array(
402 - 'success' => true,
403 - 'clientid' => $client_id,
415 + 'success' => true,
416 + 'client_id' => $client_id,
417 + 'clientid' => $client_id, // Legacy key for backwards compatibility.
404 418 );
405 419
406 420 } else {
407 421
@@ -440,10 +454,11 @@
440 454
441 455 MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites );
442 456
443 457 return array(
444 - 'success' => true,
445 - 'clientid' => $inserted->client_id,
458 + 'success' => true,
459 + 'client_id' => $inserted->client_id,
460 + 'clientid' => $inserted->client_id, // Legacy key for backwards compatibility.
446 461 );
447 462 }
448 463 } catch ( \Exception $e ) {
449 464 return array( 'error' => $e->getMessage() );
@@ -563,18 +578,22 @@
563 578 }
564 579 return $full_url; // return path to uploaded icon.
565 580 }
566 581
567 - $img_cls = 'ui mini circular image';
582 + $img_cls = 'ui avatar image';
568 583 if ( 'card' === $what ) {
569 584 $img_cls = 'ui medium circular image';
570 585 }
571 586
587 + if ( 'small' === $what ) {
588 + $img_cls = 'ui small circular image';
589 + }
590 +
572 591 $icon_wrapper_attr = ' class="' . $img_cls . '" style="height:auto;display:inline-block;" ';
573 592 if ( 'display_edit' === $what ) {
574 - $icon_wrapper_attr = ' id="mainwp_add_edit_client_upload_custom_icon" style="width:32px;height:auto;display:inline-block;" class="' . esc_attr( $img_cls ) . '" ';
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 ) . '" ';
575 594 if ( 'contact' === $type ) {
576 - $icon_wrapper_attr = ' style="width:32px;height:auto;display:inline-block;" class="mainwp_add_edit_contact_upload_custom_icon ' . esc_attr( $img_cls ) . '" ';
595 + $icon_wrapper_attr = ' style="width:28px;height:auto;display:inline-block;" class="mainwp_add_edit_contact_upload_custom_icon ' . esc_attr( $img_cls ) . '" ';
577 596 }
578 597 }
579 598
580 599 $img = '';
@@ -588,9 +607,45 @@
588 607 }
589 608 return $img;
590 609 }
591 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
592 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 +
593 648 /**
594 649 * Method get_client_image_url()
595 650 *
596 651 * Get client icon URL.
@@ -625,9 +680,12 @@
625 680 $existed_emails = esc_html( $existed_emails );
626 681 $existed_emails = str_replace( '|', '<br/>', $existed_emails );
627 682 ?>
628 683 <div class="ui yellow message">
629 - <?php printf( esc_html__( 'Existed contact emails.%sPlease try again.', 'mainwp' ), '<br/>' . $existed_emails . '</br>' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
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 + ?>
630 688 </div>
631 689 <?php
632 690 }
633 691 }