1414 * @param string $plugin The plugin basename.
1515 */
1616function sqlite_plugin_activation_redirect ( $ plugin ) {
17- if ( plugin_basename ( SQLITE_MAIN_FILE ) === $ plugin ) {
18- if ( wp_safe_redirect ( admin_url ( 'options-general.php?page=sqlite-integration ' ) ) ) {
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 ( admin_url ( 'options-general.php?page=sqlite-integration ' ) ) ) {
25+ exit ;
2126 }
2227}
2328add_action ( 'activated_plugin ' , 'sqlite_plugin_activation_redirect ' );
2429
2530/**
2631 * Check the URL to ensure we're on the plugin page,
2732 * the user has clicked the button to install SQLite,
28- * and the nonce is valid.
33+ * the user has permission to manage the shared drop-in, and the nonce is valid.
2934 * If the above conditions are met, run the sqlite_plugin_copy_db_file() function,
3035 * and redirect to the install screen.
3136 *
@@ -36,25 +41,29 @@ function sqlite_activation() {
3641 if ( isset ( $ current_screen ->base ) && 'settings_page_sqlite-integration ' === $ current_screen ->base ) {
3742 return ;
3843 }
39- if ( isset ( $ _GET ['confirm-install ' ] ) && wp_verify_nonce ( $ _GET ['_wpnonce ' ], 'sqlite-install ' ) ) {
44+ if ( ! isset ( $ _GET ['confirm-install ' ] ) ) {
45+ return ;
46+ }
4047
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 ;
48+ sqlite_plugin_check_manage_capability ();
49+ check_admin_referer ( 'sqlite-install ' );
50+
51+ // Handle upgrading from the performance-lab plugin.
52+ if ( isset ( $ _GET ['upgrade-from-pl ' ] ) ) {
53+ global $ wp_filesystem ;
54+ require_once ABSPATH . '/wp-admin/includes/file.php ' ;
55+ // Delete the previous db.php file.
56+ $ wp_filesystem ->delete ( WP_CONTENT_DIR . '/db.php ' );
57+ // Deactivate the performance-lab SQLite module.
58+ $ pl_option_name = defined ( 'PERFLAB_MODULES_SETTING ' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings ' ;
59+ $ pl_option = get_option ( $ pl_option_name , array () );
60+ unset( $ pl_option ['database/sqlite ' ] );
61+ update_option ( $ pl_option_name , $ pl_option );
5762 }
63+ sqlite_plugin_copy_db_file ();
64+ // WordPress will automatically redirect to the install screen here.
65+ wp_redirect ( admin_url () );
66+ exit ;
5867}
5968add_action ( 'admin_init ' , 'sqlite_activation ' );
6069
0 commit comments