Skip to content

Commit 5038c99

Browse files
committed
Refactoring - wp-core
Moved wp-core to a distinct function.
1 parent 6b81c17 commit 5038c99

1 file changed

Lines changed: 159 additions & 158 deletions

File tree

src/wp-admin/includes/class-wp-debug-data.php

Lines changed: 159 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,7 @@ public static function debug_data() {
3939

4040
// Save few function calls.
4141
$upload_dir = wp_upload_dir();
42-
$permalink_structure = get_option( 'permalink_structure' );
43-
$is_ssl = is_ssl();
4442
$is_multisite = is_multisite();
45-
$users_can_register = get_option( 'users_can_register' );
46-
$blog_public = get_option( 'blog_public' );
47-
$default_comment_status = get_option( 'default_comment_status' );
48-
$environment_type = wp_get_environment_type();
49-
$core_version = get_bloginfo( 'version' );
50-
$core_updates = get_core_updates();
51-
$core_update_needed = '';
52-
53-
if ( is_array( $core_updates ) ) {
54-
foreach ( $core_updates as $core => $update ) {
55-
if ( 'upgrade' === $update->response ) {
56-
/* translators: %s: Latest WordPress version number. */
57-
$core_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $update->version );
58-
} else {
59-
$core_update_needed = '';
60-
}
61-
}
62-
}
6343

