Jetpack: Fatal Error in WooCommerce product editor with Gutenberg enabled

Created on 27 Nov 2018  路  35Comments  路  Source: Automattic/jetpack


This issue apperared after installing Jetpack 6.8, before it was working fine.

Steps to reproduce the issue

  1. Enable Gutenberg editor on WooCommerce products
  2. Go to WooCommerce Products page in wp-admin
  3. Create/Edit product with the Gutenberg Editor
  4. See the fatal error specified below

What I expected


The page sould load with the Gutenberg editor

What happened instead

The page responds with error 500:
Fatal error: Uncaught Error: Call to a member function current_user_can_access_publicize_data() on null in [..]/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php:118

Gutenberg Publicize [Pri] High [Type] Bug

Most helpful comment

@phamvietloi Could you try to remove Publicize support for WooCommerce products, like so?

function jeherve_rm_jetpack_publicize_woocommerce() {
    remove_post_type_support( 'product', 'publicize' );
}

add_action( 'init', 'jeherve_rm_jetpack_publicize_woocommerce' );

You can follow the instructions here to add this code snippet to your site.

Another option would be to enable the Publicize module under Jetpack > Settings > Sharing, as my colleague suggested above.

Let us know how it goes.

All 35 comments

Thanks for the report!

Do you get the same error when trying to edit a blog post instead of a product?

Could you also let me know if the problem remains when deleting Jetpack and installing it again from scratch?

Thank you.

I can't seem to be able to reproduce on my end with the most recent version of Gutenberg (4.5.1), nor with WordPress 5.0 RC1. If the problem remains on your end after reinstalling the plugin, could you let me know what versions of WooCommerce, Gutenberg, and WP you use on your site, and if you have any other plugins on that site?

Thank you.

@ockham Maybe we could wrap it with a check, to be safe?

I've tried to disconnect the account, deactivate and reinstall the plugin and the error was still there in every one of this steps.

After reconnecting the account few times the error is gone in one site, but not in another where I've tried to replicate the same procedure without luck.

I'm using WP 4.9.8 with Gutenberg 4.5.1 on both sites (they are our 'dev' and 'live' version of the same site, so same plugins).

Here you can find the whole error stack:

Fatal error: Uncaught Error: Call to a member function current_user_can_access_publicize_data() on null in /home/ubuntu/workspace/web/app/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php:118 
Stack trace: 
#0 /home/ubuntu/workspace/web/app/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php(136): WPCOM_REST_API_V2_Post_Publicize_Connections_Field->permission_check(409) 
#1 /home/ubuntu/workspace/web/app/plugins/jetpack/_inc/lib/core-api/class-wpcom-rest-field-controller.php(116): WPCOM_REST_API_V2_Post_Publicize_Connections_Field->get_permission_check(Array, Object(WP_REST_Request)) 
#2 /home/ubuntu/workspace/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-controller.php(394): WPCOM_REST_API_V2_Field_Controller->get_for_response(Array, 'jetpack_publici...', Object(WP_REST_Request), 'product') 
#3 /home/ubuntu/workspace/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1579): WP_REST_Controller->add_additional_fields_to_object(Array, in /home/ubuntu/workspace/web/app/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php on line 118

Tell me if there is anything I can do to help you reproduce.

@ockham Maybe we could wrap it with a check, to be safe?

I'd like to find out why $publicize is null there, since there's a chance that there are also other instances where that's the case and that might cause us trouble (which wouldn't be fixed by one additional guard around that very line).

I've also disabled all Jetpack modules via WP CLI, included publicize but the error is still there.

Hmm, tried to reproduce with a fresh WP 4.9.8, Gutenberg 4.5.1, Jetpack 6.8, and that code added to functions.php (using the Storefront theme) -- however, I couldn't repro... :slightly_frowning_face:

Wondering if something might be messing with the order of filters and/or hooks for you...

@brandomeniconi Which theme are you using? Any other WooCommerce extensions?

I'm using our modified version of _s, but it hasn't any filters for Jetpack AFAIK.

I've tried to deactivate all plugins except for this ones:

| name        | status | update | version |
+-------------+--------+--------+---------+
| gutenberg   | active | none   | 4.5.1   |
| jetpack     | active | none   | 6.8     |
| woocommerce | active | none   | 3.5.1   |
+-------------+--------+--------+---------+

error still shows up.

The strange thing is that on two sites with the same plugins one is working now and the other don't. They both work ok if I switch back to Jetpack 6.7.

