Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WP filesystem setup more robust to prevent potential errors #595

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions modules/database/sqlite/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && ! file_exists( $destination ) ) {
// Init the filesystem to allow copying the file.
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}

// Copy the file, replacing contents as needed.
if ( $wp_filesystem->touch( $destination ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';

// Init the filesystem if needed, then copy the file, replacing contents as needed.
if ( ( $wp_filesystem || WP_Filesystem() ) && $wp_filesystem->touch( $destination ) ) {

// Get the db.copy.php file contents, replace placeholders and write it to the destination.
$file_contents = str_replace(
Expand Down
10 changes: 6 additions & 4 deletions modules/database/sqlite/deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
}

global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();

require_once ABSPATH . '/wp-admin/includes/file.php';

// Init the filesystem if needed, then delete custom drop-in.
if ( $wp_filesystem || WP_Filesystem() ) {
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
}
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );

// Run an action on `shutdown`, to deactivate the option in the MySQL database.
add_action(
Expand Down