-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #768 from WordPress/fix/potential-runtime-side-eff…
…ects-real-tables
- Loading branch information
Showing
9 changed files
with
211 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
includes/Checker/Preparations/Use_Custom_DB_Tables_Preparation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Class WordPress\Plugin_Check\Checker\Preparations\Use_Custom_DB_Tables_Preparation | ||
* | ||
* @package plugin-check | ||
*/ | ||
|
||
namespace WordPress\Plugin_Check\Checker\Preparations; | ||
|
||
use Exception; | ||
use WordPress\Plugin_Check\Checker\Preparation; | ||
|
||
/** | ||
* Class for the preparation step to use the custom database tables. | ||
* | ||
* This ensures no side effects on the actual database tables are possible. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
class Use_Custom_DB_Tables_Preparation implements Preparation { | ||
|
||
/** | ||
* Runs this preparation step for the environment and returns a cleanup function. | ||
* | ||
* @since 1.3.0 | ||
* | ||
* @global wpdb $wpdb WordPress database abstraction object. | ||
* @global string $table_prefix The database table prefix. | ||
* | ||
* @return callable Cleanup function to revert any changes made here. | ||
* | ||
* @throws Exception Thrown when preparation fails. | ||
*/ | ||
public function prepare() { | ||
global $wpdb, $table_prefix; | ||
|
||
$old_prefix = $wpdb->set_prefix( $table_prefix . 'pc_' ); | ||
|
||
// Return the cleanup function. | ||
return function () use ( $old_prefix ) { | ||
global $wpdb; | ||
|
||
$wpdb->set_prefix( $old_prefix ); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.