PluginProbe
Performance Lab / 2.3.0
Performance Lab v2.3.0
trunk 1.0.0 1.0.0-beta.1 1.0.0-beta.2 1.0.0-beta.3 1.0.0-rc.1 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.7.0 2.8.0 All 44 releases
performance-lab / modules / database / sqlite / admin.php

admin.php in Performance Lab 2.3.0, at modules/database/sqlite/admin.php

85 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin hooks used for SQLite Integration.
4 *
5 * @package performance-lab
6 * @since 2.1.0
7 */
8
9 /**
10 * Adds admin notices.
11 *
12 * When the plugin gets merged in wp-core, this is not to be ported.
13 *
14 * @since 1.8.0
15 */
16 function perflab_sqlite_plugin_admin_notice() {
17 // Bail early if the PERFLAB_SQLITE_DB_DROPIN_VERSION is defined.
18 if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) {
19 return;
20 }
21
22 /*
23 * If the PERFLAB_SQLITE_DB_DROPIN_VERSION constant is not defined
24 * but there's a db.php file in the wp-content directory, then the module can't be activated.
25 * The module should not have been activated in the first place
26 * (there's a check in the can-load.php file), but this is a fallback check.
27 */
28 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
29 printf(
30 '<div class="notice notice-error"><p>%s</p></div>',
31 sprintf(
32 /* translators: 1: PERFLAB_SQLITE_DB_DROPIN_VERSION constant, 2: db.php drop-in path */
33 __( 'The SQLite Integration module is active, but the %1$s constant is missing. It appears you already have another %2$s file present on your site. ', 'performance-lab' ),
34 '<code>PERFLAB_SQLITE_DB_DROPIN_VERSION</code>',
35 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
36 )
37 );
38
39 return;
40 }
41
42 // The dropin db.php is missing.
43 printf(
44 '<div class="notice notice-error"><p>%s</p></div>',
45 sprintf(
46 /* translators: 1: db.php drop-in path, 2: Admin URL to deactivate the module */
47 __( 'The SQLite Integration module is active, but the %1$s file is missing. Please <a href="%2$s">deactivate the module</a> and re-activate it to try again.', 'performance-lab' ),
48 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>',
49 esc_url( admin_url( 'options-general.php?page=' . PERFLAB_MODULES_SCREEN ) )
50 )
51 );
52 }
53 add_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); // Add the admin notices.
54
55 /**
56 * Adds a link to the admin bar.
57 *
58 * @since 2.0.0
59 *
60 * @global wpdb $wpdb WordPress database abstraction object.
61 *
62 * @param WP_Admin_Bar $admin_bar The admin bar object.
63 */
64 function perflab_sqlite_plugin_adminbar_item( $admin_bar ) {
65 global $wpdb;
66
67 if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && defined( 'DATABASE_TYPE' ) && 'sqlite' === DATABASE_TYPE ) {
68 $title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'performance-lab' ) . '</span>';
69 } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
70 $title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'performance-lab' ) . '</span>';
71 } else {
72 $title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'performance-lab' ) . '</span>';
73 }
74
75 $args = array(
76 'id' => 'performance-lab-sqlite',
77 'parent' => 'top-secondary',
78 'title' => $title,
79 'href' => esc_url( admin_url( 'options-general.php?page=' . PERFLAB_MODULES_SCREEN ) ),
80 'meta' => false,
81 );
82 $admin_bar->add_node( $args );
83 }
84 add_action( 'admin_bar_menu', 'perflab_sqlite_plugin_adminbar_item', 999 );
85