Bring structural consistency to the plugin #138
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The purpose of this PR is fourfold:
There aren't any changes to functionality in this PR - just structural changes.
Before
N/A
After
N/A
Technical Details
A bit of background: I accidentally discovered that the
civicrm_instance_loaded
action fires prior toplugins_loaded
even when "late loaded" via theCIVICRM_LATE_LOAD
constant. This led to an unfortunate plugin "missing" thecivicrm_instance_loaded
action by registering its callback after the hook had fired.Given that the load order of other plugins cannot necessarily be guaranteed, plugins should be wary of doing anything other than assembling themselves and registering hook callbacks prior to
plugins_loaded
. It makes sense to me that CiviCRM should follow a similarly standard load procedure - hence this PR.One immediate benefit of these changes is that plugins which are dependent on CiviCRM can reliably hook into
civicrm_instance_loaded
and do what they need to do knowing that CiviCRM is available. No moreif ( function_exists('civi_wp') )
because the action won't fire if this plugin is deactivated or deleted.FWIW, setting the
CIVICRM_LATE_LOAD
constant had no effect becausecivi_wp()
was called in theregister_activation_hook
andregister_deactivation_hook
calls directly below theplugins_loaded
hook registration. Oops, my bad :)The load procedure after this refactoring is therefore as follows:
plugins_loaded
at the end of whichcivicrm_instance_loaded
fires, thus ensuring that all other plugins can receive callbacks from it.init
hook, since nothing of interest to CiviCRM happens before then. Also, "Clean URLs" is going to need to register its rewrite rules at this point.The improvements to encapsulation have been made via:
civicrm_activation
andcivicrm_deactivation
which child classes can listen for.CiviCRM_For_WordPress_Basepage
class and are triggered by the new actions.CiviCRM_For_WordPress_Users
.Comments
The PR also:
civicrm_menu_item_position
filters into one.I have left the three commits separate so that it is easier to see each step.