-
Notifications
You must be signed in to change notification settings - Fork 44
/
health-check.php
83 lines (72 loc) · 2.98 KB
/
health-check.php
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
<?php
/**
* Tweaks for the health-check screens.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Filter debug data in site-health screen.
*
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-debug-data.php
* See https://github.com/WordPress/wordpress-develop/pull/3220/files
*
* @param array $info The debug data.
*/
function sqlite_plugin_filter_debug_data( $info ) {
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';
$info['wp-constants']['fields']['DB_ENGINE'] = array(
'label' => 'DB_ENGINE',
'value' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : __( 'Undefined', 'sqlite-database-integration' ) ),
'debug' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : 'undefined' ),
);
$info['wp-database']['fields']['db_engine'] = array(
'label' => __( 'Database type', 'sqlite-database-integration' ),
'value' => 'sqlite' === $db_engine ? 'SQLite' : 'MySQL/MariaDB',
);
if ( 'sqlite' === $db_engine ) {
$info['wp-database']['fields']['database_version'] = array(
'label' => __( 'SQLite version', 'sqlite-database-integration' ),
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null,
);
$info['wp-database']['fields']['database_file'] = array(
'label' => __( 'Database file', 'sqlite-database-integration' ),
'value' => FQDB,
'private' => true,
);
$info['wp-database']['fields']['database_size'] = array(
'label' => __( 'Database size', 'sqlite-database-integration' ),
'value' => size_format( filesize( FQDB ) ),
);
unset( $info['wp-database']['fields']['extension'] );
unset( $info['wp-database']['fields']['server_version'] );
unset( $info['wp-database']['fields']['client_version'] );
unset( $info['wp-database']['fields']['database_host'] );
unset( $info['wp-database']['fields']['database_user'] );
unset( $info['wp-database']['fields']['database_name'] );
unset( $info['wp-database']['fields']['database_charset'] );
unset( $info['wp-database']['fields']['database_collate'] );
unset( $info['wp-database']['fields']['max_allowed_packet'] );
unset( $info['wp-database']['fields']['max_connections'] );
}
return $info;
}
add_filter( 'debug_information', 'sqlite_plugin_filter_debug_data' ); // Filter debug data in site-health screen.
/**
* Filter site_status tests in site-health screen.
*
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-site-health.php
*
* @param array $tests The tests.
* @return array
*/
function sqlite_plugin_filter_site_status_tests( $tests ) {
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined.
}
return $tests;
}
add_filter( 'site_status_tests', 'sqlite_plugin_filter_site_status_tests' );