| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions to add admin notices if necessary. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* @package wp-sqlite-integration |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Add admin notices. |
| 11 |
* |
| 12 |
* When the plugin gets merged in wp-core, this is not to be ported. |
| 13 |
*/ |
| 14 |
function sqlite_plugin_admin_notice() { |
| 15 |
|
| 16 |
// Don't print notices in the plugin's admin screen. |
| 17 |
global $current_screen; |
| 18 |
if ( isset( $current_screen->base ) && 'settings_page_sqlite-integration' === $current_screen->base ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
// If PDO SQLite is not loaded, bail early. |
| 23 |
if ( ! extension_loaded( 'pdo_sqlite' ) ) { |
| 24 |
printf( |
| 25 |
'<div class="notice notice-error"><p>%s</p></div>', |
| 26 |
esc_html__( 'The SQLite Integration plugin is active, but the PDO SQLite extension is missing from your server. Please make sure that PDO SQLite is enabled in your PHP installation.', 'sqlite-database-integration' ) |
| 27 |
); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
/* |
| 32 |
* If the SQLITE_DB_DROPIN_VERSION constant is not defined |
| 33 |
* but there's a db.php file in the wp-content directory, then the module can't be activated. |
| 34 |
* The module should not have been activated in the first place |
| 35 |
* (there's a check in the can-load.php file), but this is a fallback check. |
| 36 |
*/ |
| 37 |
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) { |
| 38 |
printf( |
| 39 |
'<div class="notice notice-error"><p>%s</p></div>', |
| 40 |
sprintf( |
| 41 |
/* translators: 1: SQLITE_DB_DROPIN_VERSION constant, 2: db.php drop-in path */ |
| 42 |
__( '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. ', 'sqlite-database-integration' ), |
| 43 |
'<code>SQLITE_DB_DROPIN_VERSION</code>', |
| 44 |
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>' |
| 45 |
) |
| 46 |
); |
| 47 |
|
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! wp_is_writable( WP_CONTENT_DIR ) ) { |
| 56 |
printf( |
| 57 |
'<div class="notice notice-error"><p>%s</p></div>', |
| 58 |
esc_html__( 'The SQLite Integration plugin is active, but the wp-content/db.php file is missing and the wp-content directory is not writable. Please ensure the wp-content folder is writable, then deactivate the plugin and try again.', 'sqlite-database-integration' ) |
| 59 |
); |
| 60 |
return; |
| 61 |
} |
| 62 |
// The dropin db.php is missing. |
| 63 |
printf( |
| 64 |
'<div class="notice notice-error"><p>%s</p></div>', |
| 65 |
sprintf( |
| 66 |
/* translators: 1: db.php drop-in path, 2: Admin URL to deactivate the module */ |
| 67 |
__( 'The SQLite Integration plugin is active, but the %1$s file is missing. Please <a href="%2$s">deactivate the plugin</a> and re-activate it to try again.', 'sqlite-database-integration' ), |
| 68 |
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>', |
| 69 |
esc_url( admin_url( 'plugins.php' ) ) |
| 70 |
) |
| 71 |
); |
| 72 |
} |
| 73 |
add_action( 'admin_notices', 'sqlite_plugin_admin_notice' ); // Add the admin notices. |
| 74 |
|
| 75 |
// Remove the PL-plugin admin notices for SQLite. |
| 76 |
remove_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' ); |
| 77 |
|