msm-sitemap
msm-sitemap copied to clipboard
Add activation/deactivation functions
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.
The functions look good, what benefit is there to them not being inside the class?
Technically, it's all the same, but I see it as:
- Per coding standards, the class should be in a file by itself named as such.
- 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.
On deactivation, need to remove the msm_cron_update_sitemap
cron event.
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.