-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathDebugInfo.php
More file actions
99 lines (86 loc) · 2.28 KB
/
DebugInfo.php
File metadata and controls
99 lines (86 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* DebugInfo class
*
* @since 1.4.0
* @package Classifai
*/
namespace Classifai\Admin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Adds information useful for debugging to the Site Health screen introduced to core in 5.2.
*
* @since 1.4.0
*/
class DebugInfo {
/**
* Checks whether this class's register method should run.
*
* @since 1.4.0
*
* @return bool
*/
public function can_register(): bool {
return is_admin();
}
/**
* Adds hook callbacks.
*
* @since 1.4.0
*/
public function register() {
add_filter( 'debug_information', [ $this, 'add_classifai_debug_information' ] );
}
/**
* Modifies debug information displayed on the WP Site Health screen.
*
* @see WP_Debug_Data::debug_data
*
* @since 1.4.0
*
* @param array $information The full array of site debug information.
* @return array Filtered debug information.
*/
public function add_classifai_debug_information( array $information ): array {
$plugin_data = get_plugin_data( CLASSIFAI_PLUGIN );
/**
* Filters debug information displayed on the Site Health screen for the ClassifAI plugin.
*
* @since 1.4.0
* @hook classifai_debug_information
* @see {@link https://developer.wordpress.org/reference/hooks/debug_information/|debug_information}
*
* @param array 'debug_info' Array of associative arrays corresponding to lines shown on the Site Health screen. Each array
* requires a `label` and a `value` field. Other accepted fields are `debug` and `private`.
* @param array $information The full array of site debug information.
*
* @return array Filtered array of debug information.
*/
$fields = apply_filters(
'classifai_debug_information',
[
[
'label' => __( 'Version', 'classifai' ),
'value' => $plugin_data['Version'],
],
],
$information
);
if ( ! is_array( $fields ) ) {
$fields = [];
}
$validate_field = function ( $field ) {
if ( ! is_array( $field ) ) {
return false;
}
return isset( $field['label'] ) && isset( $field['value'] );
};
$fields = array_filter( $fields, $validate_field );
$text_domain = $plugin_data['TextDomain'];
$label = $plugin_data['Name'];
$information[ $text_domain ] = compact( 'label', 'fields' );
return $information;
}
}