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

Fix #3325 Set the current post when indexing posts #3333

Merged
merged 1 commit into from
Feb 23, 2023

Conversation

tomjn
Copy link
Contributor

@tomjn tomjn commented Feb 21, 2023

Description of the Change

When indexing a post, the content gets rendered, and shortcodes/blocks/etc may rely on the global $post variable to provide context that will be missing when performing an ES index.

In my case it was a block which did not handle the value being missing, but context dependent content would generate PHP warnings/errors or incorrect data

By setting the global $post and the current postdata, we can avoid some of these situations. This enabled indexing to continue locally where it would fail previously.

Closes #3325

How to test the Change

In my case, I did not check the postId in the block context for presence and used it without verification. This lead to a fatal error which is avoided when using this PR

Changelog Entry

Fixed - Not setting the post context when indexing a post

Credits

Props @tomjn

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

When indexing a post, the content gets rendered, and shortcodes/blocks/etc may rely on the global `$post` variable to provide context that will be missing when performing an ES index.

In my case it was a block which did not handle the value being missing, but context dependent content would generate PHP warnings/errors or incorrect data
@tomjn
Copy link
Contributor Author

tomjn commented Feb 21, 2023

Making this PR via the web interface, I don't have a lot of bandwidth right now to dig into things

@felipeelia felipeelia added this to the 4.5.0 milestone Feb 23, 2023
@felipeelia felipeelia merged commit 8bd7199 into 10up:develop Feb 23, 2023
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

Successfully merging this pull request may close these issues.

BUG: Blocks that use postId context crash indexing
2 participants