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