PluginProbe
SQLite Database Integration / 2.2.0
SQLite Database Integration v2.2.0
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 +73 -99 trunk2.2.0 View file →
@@ -1,52 +1,32 @@
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
4 7 */
5 8
6 9 /**
7 10 * Add an admin menu page.
11 + *
12 + * @since 1.0.0
8 13 */
9 14 function sqlite_add_admin_menu() {
10 - $parent_slug = is_multisite() ? 'settings.php' : 'options-general.php';
11 -
12 - add_submenu_page(
13 - $parent_slug,
15 + add_options_page(
14 16 __( 'SQLite integration', 'sqlite-database-integration' ),
15 17 __( 'SQLite integration', 'sqlite-database-integration' ),
16 - sqlite_plugin_get_manage_capability(),
18 + 'manage_options',
17 19 'sqlite-integration',
18 20 'sqlite_integration_admin_screen'
19 21 );
20 22 }
21 -add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'sqlite_add_admin_menu' );
23 +add_action( 'admin_menu', 'sqlite_add_admin_menu' );
22 24
23 25 /**
24 26 * The admin page contents.
25 27 */
26 28 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 -
49 29 ?>
50 30 <div class="wrap">
51 31 <h1><?php esc_html_e( 'SQLite integration.', 'sqlite-database-integration' ); ?></h1>
52 32 </div>
@@ -60,66 +40,75 @@
60 40 <?php
61 41 printf(
62 42 /* translators: 1: Admin URL to deactivate the module, 2: db.php drop-in path, */
63 43 __( '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' ),
64 - esc_url( self_admin_url( 'plugins.php' ) ),
44 + esc_url( admin_url( 'plugins.php' ) ),
65 45 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
66 46 );
67 47 ?>
68 48 </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>
97 49 <?php else : ?>
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>
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>
103 108
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>
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>
117 110 <?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>
122 111 <?php endif; ?>
123 112 </div>
124 113 <?php
125 114 }
@@ -126,21 +115,20 @@
126 115
127 116 /**
128 117 * Adds a link to the admin bar.
129 118 *
119 + * @since n.e.x.t
120 + *
130 121 * @global wpdb $wpdb WordPress database abstraction object.
131 122 *
132 123 * @param WP_Admin_Bar $admin_bar The admin bar object.
133 124 */
134 125 function sqlite_plugin_adminbar_item( $admin_bar ) {
135 - if ( ! current_user_can( sqlite_plugin_get_manage_capability() ) ) {
136 - return;
137 - }
138 -
139 126 global $wpdb;
140 127
141 128 if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
142 - $title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . '</span>';
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>';
143 131 } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
144 132 $title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
145 133 } else {
146 134 $title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'sqlite-database-integration' ) . '</span>';
@@ -149,24 +137,10 @@
149 137 $args = array(
150 138 'id' => 'sqlite-db-integration',
151 139 'parent' => 'top-secondary',
152 140 'title' => $title,
153 - 'href' => esc_url( sqlite_plugin_get_admin_page_url() ),
141 + 'href' => esc_url( admin_url( 'options-general.php?page=sqlite-integration' ) ),
154 142 'meta' => false,
155 143 );
156 144 $admin_bar->add_node( $args );
157 145 }
158 146 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 -}