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

Implement a more reliable way to retrieve the current post to avoid conflicts when a plugin resets the $post variable #7582

Closed
designsimply opened this issue Jun 27, 2018 · 3 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@designsimply
Copy link
Member

Moved from #7461 (and quoting @aduth) 🙂 to make the underlying issue smaller and clearer:

Here are steps to reproduce from a fresh install:

  1. Install Strong Testimonials plugin
  2. Publish a new Testimonial via Testimonials > Add New
  3. Create and save a new Testimonial view via Testimonials > Views > Add New
  4. Copy the generated view shortcode
  5. Paste shortcode into a new post via Posts > Add New
  6. Save post
  7. Refresh page

Specifically, Strong Testimonials is causing the $post global to be overridden via its shortcode template rendering.

Working backwards:

  1. https://github.com/WordPress/wordpress-develop/blob/0e7ed499e0c9f2f5df3c26b982b9722fe83af906/src/wp-includes/class-wp-query.php#L3229
  2. https://github.com/cdillon/strong-testimonials/blob/3d07e4fb47af06a1d04207a8cb76fc3f1fb51840/templates/default/content.php#L15
  3. https://github.com/cdillon/strong-testimonials/blob/3d07e4fb47af06a1d04207a8cb76fc3f1fb51840/includes/class-strong-view-display.php#L163
  4. https://github.com/cdillon/strong-testimonials/blob/3d07e4fb47af06a1d04207a8cb76fc3f1fb51840/includes/class-strong-testimonials-shortcode.php#L95
  5. https://github.com/cdillon/strong-testimonials/blob/3d07e4fb47af06a1d04207a8cb76fc3f1fb51840/includes/class-strong-testimonials-shortcode.php#L16

While the rendered preview is not used, it's still being generated due to the default behavior of the posts REST API endpoint (i.e. post.content.rendered).

Since there's a good chance that more than just this one plugin could cause the $post variable to be reset, I think it might be in our interest to implement a more reliable way to retrieve the current post.

A few ideas:

Separately, I have opened a pull request to the Strong Testimonials repository at WPChill/strong-testimonials#12 to avoid overriding the $post variable. You can copy the modifications into your own copy of the plugin and it should resolve the issue.

@designsimply designsimply added [Type] Task Issues or PRs that have been broken down into an individual action to take [Feature] Extensibility The ability to extend blocks or the editing experience labels Jun 27, 2018
@cdillon
Copy link

cdillon commented Jun 29, 2018

Please help me understand. You found something that's not working in Gutenberg and that is related to a known bug in WordPress admin and you want me to update my plugin to be compatible? Am I reading this correctly?

@aduth
Copy link
Member

aduth commented Jun 29, 2018

@cdillon There are a few things going on here.

The existence of the core bug means that your plugin's calling of the_post in the shortcode rendering will result in the $post global being overridden. I expect this is not done intentionally. Any core logic or plugin which relies on the global (such as Gutenberg) may encounter issues such as those demonstrated in #7461.

Regardless of whether you decide to make any changes to your plugin, Gutenberg should be updated to be more resilient to this, likely by not using $post, which by the existence of this core bug is shown to be too fragile and easily changed to rely upon.

This presumably becomes a non-issue if Core Trac#18408 is resolved.

@danielbachhuber
Copy link
Member

This was at least partially addressed by #7889 The longer term fix will need to be https://core.trac.wordpress.org/ticket/18408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

4 participants