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
sqlite-database-integration / admin-page.php

admin-page.php in SQLite Database Integration 2.2.0, at admin-page.php

147 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions for the admin page of the plugin.
4 *
5 * @since 1.0.0
6 * @package wp-sqlite-integration
7 */
8
9 /**
10 * Add an admin menu page.
11 *
12 * @since 1.0.0
13 */
14 function sqlite_add_admin_menu() {
15 add_options_page(
16 __( 'SQLite integration', 'sqlite-database-integration' ),
17 __( 'SQLite integration', 'sqlite-database-integration' ),
18 'manage_options',
19 'sqlite-integration',
20 'sqlite_integration_admin_screen'
21 );
22 }
23 add_action( 'admin_menu', 'sqlite_add_admin_menu' );
24
25 /**
26 * The admin page contents.
27 */
28 function sqlite_integration_admin_screen() {
29 ?>
30 <div class="wrap">
31 <h1><?php esc_html_e( 'SQLite integration.', 'sqlite-database-integration' ); ?></h1>
32 </div>
33 <!-- Set the wrapper width to 50em, to improve readability. -->
34 <div style="max-width:50em;">
35 <?php if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
36 <div class="notice notice-success">
37 <p><?php esc_html_e( 'SQLite is enabled.', 'sqlite-database-integration' ); ?></p>
38 </div>
39 <p>
40 <?php
41 printf(
42 /* translators: 1: Admin URL to deactivate the module, 2: db.php drop-in path, */
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' ),
44 esc_url( admin_url( 'plugins.php' ) ),
45 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
46 );
47 ?>
48 </p>
49 <?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>
108
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>
110 <?php endif; ?>
111 <?php endif; ?>
112 </div>
113 <?php
114 }
115
116 /**
117 * Adds a link to the admin bar.
118 *
119 * @since n.e.x.t
120 *
121 * @global wpdb $wpdb WordPress database abstraction object.
122 *
123 * @param WP_Admin_Bar $admin_bar The admin bar object.
124 */
125 function sqlite_plugin_adminbar_item( $admin_bar ) {
126 global $wpdb;
127
128 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>';
131 } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
132 $title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
133 } else {
134 $title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'sqlite-database-integration' ) . '</span>';
135 }
136
137 $args = array(
138 'id' => 'sqlite-db-integration',
139 'parent' => 'top-secondary',
140 'title' => $title,
141 'href' => esc_url( admin_url( 'options-general.php?page=sqlite-integration' ) ),
142 'meta' => false,
143 );
144 $admin_bar->add_node( $args );
145 }
146 add_action( 'admin_bar_menu', 'sqlite_plugin_adminbar_item', 999 );
147