PluginProbe
SQLite Database Integration / 3.0.2
SQLite Database Integration v3.0.2
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
← All changes | admin-page.php +99 -73 2.2.23.0.2 View file →
@@ -1,32 +1,52 @@
1 1 <?php
2 2 /**
3 3 * Functions for the admin page of the plugin.
4 - *
5 - * @since 1.0.0
6 - * @package wp-sqlite-integration
7 4 */
8 5
9 6 /**
10 7 * Add an admin menu page.
11 - *
12 - * @since 1.0.0
13 8 */
14 9 function sqlite_add_admin_menu() {
15 - add_options_page(
10 + $parent_slug = is_multisite() ? 'settings.php' : 'options-general.php';
11 +
12 + add_submenu_page(
13 + $parent_slug,
16 14 __( 'SQLite integration', 'sqlite-database-integration' ),
17 15 __( 'SQLite integration', 'sqlite-database-integration' ),
18 - 'manage_options',
16 + sqlite_plugin_get_manage_capability(),
19 17 'sqlite-integration',
20 18 'sqlite_integration_admin_screen'
21 19 );
22 20 }
23 -add_action( 'admin_menu', 'sqlite_add_admin_menu' );
21 +add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'sqlite_add_admin_menu' );
24 22
25 23 /**
26 24 * The admin page contents.
27 25 */
28 26 function sqlite_integration_admin_screen() {
27 + if ( ! current_user_can( sqlite_plugin_get_manage_capability() ) ) {
28 + wp_die(
29 + esc_html__( 'Sorry, you are not allowed to access the SQLite integration settings.', 'sqlite-database-integration' ),
30 + 403
31 + );
32 + }
33 +
34 + $db_dropin_path = WP_CONTENT_DIR . '/db.php';
35 +
36 + /*
37 + * When an existing "db.php" drop-in is detected, let's check if it's a known
38 + * plugin that we can continue supporting even when we override the drop-in.
39 + */
40 + $override_db_dropin = false;
41 + if ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
42 + // Check for the Query Monitor plugin.
43 + // When "QM_DB" exists, it must have been loaded via the "db.php" file.
44 + if ( class_exists( 'QM_DB', false ) ) {
45 + $override_db_dropin = true;
46 + }
47 + }
48 +
29 49 ?>
30 50 <div class="wrap">
31 51 <h1><?php esc_html_e( 'SQLite integration.', 'sqlite-database-integration' ); ?></h1>
32 52 </div>
@@ -40,75 +60,66 @@
40 60 <?php
41 61 printf(
42 62 /* translators: 1: Admin URL to deactivate the module, 2: db.php drop-in path, */
43 63 __( 'The SQLite drop-in is enabled. To disable it and get back to your previous, MySQL database, you can <a href="%1$s">deactivate the plugin</a>. Alternatively, you can manually delete the %2$s file from your server.', 'sqlite-database-integration' ),
44 - esc_url( admin_url( 'plugins.php' ) ),
64 + esc_url( self_admin_url( 'plugins.php' ) ),
45 65 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
46 66 );
47 67 ?>
48 68 </p>
69 + <?php elseif ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
70 + <div class="notice notice-error">
71 + <p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
72 + </div>
73 + <?php elseif ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! $override_db_dropin ) : ?>
74 + <div class="notice notice-error">
75 + <p>
76 + <?php
77 + printf(
78 + /* translators: %s: db.php drop-in path */
79 + esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
80 + '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
81 + );
82 + ?>
83 + </p>
84 + </div>
85 + <?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
86 + <div class="notice notice-error">
87 + <p>
88 + <?php
89 + printf(
90 + /* translators: %s: db.php drop-in path */
91 + esc_html__( 'The SQLite plugin cannot be activated because the %s directory is not writable.', 'sqlite-database-integration' ),
92 + '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
93 + );
94 + ?>
95 + </p>
96 + </div>
49 97 <?php else : ?>
50 - <?php if ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
51 - <div class="notice notice-error">
52 - <p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
53 - </div>
54 - <?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
55 - <?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
56 - <div class="notice notice-warning">
57 - <p>
58 - <?php
59 - printf(
60 - /* translators: %s: db.php drop-in path */
61 - esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
62 - '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
63 - );
64 - ?>
65 - </p>
66 - </div>
67 - <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>">
68 - <?php
69 - printf(
70 - /* translators: %s: db.php drop-in path */
71 - esc_html__( 'Update %s file', 'sqlite-database-integration' ),
72 - '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
73 - );
74 - ?>
75 - </a>
76 - <?php else : ?>
77 - <div class="notice notice-error">
78 - <p>
79 - <?php
80 - printf(
81 - /* translators: %s: db.php drop-in path */
82 - esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
83 - '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
84 - );
85 - ?>
86 - </p>
87 - </div>
88 - <?php endif; ?>
89 - <?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
90 - <div class="notice notice-error">
91 - <p>
92 - <?php
93 - printf(
94 - /* translators: %s: db.php drop-in path */
95 - esc_html__( 'The SQLite plugin cannot be activated because the %s directory is not writable.', 'sqlite-database-integration' ),
96 - '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
97 - );
98 - ?>
99 - </p>
100 - </div>
101 - <?php else : ?>
102 - <div class="notice notice-success">
103 - <p><?php esc_html_e( 'All checks completed successfully, your site can use an SQLite database. You can proceed with the installation.', 'sqlite-database-integration' ); ?></p>
104 - </div>
105 - <h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
106 - <p><?php esc_html_e( 'This plugin will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the plugin you will get back to your previous MySQL database, with all your previous data intact.', 'sqlite-database-integration' ); ?></p>
107 - <p><?php esc_html_e( 'By clicking the button below, you will be redirected to the WordPress installation screen to setup your new database', 'sqlite-database-integration' ); ?></p>
98 + <div class="notice notice-success">
99 + <p><?php esc_html_e( 'All checks completed successfully, your site can use an SQLite database. You can proceed with the installation.', 'sqlite-database-integration' ); ?></p>
100 + </div>
101 + <h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
102 + <p><?php esc_html_e( 'This plugin will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the plugin you will get back to your previous MySQL database, with all your previous data intact.', 'sqlite-database-integration' ); ?></p>
108 103
109 - <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install' ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>
104 + <?php if ( $override_db_dropin ) : ?>
105 + <p>
106 + <strong>NOTE:</strong>
107 + <?php
108 + printf(
109 + /* translators: %s: db.php drop-in path */
110 + esc_html__( 'We’ve detected an existing database drop-in file at %s, created by the Query Monitor plugin.', 'sqlite-database-integration' ),
111 + '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
112 + );
113 + ?>
114 + <?php esc_html_e( 'To enable SQLite support, this file will need to be replaced.', 'sqlite-database-integration' ); ?>
115 + <?php esc_html_e( 'The Query Monitor plugin will continue to function correctly after the change. You can safely proceed with the installation.', 'sqlite-database-integration' ); ?>
116 + </p>
110 117 <?php endif; ?>
118 +
119 + <p><?php esc_html_e( 'By clicking the button below, you will be redirected to the WordPress installation screen to setup your new database', 'sqlite-database-integration' ); ?></p>
120 +
121 + <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'confirm-install', '1', sqlite_plugin_get_admin_page_url() ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>
111 122 <?php endif; ?>
112 123 </div>
113 124 <?php
114 125 }
@@ -115,20 +126,21 @@
115 126
116 127 /**
117 128 * Adds a link to the admin bar.
118 129 *
119 - * @since n.e.x.t
120 - *
121 130 * @global wpdb $wpdb WordPress database abstraction object.
122 131 *
123 132 * @param WP_Admin_Bar $admin_bar The admin bar object.
124 133 */
125 134 function sqlite_plugin_adminbar_item( $admin_bar ) {
135 + if ( ! current_user_can( sqlite_plugin_get_manage_capability() ) ) {
136 + return;
137 + }
138 +
126 139 global $wpdb;
127 140
128 141 if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
129 - $suffix = defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ? ' (AST)' : '';
130 - $title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . $suffix . '</span>';
142 + $title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . '</span>';
131 143 } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
132 144 $title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
133 145 } else {
134 146 $title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'sqlite-database-integration' ) . '</span>';
@@ -137,10 +149,24 @@
137 149 $args = array(
138 150 'id' => 'sqlite-db-integration',
139 151 'parent' => 'top-secondary',
140 152 'title' => $title,
141 - 'href' => esc_url( admin_url( 'options-general.php?page=sqlite-integration' ) ),
153 + 'href' => esc_url( sqlite_plugin_get_admin_page_url() ),
142 154 'meta' => false,
143 155 );
144 156 $admin_bar->add_node( $args );
145 157 }
146 158 add_action( 'admin_bar_menu', 'sqlite_plugin_adminbar_item', 999 );
159 +
160 +/**
161 + * Get the SQLite integration admin page URL.
162 + *
163 + * @access private
164 + *
165 + * @return string Admin page URL.
166 + */
167 +function sqlite_plugin_get_admin_page_url() {
168 + if ( is_multisite() ) {
169 + return network_admin_url( 'settings.php?page=sqlite-integration' );
170 + }
171 + return admin_url( 'options-general.php?page=sqlite-integration' );
172 +}