Tried to put the the Gutenberg-WooCommerce enable filter above in twentysixteen and enable it, still shows the error. Maybe you can try to install and configure 6.7 and then upgrade to 6.8.

There is any way to purge all the Jetpack settings at once?

Reverting to 6.7 now, I can try to trace the bug myself tomorrow and give you some info back. It's a live site and I cant fiddle with it too much today, sorry.

We have another report of that error, with another Custom Post Type (Portfolios):
https://wordpress.org/support/topic/gutenberg-portfolio-and-publicize-causes-php-error/

  • WP 4.9.8
  • Jetpack 6.8
  • Gutenberg 4.5.1
  • PHP 7.0.32

The CPT is registered via Jetpack, in Settings > Writing:
https://jetpack.com/support/custom-content-types/

The problem does not happen for Testimonials, another CPT registered the same way in Jetpack, most likely because only Portfolios registers support for Publicize out of the box:
https://github.com/Automattic/jetpack/blob/master/modules/custom-post-types/portfolios.php#L288

This error appeared for me on all of my woocommerce sites via the woocommerce API, error log is:
All sites do not use Gutenberg!

[Wed Nov 28 14:40:18.358055 2018] [proxy_fcgi:error] [pid 22795:tid 139969578342144] [client 127.0.0.1:50566] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function current_user_can_access_publicize_data() on null in /wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php:118\nStack trace:\n#0 /wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php(136): WPCOM_REST_API_V2_Post_Publicize_Connections_Field->permission_check(17341)\n#1 /wp-content/plugins/jetpack/_inc/lib/core-api/class-wpcom-rest-field-controller.php(116): WPCOM_REST_API_V2_Post_Publicize_Connections_Field->get_permission_check(Array, Object(WP_REST_Request))\n#2 /wp-includes/rest-api/endpoints/class-wp-rest-controller.php(394): WPCOM_REST_API_V2_Field_Controller->get_for_response(Array, 'jetpack_publici...', Object(WP_REST_Request), 'product')\n#3 /wp-content/plugins/woocommerce/includes/api/v2/class-wc-rest-products-v2-controller.php(166): WP_REST_Controller->add_a...\n'

@mookie44 I see you had also posted in the forums and I replied there. Could you tell me more about your setup there, and try the suggestion I posted?

You also mentioned "via the woocommerce API"; could you tell me more about you get that error and how we could try to reproduce?

Thank you!

@jeherve I've sent more details via the Jetpack contact form. Cheers!

@mookie44 Did you get a ticket ID when you sent us the email? Could you let me know what it was?

@ockham We have more information and steps to reproduce in #10743

I am hosting my WooCommerce site on Pressable (managed-hosting) so they do not allow me to rollback Jetpack to 6.7 version. What should I do now? All of Products API do not work and business have to stop for over 2 days. Still need WooCommerce Service plugin so I can not disable Jetpack.

@phamvietloi You can install the Classic Editor plugin on your site. Let me know if it helps!

@jeherve My problem is not about Product Editor, it's Product API (Rest API) #10743
I just install and active the Classic Editor plugin but it still does not help. The same problem.

A summary of some investigation:

The offending line expects global $publicize to have a method current_user_can_access_publicize_data:
https://github.com/Automattic/jetpack/blob/62e6883ee0767f3cfbea1c32b07fce69dd32fce0/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php#L118

global $publicize appears to be set in the constructor for Publicize_UI here:
https://github.com/Automattic/jetpack/blob/35bd0be610333dd78c0b94ee4e88467cb0be3aa3/modules/publicize/ui.php#L18-L24

Publicize_UI seems to be instantiated here:
https://github.com/Automattic/jetpack/blob/35bd0be610333dd78c0b94ee4e88467cb0be3aa3/modules/publicize.php#L39
https://github.com/Automattic/jetpack/blob/35bd0be610333dd78c0b94ee4e88467cb0be3aa3/modules/publicize.php#L57-L58

So we would expect that if modules/publicize.php were included, then global $publicize; $publicize->current_user_can_access_publicize_data( $post_id ) would work just fine.

I'm not familiar with the intricacies of how modules are loaded, but it seems to me that the relevant files are not being included under some circumstances. I'd presume this is because the module is not active.


Following the instructions from #10743, I've verified that the REST API call mentioned there is broken when publicize is disabled. Enabling the publicize module fixes the problem. A temporary workaround for affected users may be to enable the publicize module:

From /wp-admin/admin.php?page=jetpack#/sharing, ensure _Publicize connections_ is enabled:

