Skip to content
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

Use different objects of the CompatCheck class based on plugin basename #87

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

ibndawood
Copy link
Contributor

Changes proposed in this Pull Request:

The CompatCheck class creates instances based on the object. This PR uses the plugin_basename to create more unique objects. Adding this allows the compat checker to be used with multiple plugins.

Detailed test instructions:

  1. Setup Compat Checker in two WooCommerce extension by following the Getting Started section. Let the two extensions be WooCommerce Points and Rewards and WooCommerce Coupon Campaigns.
  2. Run all the tests in the Compat Checker PR from here: Add Compat Checker library for versioning and compatibility checks #79 with both the extensions activated.
  3. Before PR: Only admin notice from one plugin is displayed because the CompatCheck class generates only one object.
  4. After PR: Notices from both the plugins are displayed.

Screenshots

image

Changelog entry

Add - Different instances of CompatCheck based on plugin basename.

@ibndawood ibndawood self-assigned this Oct 24, 2023
@ibndawood ibndawood changed the title Uses different objects of the CompatCheck class based on plugin basename Use different objects of the CompatCheck class based on plugin basename Oct 24, 2023
Copy link
Contributor

@layoutd layoutd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This works well and successfully separates the error messages for different extensions. 👏🏻

One note is that in Points & Rewards, finding exactly where to run the checks was a bit tricky:

  • plugins_loaded action is hooked to woocommerce_points_and_rewards_init on L799
  • However, the subsequent woocommerce_blocks_loaded hook is executed independently of woocommerce_points_and_rewards_init, and initializes the WC_Points_Rewards_Integration class
  • This throws a class not found error because if the compat checker is placed at the start of woocommerce_points_and_rewards_init, the includes() method is never invoked, so the associated files are never included. In the end, I added the Checker after initializing the class:
$GLOBALS['wc_points_rewards'] = WC_Points_Rewards::instance();
if ( ! Checker::instance()->is_compatible( __FILE__, WC_POINTS_REWARDS_VERSION ) ) {
	return;
}

@ibndawood
Copy link
Contributor Author

Thank you, @layoutd, for taking the time to review this PR. Also, excellent observation about the integration in WooCommerce Points and Rewards. I'll compare these findings with the WooCommerce Points and Rewards checker implementation PR.

@ibndawood ibndawood merged commit c1338c4 into trunk Oct 26, 2023
1 check passed
@ibndawood ibndawood deleted the fix/singleton-checks branch October 26, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants