FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Introduce plugin uninstaller routine by merkys7 · Pull Request #345 · WordPress/performance · GitHub

Introduce plugin uninstaller routine - #345

Merged
felixarntz merged 1 commit into
WordPress:trunkfrom
merkys7:feature/add_uninstall_method
Jun 14, 2022
Merged

Introduce plugin uninstaller routine#345
felixarntz merged 1 commit into
WordPress:trunkfrom
merkys7:feature/add_uninstall_method

Conversation

merkys7 commented Jun 2, 2022
edited by felixarntz
Loading

Copy link
Copy Markdown
Member

Summary

Cleanup wp_options table after plugin uninstall.

Currently, if we uninstall performance-lab plugin - it leaves wp_options entries with AUTOLOAD = yes values.

Relevant technical choices

Introduce Uninstall method referenced at https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure labels Jun 2, 2022
felixarntz added this to the 1.2.0 milestone Jun 2, 2022

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@merkys7 Thanks for the PR! Looks good to me, just a few tiny code suggestions for consistency.

Comment thread uninstall.php Outdated
Comment thread uninstall.php Outdated
Comment thread uninstall.php Outdated
merkys7 force-pushed the feature/add_uninstall_method branch from cf55940 to 4de0054 Compare June 2, 2022 14:49

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Great, thanks!

Comment thread uninstall.php
felixarntz changed the title Introduce Uninstall method Introduce plugin uninstaller Jun 2, 2022

Copy link
Copy Markdown
Member

Do we need to remove options from the Multisite using delete_site_option( 'perflab_modules_settings' ); function as WordPress Beta Tester plugin does here

merkys7 commented Jun 4, 2022

Copy link
Copy Markdown
Member Author

@mukeshpanchal27 I think there is no such need as multi-site options are not being created inside this plugin because update_site_option function is not being called (only update_option)

Copy link
Copy Markdown
Member

@mukeshpanchal27 I think there is no such need as multi-site options are not being created inside this plugin because update_site_option function is not being called (only update_option)

Thanks for the reply.

If we setup multisite then it will save the option in their sub-site DB. Like if you have two sub-site then the plugin option will save the option in the below tables.

wp_options - Main site option table
wp_2_options - 1st Sub-site option table
wp_3_options - 2nd Sub-site option table

I check the update_option in multisite and it doesn't delete the sub-sites options in all wp_SITE-ID_options tables. in my further investigation of multisite, delete_site_option also does not remove the sub-site options.

We should check in multisite for deleting the options from the multisite something like the Google Web Stories plugin did for uninstall method.

I have prepared a code snippet that removes plugin options from the multisite.

 if ( is_multisite() ) {
        $site_ids = get_sites(
            [
                'fields'                 => 'ids',
                'number'                 => '',
                'update_site_cache'      => false,
                'update_site_meta_cache' => false,
            ]
        );

        foreach ( $site_ids as $site_id ) {
            switch_to_blog( $site_id );
            delete_option( 'perflab_modules_settings' );	
        }
        restore_current_blog();
 } else {
        delete_option( 'perflab_modules_settings' );
 }

Additional enhancement for introducing a filter for whether data should be erased when uninstalling the plugin so if anyone doesn't want to delete their plugin setting then use this filter.

/**
* Filters whether data should be erased when uninstalling the plugin.
*
* @since n.e.x.t
*
* @param bool $erase Whether to erase data. Default false.
*/
$erase = (bool) apply_filters( 'perflab_erase_data_on_uninstall', false );

if ( false === $erase ) {
    return;
}

mitogh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM 👍

Copy link
Copy Markdown
Member

Thanks @mukeshpanchal27 for the additional feedback.

We should check in multisite for deleting the options from the multisite something like the Google Web Stories plugin did for uninstall method.

I have prepared a code snippet that removes plugin options from the multisite.

 if ( is_multisite() ) {
        $site_ids = get_sites(
            [
                'fields'                 => 'ids',
                'number'                 => '',
                'update_site_cache'      => false,
                'update_site_meta_cache' => false,
            ]
        );

        foreach ( $site_ids as $site_id ) {
            switch_to_blog( $site_id );
            delete_option( 'perflab_modules_settings' );	
        }
        restore_current_blog();
 } else {
        delete_option( 'perflab_modules_settings' );
 }

That's a fair point. The complexity here with multisite is that there could be a ton of sites on certain environments, and then your code wouldn't be scalable. This is a known problem with WordPress core.

What we could do is set a sensible limit, e.g. set number to 50 or something. Then it would least support the majority of multisites that don't have a ton of sites.

Because of that extra complexity though, I would prefer if we continued thinking and iterating on that in a separate follow-up issue. Would you mind opening one?

Additional enhancement for introducing a filter for whether data should be erased when uninstalling the plugin so if anyone doesn't want to delete their plugin setting then use this filter.

/**
* Filters whether data should be erased when uninstalling the plugin.
*
* @since n.e.x.t
*
* @param bool $erase Whether to erase data. Default false.
*/
$erase = (bool) apply_filters( 'perflab_erase_data_on_uninstall', false );

if ( false === $erase ) {
    return;
}

Normally I would agree with this, but I think for this plugin it's not really necessary since the options are so basic and easy to reconfigure. If we at some point want to allow control on not deleting the data on uninstall, I think we should rather go a separate approach and include a checkbox somewhere so that the site administrator can control that without writing code.

felixarntz merged commit 2088767 into WordPress:trunk Jun 14, 2022

Copy link
Copy Markdown
Member

Thanks again @merkys7 for the PR! Would you be interested in working on a follow-up enhancement to also support multisite in the uninstaller? See especially the above comments #345 (comment) and #345 (comment)

felixarntz changed the title Introduce plugin uninstaller Introduce plugin uninstaller routine Jun 14, 2022

merkys7 commented Jun 15, 2022

Copy link
Copy Markdown
Member Author

Thank you so much! Yes, I will be trying to improve it based on the mentioned comments

This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infrastructure Issues for the overall performance plugin infrastructure [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL