msm-sitemap icon indicating copy to clipboard operation
msm-sitemap copied to clipboard

Add activation/deactivation functions

Open kraftbj opened this issue 6 years ago • 4 comments

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.

kraftbj avatar May 04 '18 04:05 kraftbj

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

sboisvert avatar May 04 '18 15:05 sboisvert

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 avatar May 04 '18 19:05 kraftbj

On deactivation, need to remove the msm_cron_update_sitemap cron event.

kraftbj avatar May 05 '18 04:05 kraftbj

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.

kraftbj avatar May 08 '18 05:05 kraftbj