xwp / stream

🗄️ Stream plugin for WordPress
https://wordpress.org/plugins/stream/
GNU General Public License v2.0
411 stars 116 forks source link

Plugin conflict with WooCommerce Subscriptions and `woocommerce_available_payment_gateways` filter #1147

Open tyrann0us opened 4 years ago

tyrann0us commented 4 years ago

Bug Report

If the following plugins are active: Stream, WooCommerce and WooCommerce Subscriptions (https://woocommerce.com/products/woocommerce-subscriptions/) and a callback for the woocommerce_available_payment_gateways filter hook uses \WC_Cart->get_cart(), a PHP notice is triggered.

Expected Behavior

No PHP notice(s) should be triggered.

Actual Behavior

A PHP notice is triggered: Notice: Get cart should not be called before the wp_loaded action.

Stack trace (with some comments):

+----------------------------------------------------------------------+-----------------------------------------------------+
|                               Function                               |                      Location                       |
+----------------------------------------------------------------------+-----------------------------------------------------+
| {main}( )                                                            | .../index.php:0                                     |
| require( '/app/public/wp/index.php' )                                | .../index.php:2                                     |
| require( '/app/public/wp/wp-blog-header.php' )                       | .../index.php:17                                    |
| require_once( '/app/public/wp/wp-load.php' )                         | .../wp-blog-header.php:13                           |
| require_once( '/app/public/wp-config.php' )                          | .../wp-load.php:42                                  |
| require_once( '/app/public/wp/wp-settings.php' )                     | .../wp-config.php:213                               |
| do_action( )                                                         | .../wp-settings.php:540                             |
| WP_Hook->do_action( ) // `init`                                      | .../plugin.php:478                                  |
| WP_Hook->apply_filters( )                                            | .../class-wp-hook.php:311                           |
| WP_Stream\Plugin->init( )                                            | .../class-wp-hook.php:287                           |
| WP_Stream\Connectors->__construct( )                                 | .../class-plugin.php:184                            |
| WP_Stream\Connectors->load_connectors( )                             | .../class-connectors.php:52                         |
| WP_Stream\Connector_Woocommerce->register( )                         | .../class-connectors.php:186                        |
| WP_Stream\Connector_Woocommerce->get_woocommerce_settings_fields( )  | .../class-connector-woocommerce.php:67              |
| WC_Settings_Payment_Gateways->get_settings( )                        | .../class-connector-woocommerce.php:735             |
| apply_filters( ) // `woocommerce_payment_gateways_settings`          | .../class-wc-settings-payment-gateways.php:56       |
| WP_Hook->apply_filters( )                                            | .../plugin.php:206                                  |
| WC_Subscriptions_Admin::add_recurring_payment_gateway_information( ) | .../class-wp-hook.php:287                           |
| WC_Subscriptions_Payment_Gateways::one_gateway_supports( )           | .../class-wc-subscriptions-admin.php:1859           |
| WC_Payment_Gateways->get_available_payment_gateways( )               | .../class-wc-subscriptions-payment-gateways.php:115 |
| apply_filters( ) // `woocommerce_available_payment_gateways`         | .../class-wc-payment-gateways.php:160               |
| WP_Hook->apply_filters( )                                            | .../plugin.php:206                                  |
| anyCallbackThatUsesGetCart( ) // <-                                  | .../class-wp-hook.php:287                           |
| WC_Cart->get_cart( )                                                 | .../AnyClass.php:0                           |
| wc_doing_it_wrong( )                                                 | .../class-wc-cart.php:607                           |
| _doing_it_wrong( )                                                   | .../wc-deprecated-functions.php:118                 |
+----------------------------------------------------------------------+-----------------------------------------------------+

Steps to Reproduce the Problem

  1. Install and activate Stream, WooCommerce, WooCommerce Subscriptions
  2. Add a callback for the woocommerce_available_payment_gateways filter hook
  3. Inside the callback, call \WC()->cart->get_cart()

Calling \WC_Cart::get_cart() is a common practice to toggle payment providers based on cart content.

System Information

tyrann0us commented 4 years ago

@kasparsd, any change you take a look at this? Thanks!

tyrann0us commented 2 years ago

@kopepasah, any chance this issue can be fixed? Thanks!

tyrann0us commented 2 years ago

@kasparsd, the bug still occurs with the following system information:

I'd really appreciate it if you could have a look since it's massively spamming our logs. It should be possible to provide you with a copy of "WooCommerce Subscriptions" for testing purposes if need be. Thank you!

tyrann0us commented 2 years ago

Hi @kasparsd, this is my semi-annual friendly reminder to ask if you could take a look at this issue. Thanks 🙂