#50775 closed defect (bug) (fixed)
Correctly back up the global $post in edit-form-blocks.php
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
wp-admin/edit-form-blocks.php
goes through some effort to back up and restore the global $post
:
/* * Ensure the global $post remains the same after API data is preloaded. * Because API preloading can call the_content and other filters, plugins * can unexpectedly modify $post. */ $backup_global_post = $post; $preload_data = array_reduce( $preload_paths, 'rest_preload_api_request', array() ); // Restore the global $post as it was before API preloading. $post = $backup_global_post;
This doesn't seem to work as expected, as $backup_global_post = $post;
is not creating a copy of the object, it's a reference to the same object. If $post
is modified, $backup_global_post
is modified too.
To create a proper copy, $backup_global_post = clone $post;
should be used, see Object Cloning.
Attachments (1)
Change History (6)
This ticket was mentioned in PR #446 on WordPress/wordpress-develop by sylvestercarolan.
5 years ago
#1
- Keywords has-patch added; needs-patch removed
#2
follow-up:
↓ 3
@
5 years ago
First patch submission - not sure if I have the process right... any feedback much appreciated!
#3
in reply to:
↑ 2
@
5 years ago
Replying to scarolan:
First patch submission - not sure if I have the process right... any feedback much appreciated!
Thanks for the patch!
Just noting that https://github.com/WordPress/wordpress-develop/pull/446 appears to include some unrelated changes and should have probably been rebased.
50775.diff.txt looks good and is exactly what's needed here. One minor thing is that it would be better in the future to upload patches with the .diff
extension instead of .txt
, so that syntax highlighting works correctly.
#4
@
5 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 48700:
Minor change to clone $post into $backupglobal post.
Trac ticket: https://core.trac.wordpress.org/ticket/50775