-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring plugin-initial code structure - part 1: Enhancing the behavior of checking dependency plugin #94
Merged
Conversation
This file contains 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
03ae79d
to
f537309
Compare
…d' hook then, 'init' the plugin if the requirement meets.
f537309
to
86329eb
Compare
This was referenced Jan 18, 2019
Merged
jonrandy
suggested changes
Jan 18, 2019
omise-woocommerce.php
Outdated
@@ -46,7 +54,7 @@ public function __construct() { | |||
public function woocommerce_plugin_notice(){ | |||
?> | |||
<div class="error"> | |||
<p><?php echo __( 'Plugin <strong>deactivated</strong>. The Omise WooCommerce plugin requires <strong>WooCommerce</strong> to be installed and active.', 'omise' ); ?></p> | |||
<p><?php echo __( 'Omise WooCommerce plugin requires <strong>WooCommerce</strong> to be activated.', 'omise' ); ?></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't have removed "The" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jacstn
approved these changes
Jan 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
1. Objective
Omise-WooCommerce has always been coupled with WooCommerce plugin, which the plugin cannot be used as a stand-alone plugin and always require WooCommerce plugin to be activated first.
However, the legacy-codebase itself wasn't really aware of a case where WooCommerce plugin is disabled as much as it should be.
Although we have prevented such cases #78, and #83. But by the current design of the plugin-initial step, it still remains some issue (#90) that could be ceased out by redesigning the initial-step with a proper awareness of WooCommerce plugin.
Related issue(s):
2. Description of change
Part 1
Enhancing the behavior of checking dependency plugin (in this case, WooCommerce).
I have done some researches on which "hook-event" we should hook to validate a dependency and initiate the plugin. And I have found 2 useful events,
plugins_loaded
andinit
.ref: https://codex.wordpress.org/Plugin_API/Action_Reference
hook: plugins_loaded
According to the document:
hook: init
Document says:
Hook
plugins_loaded
is fired beforeinit
.For the first refactoring, I decided to have a dependency-checking at
plugins_loaded
then, send a signal toinit
event if the plugin can be initiated or not.In case of WooCommerce plugin disabled, then the plugin should not initiate anything and stop itself from loading classes & registering stuff.
Here I choose to let plugin successfully activated itself and prevent it from initiating classes and hooks rather than disable the plugin as the current approach because in WordPress, there is no way to deactivate plugin right before the plugin successfully activate.
Meaning that, the actual sequences of the current approach are
Plugin activated
message.Double messages, Omise menu is presented at the admin-sidebar. And because the plugin is successfuly activated, meaning that all of files have been loaded and executed once.

For the refactoring first-part. The plugin will be successfully activated even WooCommerce plugin is disabled but all classes and hooks won't be executed and instead, shows the message that "Omise-WooCommerce requires WooCommerce to be activated" first.

Part 2
See, #95: "Refactoring plugin-initial code structure - part 2: Relocating, renaming functions and method. "
Part 3
See, #96: "Refactoring plugin-initial code structure - part 3: Organizing Omise_Admin class."
3. Quality assurance
🔧 Environments:
✏️ Details:
The main test-case will be separated into 3 cases as follows:
Omise-WooCommerce plugin can be activated, but all functions should be disabled, including no Omise menu at the WordPress admin-sidebar.
4. Impact of the change
No
5. Priority of change
Normal
6. Additional Notes
No