publicize


~Considering this, I think @jeherve's suggestion to guard this call in case $publicize is not instantiated is a good suggestion. I'll get a PR ready for that.~ Decided against this: https://github.com/Automattic/jetpack/issues/10743#issuecomment-442790683

A bit more detail, I was wondering _why_ we were hitting this publicize code path for a WooCommerce Rest API call.

WooCommerce declares product post type supports publicize:

https://github.com/woocommerce/woocommerce/blob/83c71f053b2a4f25ce88243f9e68b0fff93aa307/includes/class-wc-post-types.php#L278

I believe the Rest API is attaching jetpack_publicize_connections fields to the products, which leads to this error:
https://github.com/Automattic/jetpack/blob/62e6883ee0767f3cfbea1c32b07fce69dd32fce0/_inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php#L36

Considering this, I think @jeherve's suggestion to guard this call in case $publicize is not instantiated is a good suggestion. I'll get a PR ready for that.

I've rethought and I don't believe this is the best solution. It seems to me that, if the publicize module is not active, the WPCOM_REST_API_V2_Post_Publicize_Connections_Field API plugin should not even be loaded. I'd appreciate if someone could take a look at why this is API plugin is being loaded when the module is not active.

Let's also cc @mdawaffe here.

@phamvietloi Could you try to remove Publicize support for WooCommerce products, like so?

function jeherve_rm_jetpack_publicize_woocommerce() {
    remove_post_type_support( 'product', 'publicize' );
}

add_action( 'init', 'jeherve_rm_jetpack_publicize_woocommerce' );

You can follow the instructions here to add this code snippet to your site.

Another option would be to enable the Publicize module under Jetpack > Settings > Sharing, as my colleague suggested above.

Let us know how it goes.

@jeherve Hey that worked! Just tried on one of our websites. The woocommerce product API now works.

It seems to me that, if the publicize module is not active, the WPCOM_REST_API_V2_Post_Publicize_Connections_Field API plugin should not even be loaded. I'd appreciate if someone could take a look at why this is API plugin is being loaded when the module is not active.

Right. Maybe we should add is_module_active checks for everything that gets loaded in https://github.com/Automattic/jetpack/tree/master/_inc/lib/core-api and depends on a module? Noting that if we go this route, we would have to merge D18449-code to be able to merge the changes we make in Jetpack back to WordPress.com.

@jeherve Just enable the Publicize module under Jetpack > Settings > Sharing and it works now. Thanks you both so much

FWIW another report in p90Yrv-TJ-p2 - @phamvietloi's solution of enabling publicize fixed it.

I can confirm that I've also encountered this same bug impacting the "Podcast" CPT created by the Seriously Simple Podcasting plugin.

Same bug seems to be affecting Ship Easy plugins ability to pull orders. Enabling publicize fixed it.

Another case with ShippingEasy 1617209-zen

@ockham I'm still getting the exact same fatal error with Jetpack 6.8.1 when Jetpack is put in development mode using the jetpack_development_mode filter.

It doesn't even have to be a WC product, this happens with the jetpack-portfolio CPT.

Changing the condition on this line to ! Jetpack::is_development_mode() && Jetpack::is_module_active( 'publicize' ) does not fix the problem because the call to add_filter( 'jetpack_development_mode', '__return_true' ); may not have happened yet if it is in a plugin. Try using the Unplug Jetpack plugin.

Is it possible to delay the above check until init or at least plugins_loaded?

@nyordanov Could you tell us more about your setup? Publicize should not be active on a site running Development mode, since the feature requires a connection to WordPress.com. Is this for a site that was connected to WordPress.com before and used the Publicize feature, and where you then added the jetpack_development_mode filter?

Could you tell us more about your setup?

Jetpack 6.8.1 with Unplug Jetpack; latest WP. I'm not using the Classic Editor plugin.

Publicize should not be active on a site running Development mode, since the feature requires a connection to WordPress.com

I assume the global $publicize is null because Publicize is not active. As far as I can see, modules/publicize.php is not loaded, but _inc/lib/core-api/wpcom-fields/post-fields-publicize-connections.php is.

Is this for a site that was connected to WordPress.com before and used the Publicize feature

No, I don't think so. If I deactivate the Unplug Jetpack plugin, the site is not connected to WP.com

Thank you for the extra details.

Somewhat related: #1462 #3827

In 1687093-zen we've got a user reporting a similar issue using WP Ultimate Recipe Plugin.

Was this page helpful?
0 / 5 - 0 ratings