Skip to content

Commit

Permalink
Merge pull request #1128 from WordPress/add/speculation-rules-uninstall
Browse files Browse the repository at this point in the history
Add missing uninstall.php to remove plugin's database option
  • Loading branch information
mukeshpanchal27 authored Apr 12, 2024
2 parents 5973a24 + 2a3fbb9 commit 738fec4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/speculation-rules/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Enables browsers to speculatively prerender or prefetch pages when hovering over links.
* Requires at least: 6.4
* Requires PHP: 7.0
* Version: 1.1.0
* Version: 1.2.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
Expand All @@ -25,7 +25,7 @@
return;
}

define( 'SPECULATION_RULES_VERSION', '1.1.0' );
define( 'SPECULATION_RULES_VERSION', '1.2.0' );

require_once __DIR__ . '/class-plsr-url-pattern-prefixer.php';
require_once __DIR__ . '/helper.php';
Expand Down
6 changes: 5 additions & 1 deletion plugins/speculation-rules/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: wordpressdotorg
Requires at least: 6.4
Tested up to: 6.5
Requires PHP: 7.0
Stable tag: 1.1.0
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, javascript, speculation rules, prerender, prefetch
Expand Down Expand Up @@ -102,6 +102,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C

== Changelog ==

= 1.2.0 =

* Add missing uninstall.php to remove plugin's database option. ([1128](https://github.com/WordPress/performance/pull/1128))

= 1.1.0 =

* Allow excluding URL patterns from prerendering or prefetching specifically. ([1025](https://github.com/WordPress/performance/pull/1025))
Expand Down
41 changes: 41 additions & 0 deletions plugins/speculation-rules/uninstall.php
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' );
}
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' ) );
}
}

0 comments on commit 738fec4

Please sign in to comment.