|
14 | 14 | * @param string $plugin The plugin basename. |
15 | 15 | */ |
16 | 16 | function sqlite_plugin_activation_redirect( $plugin ) { |
17 | | - if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) { |
18 | | - if ( wp_safe_redirect( sqlite_plugin_get_admin_page_url() ) ) { |
19 | | - exit; |
20 | | - } |
| 17 | + if ( |
| 18 | + plugin_basename( SQLITE_MAIN_FILE ) !== $plugin |
| 19 | + || ! current_user_can( sqlite_plugin_get_manage_capability() ) |
| 20 | + ) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + if ( wp_safe_redirect( sqlite_plugin_get_admin_page_url() ) ) { |
| 25 | + exit; |
21 | 26 | } |
22 | 27 | } |
23 | 28 | add_action( 'activated_plugin', 'sqlite_plugin_activation_redirect' ); |
24 | 29 |
|
25 | 30 | /** |
26 | 31 | * Check the URL to ensure we're on the plugin page, |
27 | 32 | * the user has clicked the button to install SQLite, |
28 | | - * and the nonce is valid. |
| 33 | + * the user has permission to manage the database drop-in, and the nonce is valid. |
29 | 34 | * If the above conditions are met, run the sqlite_plugin_copy_db_file() function, |
30 | 35 | * and redirect to the install screen. |
31 | 36 | * |
32 | 37 | * @since 1.0.0 |
33 | 38 | */ |
34 | 39 | function sqlite_activation() { |
35 | | - global $current_screen; |
36 | | - if ( isset( $current_screen->base ) && 'settings_page_sqlite-integration' === $current_screen->base ) { |
| 40 | + if ( |
| 41 | + ! isset( $_GET['page'], $_GET['confirm-install'] ) |
| 42 | + || 'sqlite-integration' !== $_GET['page'] |
| 43 | + ) { |
37 | 44 | return; |
38 | 45 | } |
39 | | - if ( isset( $_GET['confirm-install'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'sqlite-install' ) ) { |
40 | 46 |
|
41 | | - // Handle upgrading from the performance-lab plugin. |
42 | | - if ( isset( $_GET['upgrade-from-pl'] ) ) { |
43 | | - global $wp_filesystem; |
44 | | - require_once ABSPATH . '/wp-admin/includes/file.php'; |
45 | | - // Delete the previous db.php file. |
46 | | - $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' ); |
47 | | - // Deactivate the performance-lab SQLite module. |
48 | | - $pl_option_name = defined( 'PERFLAB_MODULES_SETTING' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings'; |
49 | | - $pl_option = get_option( $pl_option_name, array() ); |
50 | | - unset( $pl_option['database/sqlite'] ); |
51 | | - update_option( $pl_option_name, $pl_option ); |
52 | | - } |
53 | | - sqlite_plugin_copy_db_file(); |
54 | | - // WordPress will automatically redirect to the install screen here. |
55 | | - wp_redirect( admin_url() ); |
56 | | - exit; |
| 47 | + if ( ! current_user_can( sqlite_plugin_get_manage_capability() ) ) { |
| 48 | + wp_die( |
| 49 | + esc_html__( 'Sorry, you are not allowed to install the SQLite database drop-in.', 'sqlite-database-integration' ), |
| 50 | + 403 |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + check_admin_referer( 'sqlite-install' ); |
| 55 | + |
| 56 | + // Handle upgrading from the performance-lab plugin. |
| 57 | + if ( isset( $_GET['upgrade-from-pl'] ) ) { |
| 58 | + global $wp_filesystem; |
| 59 | + require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 60 | + // Delete the previous db.php file. |
| 61 | + $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' ); |
| 62 | + // Deactivate the performance-lab SQLite module. |
| 63 | + $pl_option_name = defined( 'PERFLAB_MODULES_SETTING' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings'; |
| 64 | + $pl_option = get_option( $pl_option_name, array() ); |
| 65 | + unset( $pl_option['database/sqlite'] ); |
| 66 | + update_option( $pl_option_name, $pl_option ); |
57 | 67 | } |
| 68 | + |
| 69 | + sqlite_plugin_copy_db_file(); |
| 70 | + |
| 71 | + // WordPress will automatically redirect to the install screen here. |
| 72 | + wp_redirect( admin_url() ); |
| 73 | + exit; |
58 | 74 | } |
59 | 75 | add_action( 'admin_init', 'sqlite_activation' ); |
60 | 76 |
|
|
0 commit comments