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

Fix a fatal error when CC is active and the user tries to activate Woo #175

Merged
merged 1 commit into from Jan 13, 2020

Conversation

nylen
Copy link
Contributor

@nylen nylen commented Jan 13, 2020

All Submissions:

Changes proposed in this Pull Request:

Currently when Classic Commerce is active and a user tries to activate WooCommerce, a fatal error occurs because WooCommerce tries to redefine the global function wc() which is already defined by Classic Commerce.

There is existing code in Classic Commerce to try to prevent this situation, but it doesn't work in this case because on the request where a new plugin is activated it runs after other plugins load and even after the init action. Reference:

The fix in this PR is to intercept any request that represents an attempt to activate WooCommerce while Classic Commerce is still active. I wouldn't say this is beautiful but it is the only way I could find to get it working.

This is a follow up to #165 #173 and other related changes.

How to test the changes in this Pull Request:

  1. Deactivate WooCommerce and activate Classic Commerce.
  2. Try to activate WooCommerce while Classic Commerce is still active. Test this both using the "Activate" link for WooCommerce and the "Bulk Actions" forms on the plugins page, since these different UI controls use slightly different code paths to activate a plugin.
  3. You should see a notice indicating that both plugins cannot be active at once. (Before this PR you would see a fatal error instead.)

Screenshot - before:

2020-01-13T19-15-55Z

Screenshot - after:

2020-01-13T19-15-28Z

Changelog entry

Fix a fatal error when CC is active and the user tries to activate Woo

( isset( $_POST['action2'] ) && $_POST['action2'] === 'activate-selected' )
) &&
isset( $_POST['checked'] ) &&
in_array( 'woocommerce/woocommerce.php', (array) wp_unslash( $_POST['checked'] ) )
Copy link
Contributor Author

@nylen nylen Jan 13, 2020

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

image

It's not that ugly :)

That's a nice fix!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the end result is fine, but the internals are definitely not ideal.

I looked for a filter that might work to block a plugin activation but didn't find one. Also, activating a plugin happens fairly late in the load order, but we need to get in before the admin_notices action at least.

Thanks for taking a look!

Copy link
Contributor

@timbocode timbocode left a comment

Choose a reason for hiding this comment

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

Good to merge

@nylen nylen merged commit cedc45d into ClassicPress:develop Jan 13, 2020
@nylen nylen deleted the update/cc-woo-activation-2 branch January 13, 2020 23:44
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.

None yet

2 participants