PluginProbe
SQLite Database Integration / 2.1.15
SQLite Database Integration v2.1.15
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.1.15, at admin-page.php

150 lines 6.2 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 ( ! class_exists( 'SQLite3' ) ) : ?>
51 <div class="notice notice-error">
52 <p><?php esc_html_e( 'We detected that the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
53 </div>
54 <?php elseif ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
55 <div class="notice notice-error">
56 <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>
57 </div>
58 <?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
59 <?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
60 <div class="notice notice-warning">
61 <p>
62 <?php
63 printf(
64 /* translators: %s: db.php drop-in path */
65 esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
66 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
67 );
68 ?>
69 </p>
70 </div>
71 <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' ) ); ?>">
72 <?php
73 printf(
74 /* translators: %s: db.php drop-in path */
75 esc_html__( 'Update %s file', 'sqlite-database-integration' ),
76 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
77 );
78 ?>
79 </a>
80 <?php else : ?>
81 <div class="notice notice-error">
82 <p>
83 <?php
84 printf(
85 /* translators: %s: db.php drop-in path */
86 esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
87 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
88 );
89 ?>
90 </p>
91 </div>
92 <?php endif; ?>
93 <?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
94 <div class="notice notice-error">
95 <p>
96 <?php
97 printf(
98 /* translators: %s: db.php drop-in path */
99 esc_html__( 'The SQLite plugin cannot be activated because the %s directory is not writable.', 'sqlite-database-integration' ),
100 '<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
101 );
102 ?>
103 </p>
104 </div>
105 <?php else : ?>
106 <div class="notice notice-success">
107 <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>
108 </div>
109 <h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
110 <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>
111 <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>
112
113 <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>
114 <?php endif; ?>
115 <?php endif; ?>
116 </div>
117 <?php
118 }
119
120 /**
121 * Adds a link to the admin bar.
122 *
123 * @since n.e.x.t
124 *
125 * @global wpdb $wpdb WordPress database abstraction object.
126 *
127 * @param WP_Admin_Bar $admin_bar The admin bar object.
128 */
129 function sqlite_plugin_adminbar_item( $admin_bar ) {
130 global $wpdb;
131
132 if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
133 $title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . '</span>';
134 } elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
135 $title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
136 } else {
137 $title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'sqlite-database-integration' ) . '</span>';
138 }
139
140 $args = array(
141 'id' => 'sqlite-db-integration',
142 'parent' => 'top-secondary',
143 'title' => $title,
144 'href' => esc_url( admin_url( 'options-general.php?page=sqlite-integration' ) ),
145 'meta' => false,
146 );
147 $admin_bar->add_node( $args );
148 }
149 add_action( 'admin_bar_menu', 'sqlite_plugin_adminbar_item', 999 );
150