| 1 |
<?php |
| 2 |
/** |
| 3 |
* Tweaks for the health-check screens. |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Filter debug data in site-health screen. |
| 8 |
* |
| 9 |
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-debug-data.php |
| 10 |
* See https://github.com/WordPress/wordpress-develop/pull/3220/files |
| 11 |
* |
| 12 |
* @param array $info The debug data. |
| 13 |
*/ |
| 14 |
function sqlite_plugin_filter_debug_data( $info ) { |
| 15 |
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql'; |
| 16 |
|
| 17 |
$info['wp-constants']['fields']['DB_ENGINE'] = array( |
| 18 |
'label' => 'DB_ENGINE', |
| 19 |
'value' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : __( 'Undefined', 'sqlite-database-integration' ) ), |
| 20 |
'debug' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : 'undefined' ), |
| 21 |
); |
| 22 |
|
| 23 |
$info['wp-database']['fields']['db_engine'] = array( |
| 24 |
'label' => __( 'Database type', 'sqlite-database-integration' ), |
| 25 |
'value' => 'sqlite' === $db_engine ? 'SQLite' : 'MySQL/MariaDB', |
| 26 |
); |
| 27 |
|
| 28 |
if ( 'sqlite' === $db_engine ) { |
| 29 |
$info['wp-database']['fields']['database_version'] = array( |
| 30 |
'label' => __( 'SQLite version', 'sqlite-database-integration' ), |
| 31 |
'value' => $info['wp-database']['fields']['server_version'] ?? null, |
| 32 |
); |
| 33 |
|
| 34 |
$info['wp-database']['fields']['database_file'] = array( |
| 35 |
'label' => __( 'Database file', 'sqlite-database-integration' ), |
| 36 |
'value' => FQDB, |
| 37 |
'private' => true, |
| 38 |
); |
| 39 |
|
| 40 |
$info['wp-database']['fields']['database_size'] = array( |
| 41 |
'label' => __( 'Database size', 'sqlite-database-integration' ), |
| 42 |
'value' => size_format( filesize( FQDB ) ), |
| 43 |
); |
| 44 |
|
| 45 |
unset( $info['wp-database']['fields']['extension'] ); |
| 46 |
unset( $info['wp-database']['fields']['server_version'] ); |
| 47 |
unset( $info['wp-database']['fields']['client_version'] ); |
| 48 |
unset( $info['wp-database']['fields']['database_host'] ); |
| 49 |
unset( $info['wp-database']['fields']['database_user'] ); |
| 50 |
unset( $info['wp-database']['fields']['database_name'] ); |
| 51 |
unset( $info['wp-database']['fields']['database_charset'] ); |
| 52 |
unset( $info['wp-database']['fields']['database_collate'] ); |
| 53 |
unset( $info['wp-database']['fields']['max_allowed_packet'] ); |
| 54 |
unset( $info['wp-database']['fields']['max_connections'] ); |
| 55 |
} |
| 56 |
|
| 57 |
return $info; |
| 58 |
} |
| 59 |
add_filter( 'debug_information', 'sqlite_plugin_filter_debug_data' ); // Filter debug data in site-health screen. |
| 60 |
|
| 61 |
/** |
| 62 |
* Filter site_status tests in site-health screen. |
| 63 |
* |
| 64 |
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-site-health.php |
| 65 |
* |
| 66 |
* @param array $tests The tests. |
| 67 |
* @return array |
| 68 |
*/ |
| 69 |
function sqlite_plugin_filter_site_status_tests( $tests ) { |
| 70 |
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql'; |
| 71 |
|
| 72 |
if ( 'sqlite' === $db_engine ) { |
| 73 |
unset( $tests['direct']['utf8mb4_support'] ); |
| 74 |
unset( $tests['direct']['sql_server'] ); |
| 75 |
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined. |
| 76 |
} |
| 77 |
|
| 78 |
return $tests; |
| 79 |
} |
| 80 |
add_filter( 'site_status_tests', 'sqlite_plugin_filter_site_status_tests' ); |
| 81 |
|