From 81de8b066d496d2e6f034bf53e9114c38636f5e7 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Dec 2022 14:53:55 +0200 Subject: [PATCH 1/5] Add an indicator in the adminbar to show when using SQLite --- modules/database/sqlite/load.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/database/sqlite/load.php b/modules/database/sqlite/load.php index 40b452d122..7984a8d7b1 100644 --- a/modules/database/sqlite/load.php +++ b/modules/database/sqlite/load.php @@ -58,3 +58,21 @@ function perflab_sqlite_plugin_admin_notice() { ); } add_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); // Add the admin notices. + +/** + * Add a link to the admin bar. + * + * @param WP_Admin_Bar $admin_bar The admin bar object. + */ +function perflab_sqlite_plugin_adminbar_item( $admin_bar ) { + $args = array( + 'id' => 'performance-lab-sqlite', + 'parent' => 'top-secondary', + /* translators: %s: SQLite icon. */ + 'title' => '' . __( 'SQLite activated', 'performance-lab' ) . '', + 'href' => esc_url( admin_url( 'options-general.php?page=' . PERFLAB_MODULES_SCREEN ) ), + 'meta' => false, + ); + $admin_bar->add_node( $args ); +} +add_action( 'admin_bar_menu', 'perflab_sqlite_plugin_adminbar_item', 999 ); From f9a6f4229698f0593cb423381fcee3806debe21f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Dec 2022 14:56:06 +0200 Subject: [PATCH 2/5] bail early when not using sqlite --- modules/database/sqlite/load.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/database/sqlite/load.php b/modules/database/sqlite/load.php index 7984a8d7b1..840bfb1e82 100644 --- a/modules/database/sqlite/load.php +++ b/modules/database/sqlite/load.php @@ -65,6 +65,9 @@ function perflab_sqlite_plugin_admin_notice() { * @param WP_Admin_Bar $admin_bar The admin bar object. */ function perflab_sqlite_plugin_adminbar_item( $admin_bar ) { + if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) { + return; + } $args = array( 'id' => 'performance-lab-sqlite', 'parent' => 'top-secondary', From 5dfa9c2eecc94a543ddd4f68e1be35b8e484e778 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 15 Feb 2023 14:44:04 +0200 Subject: [PATCH 3/5] Show whether the db is SQLite or MySQL --- modules/database/sqlite/load.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/database/sqlite/load.php b/modules/database/sqlite/load.php index 840bfb1e82..6e32cbd740 100644 --- a/modules/database/sqlite/load.php +++ b/modules/database/sqlite/load.php @@ -65,14 +65,13 @@ function perflab_sqlite_plugin_admin_notice() { * @param WP_Admin_Bar $admin_bar The admin bar object. */ function perflab_sqlite_plugin_adminbar_item( $admin_bar ) { - if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) { - return; - } $args = array( 'id' => 'performance-lab-sqlite', 'parent' => 'top-secondary', /* translators: %s: SQLite icon. */ - 'title' => '' . __( 'SQLite activated', 'performance-lab' ) . '', + 'title' => defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE + ? '' . __( 'Database: SQLite', 'performance-lab' ) . '' + : '' . __( 'Database: MySQL', 'performance-lab' ) . '', 'href' => esc_url( admin_url( 'options-general.php?page=' . PERFLAB_MODULES_SCREEN ) ), 'meta' => false, ); From 6bf932872abec6a79a7a535aff8c99e63ea15a36 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 15 Feb 2023 09:54:53 -0800 Subject: [PATCH 4/5] Provide more accurate info about MariaDB vs MySQL, enhance doc block. --- modules/database/sqlite/load.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/database/sqlite/load.php b/modules/database/sqlite/load.php index 6e32cbd740..72f4feef36 100644 --- a/modules/database/sqlite/load.php +++ b/modules/database/sqlite/load.php @@ -14,7 +14,7 @@ require_once __DIR__ . '/site-health.php'; /** - * Add admin notices. + * Adds admin notices. * * When the plugin gets merged in wp-core, this is not to be ported. * @@ -60,18 +60,32 @@ function perflab_sqlite_plugin_admin_notice() { add_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); // Add the admin notices. /** - * Add a link to the admin bar. + * Adds a link to the admin bar. + * + * @since n.e.x.t + * + * @global wpdb $wpdb WordPress database abstraction object. * * @param WP_Admin_Bar $admin_bar The admin bar object. */ function perflab_sqlite_plugin_adminbar_item( $admin_bar ) { + global $wpdb; + + if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ) { + $title = '' . __( 'Database: SQLite', 'performance-lab' ) . ''; + } else { + $db_info = $wpdb->db_server_info(); + if ( stripos( $db_info, 'maria' ) !== false ) { + $title = '' . __( 'Database: MariaDB', 'performance-lab' ) . ''; + } else { + $title = '' . __( 'Database: MySQL', 'performance-lab' ) . ''; + } + } + $args = array( 'id' => 'performance-lab-sqlite', 'parent' => 'top-secondary', - /* translators: %s: SQLite icon. */ - 'title' => defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE - ? '' . __( 'Database: SQLite', 'performance-lab' ) . '' - : '' . __( 'Database: MySQL', 'performance-lab' ) . '', + 'title' => $title, 'href' => esc_url( admin_url( 'options-general.php?page=' . PERFLAB_MODULES_SCREEN ) ), 'meta' => false, ); From 05ae84155f8a0c345f720e85ba0674b271d63ff6 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 15 Feb 2023 09:58:15 -0800 Subject: [PATCH 5/5] Further simplify code for readability. --- modules/database/sqlite/load.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/database/sqlite/load.php b/modules/database/sqlite/load.php index 72f4feef36..0d9297eaed 100644 --- a/modules/database/sqlite/load.php +++ b/modules/database/sqlite/load.php @@ -73,13 +73,10 @@ function perflab_sqlite_plugin_adminbar_item( $admin_bar ) { if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ) { $title = '' . __( 'Database: SQLite', 'performance-lab' ) . ''; + } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) { + $title = '' . __( 'Database: MariaDB', 'performance-lab' ) . ''; } else { - $db_info = $wpdb->db_server_info(); - if ( stripos( $db_info, 'maria' ) !== false ) { - $title = '' . __( 'Database: MariaDB', 'performance-lab' ) . ''; - } else { - $title = '' . __( 'Database: MySQL', 'performance-lab' ) . ''; - } + $title = '' . __( 'Database: MySQL', 'performance-lab' ) . ''; } $args = array(