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

Allow dynamic blocks to create loops #9182

Merged
merged 3 commits into from
Aug 21, 2018
Merged

Conversation

obenland
Copy link
Member

@obenland obenland commented Aug 20, 2018

Fixes #7427, fixes #8035.

Description

Stores and restores the global post object around dynamic block callbacks. This allows dynamic blocks to create new WP_Query instances and set up its post data, without changing the currently edited post.

How has this been tested?

Added a new unit test.
Tested with a custom dynamic block in wp-admin and front-end with the block callback I added in the unit test. I could recreate the scenario described in #7427.

Types of changes

Stores global $post in do_blocks() and resets it after every dynamic block callback.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

Stores and restores the global post object around dynamic block callbacks. This allows dynamic blocks to create new `WP_Query` instances and set up its post data, without changing the currently edited post.

See #7427, #8035.
@obenland obenland added [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. labels Aug 20, 2018
@obenland obenland added this to the 3.7 milestone Aug 20, 2018
@obenland obenland merged commit ba5dc99 into master Aug 21, 2018
@obenland obenland deleted the origin/add/global-post-backup branch August 21, 2018 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocks unavailable when new WP_Query is used inside render callback wp_reset_query() in a block doesn't work
2 participants