Rewrite & Republish: images attached to the copy are not attached to the original post after republishing
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start with Post_Republisher::delete_copy() in src/post-republisher.php and trace how the copy is removed; then review how the copy inherits its parent in src/post-duplicator.php. Confirm the reported behavior on WordPress 7.2 with a child page and an unattached image. Done means republishing leaves that image attached to the original page.
Written by the indexing model from the issue text.
Description
- I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
Images that get attached to a Rewrite & Republish copy are not attached to the original post after you republish.
WordPress 7.2 makes this more common. On a manual save in the block editor, WordPress 7.2 attaches every unattached image used in an Image block (also inside a Gallery) to the post being edited. See Media changes in WordPress 7.2, section "Unattached images auto-attach". When you edit a Rewrite & Republish copy, that post is the copy.
On republish, Post_Republisher::delete_copy() deletes the copy with wp_delete_post() (src/post-republisher.php). Nothing moves the copy's attachments to the original post first. wp_delete_post() then points the attachments "up one level", to the post_parent of the deleted copy. The copy inherits post_parent from the original (src/post-duplicator.php), so the images end up:
- unattached, when the original has no parent;
- attached to the parent page of the original, when the original is a child page.
Before WordPress 7.2 the same happens to images that you upload while editing the copy. WordPress 7.2 extends it to images picked from the Media Library.
This report comes from reading the code of Yoast Duplicate Post and WordPress. It has not been reproduced on a WordPress 7.2 site yet.
To Reproduce
Step-by-step reproduction instructions
- Use WordPress 7.2 with attachment pages disabled (the default for sites created on WordPress 6.4 or later).
- Upload an image in Media > Add New Media File, so that it is unattached.
- Create and publish a child page (a page with a parent page).
- Click "Rewrite & Republish" on that page.
- In the copy, add an Image block, pick the unattached image from the Media Library, and save the draft.
- In Media > Library (list mode), check the "Uploaded to" column: the image is attached to the copy.
- Republish the copy.
- Check the "Uploaded to" column again.
Expected results
- The image is attached to the original page.
Actual results
- The image is attached to the parent page of the original. For a top-level post or page, the image is unattached.
Screenshots, screen recording, code snippet
wp_delete_post() in wp-includes/post.php:
$parent_data = array( 'post_parent' => $post->post_parent );
$parent_where = array( 'post_parent' => $post_id );
// ...
// Point all attachments to this post up one level.
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
Technical info
- If relevant, which editor is affected (or editors):
- Block Editor
- Gutenberg Editor
- Classic Editor
- Other:
- Which browser is affected (or browsers):
- Chrome
- Firefox
- Safari
- Other:
Used versions
- Device you are using:
- Operating system:
- PHP version:
- WordPress version: 7.2
- WordPress Theme:
- Yoast Duplicate Post version: trunk
- Gutenberg plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug:
- Dominant language
- PHP
- Stars
- 53
- Forks
- 40
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Yoast/duplicate-post
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Yoast/duplicate-post#537 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Yoast/duplicate-post#395 · 1 comment ·
-
TypeError in Post_Republisher::clean_up_when_copy_manually_deleted() when the post is already gone (concurrent deletes)Possibly taken @fabiomsnunes claimed this 49 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Yoast/duplicate-post#563 ·
-
Add WP abilities for key plugin functionsPossibly taken @roborourke claimed this 78 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Yoast/duplicate-post#544 ·
-
Release workflows do not trigger the dist deployPossibly taken @enricobattocchi claimed this 83 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 68/100
Yoast/duplicate-post#542 ·
All issues in Yoast/duplicate-post
Similar issues
-
repo:ckeditor
Difficulty 1/5 Under an hour Newbie friendliness 78/100
craftcms/ckeditor#682 · 1 comment ·
Maintainers usually reply within 1 day
-
component/core domain/framework
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day