6444
/*
6545
* Set up the array that holds all debug information.
@@ -75,12 +55,12 @@ public static function debug_data() {
7555
* @ticket 61648
7656
*/
7757
$info = array(
78-
'wp-core' => array(),
58+
'wp-core' => self::get_wp_core(),
7959
'wp-paths-sizes' => array(),
8060
'wp-dropins' => array(),
8161
'wp-active-theme' => array(),
8262
'wp-parent-theme' => array(),
83-
'wp-themes-inactive' => array(),
63+
'wp-themes-inactive' => self::get_wp_themes_inactive(),
8464
'wp-mu-plugins' => self::get_wp_mu_plugins(),
8565
'wp-plugins-active' => array(),
8666
'wp-plugins-inactive' => array(),
@@ -96,74 +76,6 @@ public static function debug_data() {
9676
unset( $info['wp-paths-sizes'] );
9777
}
9878

99-
$info['wp-core'] = array(
100-
'label' => __( 'WordPress' ),
101-
'fields' => array(
102-
'version' => array(
103-
'label' => __( 'Version' ),
104-
'value' => $core_version . $core_update_needed,
105-
'debug' => $core_version,
106-
),
107-
'site_language' => array(
108-
'label' => __( 'Site Language' ),
109-
'value' => get_locale(),
110-
),
111-
'user_language' => array(
112-
'label' => __( 'User Language' ),
113-
'value' => get_user_locale(),
114-
),
115-
'timezone' => array(
116-
'label' => __( 'Timezone' ),
117-
'value' => wp_timezone_string(),
118-
),
119-
'home_url' => array(
120-
'label' => __( 'Home URL' ),
121-
'value' => get_bloginfo( 'url' ),
122-
'private' => true,
123-
),
124-
'site_url' => array(
125-
'label' => __( 'Site URL' ),
126-
'value' => get_bloginfo( 'wpurl' ),
127-
'private' => true,
128-
),
129-
'permalink' => array(
130-
'label' => __( 'Permalink structure' ),
131-
'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set' ),
132-
'debug' => $permalink_structure,
133-
),
134-
'https_status' => array(
135-
'label' => __( 'Is this site using HTTPS?' ),
136-
'value' => $is_ssl ? __( 'Yes' ) : __( 'No' ),
137-
'debug' => $is_ssl,
138-
),
139-
'multisite' => array(
140-
'label' => __( 'Is this a multisite?' ),
141-
'value' => $is_multisite ? __( 'Yes' ) : __( 'No' ),
142-
'debug' => $is_multisite,
143-
),
144-
'user_registration' => array(
145-
'label' => __( 'Can anyone register on this site?' ),
146-
'value' => $users_can_register ? __( 'Yes' ) : __( 'No' ),
147-
'debug' => $users_can_register,
148-
),
149-
'blog_public' => array(
150-
'label' => __( 'Is this site discouraging search engines?' ),
151-
'value' => $blog_public ? __( 'No' ) : __( 'Yes' ),
152-
'debug' => $blog_public,
153-
),
154-
'default_comment_status' => array(
155-
'label' => __( 'Default comment status' ),
156-
'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status' ) : _x( 'Closed', 'comment status' ),
157-
'debug' => $default_comment_status,
158-
),
159-
'environment_type' => array(
160-
'label' => __( 'Environment type' ),
161-
'value' => $environment_type,
162-
'debug' => $environment_type,
163-
),
164-
),
165-
);
166-
16779
if ( ! $is_multisite ) {
16880
$info['wp-paths-sizes'] = array(
16981
/* translators: Filesystem directory paths and storage sizes. */
@@ -193,12 +105,6 @@ public static function debug_data() {
193105
'fields' => array(),
194106
);
195107

196-
$info['wp-themes-inactive'] = array(
197-
'label' => __( 'Inactive Themes' ),
198-
'show_count' => true,
199-
'fields' => array(),
200-
);
201-
202108
$info['wp-plugins-active'] = array(
203109
'label' => __( 'Active Plugins' ),
204110
'show_count' => true,
@@ -216,68 +122,6 @@ public static function debug_data() {
216122
'fields' => array(),
217123
);
218124

219-
// Conditionally add debug information for multisite setups.
220-
if ( is_multisite() ) {
221-
$site_id = get_current_blog_id();
222-
223-
$info['wp-core']['fields']['site_id'] = array(
224-
'label' => __( 'Site ID' ),
225-
'value' => $site_id,
226-
'debug' => $site_id,
227-
);
228-
229-
$network_query = new WP_Network_Query();
230-
$network_ids = $network_query->query(
231-
array(
232-
'fields' => 'ids',
233-
'number' => 100,
234-
'no_found_rows' => false,
235-
)
236-
);
237-
238-
$site_count = 0;
239-
foreach ( $network_ids as $network_id ) {
240-
$site_count += get_blog_count( $network_id );
241-
}
242-
243-
$info['wp-core']['fields']['site_count'] = array(
244-
'label' => __( 'Site count' ),
245-
'value' => $site_count,
246-
);
247-
248-
$info['wp-core']['fields']['network_count'] = array(
249-
'label' => __( 'Network count' ),
250-
'value' => $network_query->found_networks,
251-
);
252-
}
253-
254-
$info['wp-core']['fields']['user_count'] = array(
255-
'label' => __( 'User count' ),
256-
'value' => get_user_count(),
257-
);
258-
259-
// WordPress features requiring processing.
260-
$wp_dotorg = wp_remote_get( 'https://wordpress.org', array( 'timeout' => 10 ) );
261-
262-
if ( ! is_wp_error( $wp_dotorg ) ) {
263-
$info['wp-core']['fields']['dotorg_communication'] = array(
264-
'label' => __( 'Communication with WordPress.org' ),
265-
'value' => __( 'WordPress.org is reachable' ),
266-
'debug' => 'true',
267-
);
268-
} else {
269-
$info['wp-core']['fields']['dotorg_communication'] = array(
270-
'label' => __( 'Communication with WordPress.org' ),
271-
'value' => sprintf(
272-
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
273-
__( 'Unable to reach WordPress.org at %1$s: %2$s' ),
274-
gethostbyname( 'wordpress.org' ),
275-
$wp_dotorg->get_error_message()
276-
),
277-
'debug' => $wp_dotorg->get_error_message(),
278-
);
279-
}
280-
281125
// Remove accordion for Directories and Sizes if in Multisite.
282126
if ( ! $is_multisite ) {
283127
$loading = __( 'Loading…' );
@@ -1024,6 +868,163 @@ public static function debug_data() {
1024868
return $info;
1025869
}
1026870

871+
public static function get_wp_core(): array {
872+
// Save few function calls.
873+
$permalink_structure = get_option( 'permalink_structure' );
874+
$is_ssl = is_ssl();
875+
$is_multisite = is_multisite();
876+
$users_can_register = get_option( 'users_can_register' );
877+
$blog_public = get_option( 'blog_public' );
878+
$default_comment_status = get_option( 'default_comment_status' );
879+
$environment_type = wp_get_environment_type();
880+
$core_version = get_bloginfo( 'version' );
881+
$core_updates = get_core_updates();
882+
$core_update_needed = '';
883+
884+
if ( is_array( $core_updates ) ) {
885+
foreach ( $core_updates as $core => $update ) {
886+
if ( 'upgrade' === $update->response ) {
887+
/* translators: %s: Latest WordPress version number. */
888+
$core_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $update->version );
889+
} else {
890+
$core_update_needed = '';
891+
}
892+
}
893+
}
894+
895+
$fields = array(
896+
'version' => array(
897+
'label' => __( 'Version' ),
898+
'value' => $core_version . $core_update_needed,
899+
'debug' => $core_version,
900+
),
901+
'site_language' => array(
902+
'label' => __( 'Site Language' ),
903+
'value' => get_locale(),
904+
),
905+
'user_language' => array(
906+
'label' => __( 'User Language' ),
907+
'value' => get_user_locale(),
908+
),
909+
'timezone' => array(
910+
'label' => __( 'Timezone' ),
911+
'value' => wp_timezone_string(),
912+
),
913+
'home_url' => array(
914+
'label' => __( 'Home URL' ),
915+
'value' => get_bloginfo( 'url' ),
916+
'private' => true,
917+
),
918+
'site_url' => array(
919+
'label' => __( 'Site URL' ),
920+
'value' => get_bloginfo( 'wpurl' ),
921+
'private' => true,
922+
),
923+
'permalink' => array(
924+
'label' => __( 'Permalink structure' ),
925+
'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set' ),
926+
'debug' => $permalink_structure,
927+
),
928+
'https_status' => array(
929+
'label' => __( 'Is this site using HTTPS?' ),
930+
'value' => $is_ssl ? __( 'Yes' ) : __( 'No' ),
931+
'debug' => $is_ssl,
932+
),
933+
'multisite' => array(
934+
'label' => __( 'Is this a multisite?' ),
935+
'value' => $is_multisite ? __( 'Yes' ) : __( 'No' ),
936+
'debug' => $is_multisite,
937+
),
938+
'user_registration' => array(
939+
'label' => __( 'Can anyone register on this site?' ),
940+
'value' => $users_can_register ? __( 'Yes' ) : __( 'No' ),
941+
'debug' => $users_can_register,
942+
),
943+
'blog_public' => array(
944+
'label' => __( 'Is this site discouraging search engines?' ),
945+
'value' => $blog_public ? __( 'No' ) : __( 'Yes' ),
946+
'debug' => $blog_public,
947+
),
948+
'default_comment_status' => array(
949+
'label' => __( 'Default comment status' ),
950+
'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status' ) : _x( 'Closed', 'comment status' ),
951+
'debug' => $default_comment_status,
952+
),
953+
'environment_type' => array(
954+
'label' => __( 'Environment type' ),
955+
'value' => $environment_type,
956+
'debug' => $environment_type,
957+
),
958+
);
959+
960+
// Conditionally add debug information for multisite setups.
961+
if ( is_multisite() ) {
962+
$site_id = get_current_blog_id();
963+
964+
$fields['site_id'] = array(
965+
'label' => __( 'Site ID' ),
966+
'value' => $site_id,
967+
'debug' => $site_id,
968+
);
969+
970+
$network_query = new WP_Network_Query();
971+
$network_ids = $network_query->query(
972+
array(
973+
'fields' => 'ids',
974+
'number' => 100,
975+
'no_found_rows' => false,
976+
)
977+
);
978+
979+
$site_count = 0;
980+
foreach ( $network_ids as $network_id ) {
981+
$site_count += get_blog_count( $network_id );
982+
}
983+
984+
$fields['site_count'] = array(
985+
'label' => __( 'Site count' ),
986+
'value' => $site_count,
987+
);
988+
989+
$fields['network_count'] = array(
990+
'label' => __( 'Network count' ),
991+
'value' => $network_query->found_networks,
992+
);
993+
}
994+
995+
$fields['user_count'] = array(
996+
'label' => __( 'User count' ),
997+
'value' => get_user_count(),
998+
);
999+
1000+
// WordPress features requiring processing.
1001+
$wp_dotorg = wp_remote_get( 'https://wordpress.org', array( 'timeout' => 10 ) );
1002+
1003+
if ( ! is_wp_error( $wp_dotorg ) ) {
1004+
$fields['dotorg_communication'] = array(
1005+
'label' => __( 'Communication with WordPress.org' ),
1006+
'value' => __( 'WordPress.org is reachable' ),
1007+
'debug' => 'true',
1008+
);
1009+
} else {
1010+
$fields['dotorg_communication'] = array(
1011+
'label' => __( 'Communication with WordPress.org' ),
1012+
'value' => sprintf(
1013+
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
1014+
__( 'Unable to reach WordPress.org at %1$s: %2$s' ),
1015+
gethostbyname( 'wordpress.org' ),
1016+
$wp_dotorg->get_error_message()
1017+
),
1018+
'debug' => $wp_dotorg->get_error_message(),
1019+
);
1020+
}
1021+
1022+
return array(
1023+
'label' => __( 'WordPress' ),
1024+
'fields' => $fields,
1025+
);
1026+
}
1027+
10271028
/**
10281029
* Gets the WordPress server section of the debug data.
10291030
*

0 commit comments

Comments
 (0)