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

Publish and Update Fail on invalid JSON due to other plugin PHP notice #4935

Closed
2 tasks
jjtroberts opened this issue Feb 7, 2018 · 3 comments
Closed
2 tasks

Comments

@jjtroberts
Copy link

jjtroberts commented Feb 7, 2018

Issue Overview

I've installed Gutenberg 2.1.0 on WordPress 4.9.4 (PHP 5.6) and cannot publish or update a page because another plugin is writing output that is prepended to the json object.

Steps to Reproduce (for bugs)

  1. Install and activate Gutenberg 2.1.0 on a new WordPress 4.9.4
  2. Install and activate https://wordpress.org/plugins/members/ latest version.
  3. Turn debug on.
  4. Create a new page using Gutenberg editor and attempt to update/publish.

Expected Behavior

REST API should return a JSON object that allows the plugin to complete the save operation.

Current Behavior

A PHP notice from the members plugin is prepended to the json object, which causes the save to fail:

<br />
<b>Notice</b>:  Trying to get property of non-object in <b>xxxxxxxxxxxxxxxx/plugins/members/inc/template.php</b> on line <b>95</b><br />
{"id":191,"date":"2018-02-07T10:46:29","date_gmt":"2018-02-07T16:46:29","guid":{"rendered":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/?page_id=191","raw":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/?page_id=191"},"modified":"2018-02-07T11:01:42","modified_gmt":"2018-02-07T17:01:42","password":"","slug":"test","status":"publish","type":"page","link":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/test\/","title":{"raw":"Test","rendered":"Test"},"content":{"raw":"","rendered":"","protected":false},"excerpt":{"raw":"","rendered":"","protected":false},"author":10,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"revisions":{"count":1,"last_id":192},"_links":{"self":[{"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/pages\/191"}],"collection":[{"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/pages\/191\/revisions"}],"wp:attachment":[{"href":"http:\/\/xxxxxxxxx.xxxxxx.xxx\/wp-json\/wp\/v2\/media?parent=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}

Possible Solution

Have the developer fix the plugin, or have our developers fix how they are using the plugin.

Kind of hoping you guys can provide a fix because I manage many legacy sites that spew all sorts of PHP notices and warnings all over the cli when debug is turned on. Some come from poorly coded custom themes, others from plugins. I'd expect Gutenberg to be able to overcome this, but it may be unrealistic given the nature of the API call and its expected JSON payload.

Screenshots / Video

Related Issues and/or PRs

Todos

  • Tests
  • Documentation
@jjtroberts
Copy link
Author

jjtroberts commented Feb 7, 2018

Code in members that is breaking because at this point the check returns null.

// Set to `FALSE` to avoid hierarchical checking.
if ( apply_filters( 'members_check_parent_post_permission', $check_parent, $post_id, $user_id ) ) {

  $parent_id = get_post( $post_id )->post_parent;

  // If the post has a parent, check if the user has permission to view it.
  if ( 0 < $parent_id )
    $can_view = members_can_user_view_post( $user_id, $parent_id );
}

@bobbingwide
Copy link
Contributor

This was discussed today in core-editor but you got there first it seems. See #4936.

@youknowriad
Copy link
Contributor

youknowriad commented Feb 14, 2018

Hard issue to solve, closing as duplicate of #4936 .

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

No branches or pull requests

3 participants