Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55101 new defect (bug)

pre_set_site_transient_update_plugins was called from deactivated plugin while uninstall.

Reported by: okvee's profile okvee Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9
Component: Plugins Keywords: needs-patch
Focuses: Cc:

Description

I have this sample plugin.

<?php
/**
* Plugin Name: A test
*/


class ATest
{
    public function check()
    {
        error_log('pre_set_site_transient_update_plugins hook was called on ' . date('Y-m-d H:i:s'));
    }
    
    public function hooks()
    {
        add_filter ('pre_set_site_transient_update_plugins', [$this, 'check'], 10, 2);
        register_uninstall_hook(__FILE__, [__CLASS__, 'uninstall']);
        add_action('init', [$this, 'init']);
    }
    
    public function init()
    {
        error_log('init hook was called on ' . date('Y-m-d H:i:s'));
    }
    
    public function run()
    {
        $this->hooks();
    }
    
    static public function uninstall()
    {
        error_log('uninstall method was called on ' . date('Y-m-d H:i:s'));
    }
}


$ATest = new \ATest();
$ATest->run();

When I click on delete plugin (the plugin is already deactivated), the pre_set_site_transient_update_plugins hook was called.

To reproduce.

  1. Copy and paste the sample code above to new plugin file. For example test.php
  2. Go to your WordPress > admin > plugins.
  3. Activate this plugin.
  4. Go to your DB, delete _site_transient_update_plugins option name in options table to make sure that this hook will be call next time.
  5. Reload admin plugins page. This hook will be called as normal process because plugin is activated. The error log will be write to wp-contents/debug.log file.
  6. Deactive this plugin.
  7. Maybe try to reload plugins admin page again. The hook will not called from this plugin, no error log were write. This is correct.
  8. Click on delete this plugin.
  9. The error log were write because this hook is called while it is on uninstall process. This is incorrect!! It should not be called.

WordPress 6.0-alpha-52682

Change History (2)

#1 @SergeyBiryukov
2 years ago

  • Component changed from General to Plugins

#2 @azouamauriac
2 years ago

  • Keywords needs-patch added

Hello thanks for the report, i'm able to reproduce it.

Note: See TracTickets for help on using tickets.