-
Notifications
You must be signed in to change notification settings - Fork 107
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 #1128 from WordPress/add/speculation-rules-uninstall
Add missing uninstall.php to remove plugin's database option
- Loading branch information
Showing
4 changed files
with
97 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Plugin uninstaller logic. | ||
* | ||
* @package speculation-rules | ||
* @since 1.2.0 | ||
*/ | ||
|
||
// If uninstall.php is not called by WordPress, bail. | ||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
exit; | ||
} | ||
|
||
// For a multisite, delete the option for all sites (however limited to 100 sites to avoid memory limit or timeout problems in large scale networks). | ||
if ( is_multisite() ) { | ||
$site_ids = get_sites( | ||
array( | ||
'fields' => 'ids', | ||
'number' => 100, | ||
'update_site_cache' => false, | ||
'update_site_meta_cache' => false, | ||
) | ||
); | ||
|
||
foreach ( $site_ids as $site_id ) { | ||
switch_to_blog( $site_id ); | ||
plsr_delete_plugin_option(); | ||
restore_current_blog(); | ||
} | ||
} | ||
|
||
plsr_delete_plugin_option(); | ||
|
||
/** | ||
* Delete the current site's option. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
function plsr_delete_plugin_option() { | ||
delete_option( 'plsr_speculation_rules' ); | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/plugins/speculation-rules/speculation-rules-uninstall-tests.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,49 @@ | ||
<?php | ||
/** | ||
* Tests for speculation-rules plugin uninstall.php. | ||
* | ||
* @runInSeparateProcess | ||
* @package speculation-rules | ||
*/ | ||
|
||
class Speculation_Rules_Uninstall_Tests extends WP_UnitTestCase { | ||
|
||
/** | ||
* Runs the routine before setting up all tests. | ||
*/ | ||
public static function set_up_before_class() { | ||
parent::set_up_before_class(); | ||
|
||
// Mock uninstall const. | ||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
define( 'WP_UNINSTALL_PLUGIN', 'Yes' ); | ||
} | ||
} | ||
|
||
/** | ||
* Load uninstall.php. | ||
*/ | ||
private function require_uninstall() { | ||
require __DIR__ . '/../../../plugins/speculation-rules/uninstall.php'; | ||
} | ||
|
||
/** | ||
* Test option deletion. | ||
* | ||
* @covers ::plsr_delete_plugin_option | ||
*/ | ||
public function test_delete_plugin_option() { | ||
unregister_setting( 'reading', 'plsr_speculation_rules' ); | ||
$test_blogname = 'Hello World'; | ||
update_option( 'blogname', $test_blogname ); | ||
update_option( 'plsr_speculation_rules', plsr_get_setting_default() ); | ||
|
||
$this->assertEquals( $test_blogname, $test_blogname ); | ||
$this->assertEquals( plsr_get_setting_default(), get_option( 'plsr_speculation_rules' ) ); | ||
|
||
$this->require_uninstall(); | ||
|
||
$this->assertEquals( $test_blogname, get_option( 'blogname' ) ); | ||
$this->assertFalse( get_option( 'plsr_speculation_rules' ) ); | ||
} | ||
} |