Automattic / msm-sitemap

Comprehensive sitemaps for your WordPress VIP site. Joint collaboration between Metro.co.uk, WordPress VIP, Alley Interactive, Maker Media, 10up, and others.
73 stars 37 forks source link

Add activation/deactivation functions #138

Open kraftbj opened 6 years ago

kraftbj commented 6 years ago

Fixes #137

This adds a simple call to the rewrite initiation function and flushes rewrites on plugin activation and a second function to run on deactivation.

On deactivation, there is no remove_rewrite_rule function, so we need to manually unset the rules. unset is safe enough that we can run it on all possible rules, not only the ones that were set in the beginning.

sboisvert commented 6 years ago

The functions look good, what benefit is there to them not being inside the class?

kraftbj commented 6 years ago

Technically, it's all the same, but I see it as:

  1. Per coding standards, the class should be in a file by itself named as such.
  2. These functions are not plugin functionality per se, but meta work associated with the plugin.

It would set us up for splitting out the class to a separate file, while keeping these "meta" functions in the base plugin file. While we're aiming at PHP 5.5+ for best performance, we don't enforce that. Splitting out real functionality from the base plugin file would make it easier to use modern syntax without worrying about a hard fatal on upgrading sites that lack the proper PHP. We can use the activation function to check and not allow activation or only require_once the class file if meeting a PHP prereq.

tl;dr: It sets us up for less code churn in the future.

kraftbj commented 6 years ago

On deactivation, need to remove the msm_cron_update_sitemap cron event.

kraftbj commented 6 years ago

Cleaned out cron hooks and options in f92ebda. In both cases, we do not know how long it has been since the plugin was deactivated, so we should expect to need to start from scratch.