| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Client Overview Custom Info Widget |
| 4 |
* |
| 5 |
* Displays the Client Custom Info. |
| 6 |
* |
| 7 |
* @package MainWP/MainWP_Client_Overview_Custom_Info |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class MainWP_Client_Overview_Custom_Info |
| 19 |
* |
| 20 |
* Displays the Client Custom info. |
| 21 |
*/ |
| 22 |
class MainWP_Client_Overview_Custom_Info { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 23 |
|
| 24 |
/** |
| 25 |
* Method get_class_name() |
| 26 |
* |
| 27 |
* @return string __CLASS__ Class name. |
| 28 |
*/ |
| 29 |
public static function get_class_name() { |
| 30 |
return __CLASS__; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Method render() |
| 35 |
* |
| 36 |
* @return mixed render_site_info() |
| 37 |
*/ |
| 38 |
public static function render() { |
| 39 |
$client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 40 |
if ( empty( $client_id ) ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
static::render_addition_info( $client_id ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Render client overview Info. |
| 49 |
* |
| 50 |
* @param object $client_id Client ID. |
| 51 |
*/ |
| 52 |
public static function render_addition_info( $client_id ) { // phpcs:ignore -- NOSONAR - complex. |
| 53 |
|
| 54 |
$client_info = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id, ARRAY_A ); |
| 55 |
$default_client_fields = MainWP_Client_Handler::get_default_client_fields(); |
| 56 |
?> |
| 57 |
<div class="mainwp-widget-header"> |
| 58 |
<h2 class="ui header handle-drag"> |
| 59 |
<?php |
| 60 |
/** |
| 61 |
* Filter: mainwp_clients_overview_info_widget_title |
| 62 |
* |
| 63 |
* Filters the Site info widget title text. |
| 64 |
* |
| 65 |
* @param object $client_info Object containing the child site info. |
| 66 |
* |
| 67 |
* @since 4.1 |
| 68 |
*/ |
| 69 |
echo esc_html( apply_filters( 'mainwp_clients_overview_info_widget_title', esc_html__( 'Additional Client Info', 'mainwp' ), $client_info ) ); |
| 70 |
?> |
| 71 |
<div class="sub header"></div> |
| 72 |
</h2> |
| 73 |
</div> |
| 74 |
<div class="mainwp-widget-client-card mainwp-scrolly-overflow"> |
| 75 |
<?php |
| 76 |
/** |
| 77 |
* Actoin: mainwp_clients_overview_info_widget_top |
| 78 |
* |
| 79 |
* Fires at the top of the Site Info widget on the Individual site overview page. |
| 80 |
* |
| 81 |
* @param object $client_info Object containing the child site info. |
| 82 |
* |
| 83 |
* @since 4.0 |
| 84 |
*/ |
| 85 |
do_action( 'mainwp_clients_overview_info_widget_top', $client_info ); |
| 86 |
?> |
| 87 |
<?php |
| 88 |
if ( $client_info ) { |
| 89 |
$custom_fields = MainWP_DB_Client::instance()->get_client_fields( true, $client_id ); |
| 90 |
?> |
| 91 |
<table class="ui very compact mini table"> |
| 92 |
<tbody> |
| 93 |
<?php |
| 94 |
/** |
| 95 |
* Action: mainwp_clients_overview_info_table_top |
| 96 |
* |
| 97 |
* Fires at the top of the Site Info table in Site Info widget on the Individual site overview page. |
| 98 |
* |
| 99 |
* @param object $client_info Object containing the child site info. |
| 100 |
* |
| 101 |
* @since 4.0 |
| 102 |
*/ |
| 103 |
do_action( 'mainwp_clients_overview_info_table_top', $client_info ); |
| 104 |
?> |
| 105 |
<?php |
| 106 |
|
| 107 |
if ( is_array( $custom_fields ) && ! empty( $custom_fields ) ) { |
| 108 |
foreach ( $custom_fields as $field ) { |
| 109 |
$field_value = ''; |
| 110 |
if ( isset( $default_client_fields[ $field->field_name ] ) ) { |
| 111 |
$db_field = $default_client_fields[ $field->field_name ]['db_field']; |
| 112 |
if ( ! empty( $db_field ) && isset( $client_info[ $db_field ] ) ) { |
| 113 |
$field_value = $client_info[ $db_field ]; |
| 114 |
} |
| 115 |
} else { |
| 116 |
$field_value = $field->field_value; |
| 117 |
} |
| 118 |
|
| 119 |
if ( empty( $field_value ) ) { |
| 120 |
continue; |
| 121 |
} |
| 122 |
?> |
| 123 |
<tr> |
| 124 |
<td><?php echo esc_html( $field->field_name ); ?></td> |
| 125 |
<td><?php echo esc_html( $field_value ); ?></td> |
| 126 |
</tr> |
| 127 |
<?php |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
?> |
| 132 |
<?php |
| 133 |
/** |
| 134 |
* Action: mainwp_clients_overview_info_table_bottom |
| 135 |
* |
| 136 |
* Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page. |
| 137 |
* |
| 138 |
* @param object $client_info Object containing the child site info. |
| 139 |
* |
| 140 |
* @since 4.0 |
| 141 |
*/ |
| 142 |
do_action( 'mainwp_clients_overview_info_table_bottom', $client_info ); |
| 143 |
?> |
| 144 |
</tbody> |
| 145 |
</table> |
| 146 |
<?php |
| 147 |
} else { |
| 148 |
MainWP_UI::render_empty_element_placeholder( __( 'No Custom Client Info yet', 'mainwp' ), __( 'Create custom fields to capture additional information about your clients.', 'mainwp' ), '<em data-emoji=":pencil:" class="medium"></em>' ); |
| 149 |
} |
| 150 |
?> |
| 151 |
<?php |
| 152 |
/** |
| 153 |
* Action: mainwp_clients_overview_info_widget_bottom |
| 154 |
* |
| 155 |
* Fires at the bottom of the Site Info widget on the Individual site overview page. |
| 156 |
* |
| 157 |
* @param object $client_info Object containing the child site info. |
| 158 |
* |
| 159 |
* @since 4.0 |
| 160 |
*/ |
| 161 |
do_action( 'mainwp_clients_overview_info_widget_bottom', $client_info ); |
| 162 |
?> |
| 163 |
</div> |
| 164 |
<div class="ui two columns grid mainwp-widget-footer"> |
| 165 |
<div class="column"><a href="admin.php?page=ClientAddField" title="" class="ui mini basic button"><?php echo esc_html__( 'Add Custom Client Info', 'mainwp' ); ?></a></div> |
| 166 |
<div class="column"></div> |
| 167 |
</div> |
| 168 |
<?php |
| 169 |
} |
| 170 |
} |
| 171 |
|