Make WordPress Core

Opened 13 years ago

Closed 4 weeks ago

Last modified 5 days ago

#17379 closed defect (bug) (fixed)

Filtered exports drop attachments and featured images

Reported by: billseymour's profile billseymour Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.5 Priority: normal
Severity: normal Version: 3.0
Component: Export Keywords: has-patch has-unit-tests has-testing-info commit
Focuses: Cc:

Description

When using Tools>Export, targeting a specific author, the resulting XML file does not contain a reference/link to any Featured Image (thumbnail) associated with these posts.

On the other hand, Tools>Export "all content" (including all authors) produces an XML file that does contain reference/link to Featured Image.

Request: Have Tools>Export "specific author" generate the same metadata as the "all content" export, so that Export "specific author" will also include metadata reference to the Featured Image.

Many people (including myself) use "specific author" as a way to export some, but not all, posts. Full metadata would really help. Thanks.

Attachments (2)

export_attachments_for_cpt.diff (1.3 KB) - added by jghazally 12 years ago.
Include attachments for specific post_types
export-with-attachments.diff (1.8 KB) - added by Ganon 10 years ago.
Export with attachments and thumbnails

Download all attachments as: .zip

Change History (63)

#1 @duck_
13 years ago

The problem isn't missing meta data (see <wp:meta_key>_thumbnail_id</wp:meta_key>). Rather the fact that no attachments are exported/imported so the reference doesn't mean anything in the imported install.

#2 @jane
12 years ago

  • Summary changed from Export Posts by Author- Featured Image reference to Export Posts by Author needs Featured Image reference

#3 @duck_
12 years ago

  • Component changed from General to Export
  • Summary changed from Export Posts by Author needs Featured Image reference to Filtered exports drop attachments and featured images
  • Version set to 3.0

Marked #19591 as dupe. Definitely present in 3.0, and I'm pretty sure it was present earlier than that but I haven't checked.

Related: #19307

#4 @rcain
12 years ago

thought it might be helpful to suggest a very simple solution to this:

can we not have an 'export attachments only' option (alongside 'export posts only', etc)?

i've just implemented similar in the old advanced-export-forwp-wpmu plugin here : http://wordpress.org/support/topic/plugin-advanced-export-for-wp-wpmu-how-to-export-attachments-only - which i believe is pretty similar code.

since big exports generally have to be done in smaller batches anyway, exporting attachments separately seems logical.

on the flip-side, there still appear to be some issues with the wordpress-importer plugin (eg: http://wordpress.org/support/topic/plugin-wordpress-importer-not-importing-any-images-at-all), but this would seem a practical step in the right direction.

#5 @Ipstenu
12 years ago

  • Cc ipstenu@… added

#6 @johnbillion
12 years ago

  • Cc johnbillion added

#7 @jtsternberg
12 years ago

  • Cc justin@… added

#8 @JarretC
12 years ago

  • Cc jarretcade@… added

@jghazally
12 years ago

Include attachments for specific post_types

#9 @jghazally
12 years ago

Hi I just came across this problem when trying to import a CPT, the featured images (and other attachments) are not included in the xml file. I have attached a patch above to fix my issue which is fairly basic and can probably be improved. It can also be made to utilize a checkbox as per @rcain 's suggestion.
Hope this helps core out.

best
jeff

#10 @batmoo
12 years ago

  • Cc batmoo@… added

#11 @smub
12 years ago

Just ran into this issue. This also breaks conditionals like has_post_thumbnail() ... Just exported about 24 posts from a site to test on local dev environment (building a new theme). Put up some dummy thumbnails on few articles. Then added a custom field for image URLs (just to simulate posts from pre WP 2.9)... Was running a conditional and it wasn't working. Spend all the time just to realize it was because an attachment ID was saved. So while it doesn't display a thumbnail that is attached, it stores an ID in the database thus causing the conditional to return TRUE when it is not.

#12 @travisnorthcutt
12 years ago

  • Cc travis@… added

A big fat +1 from me on this. My use case was exporting/importing a custom post type with associated featured images. The code posted by @jghazally worked *perfectly* for me.

#13 @wingfingerbill
12 years ago

  • Cc wingfingerbill added

#14 @jghazally
12 years ago

If someone wants to give me an idea of what sort of UI / form elements we want to use, and a hand getting started on Unit Testing this would love to help...

best
jeff

#15 @batmoo
11 years ago

export_attachments_for_cpt.diff works pretty nicely. Would be nice to get this into 3.5.

#16 @axwax
11 years ago

+1 on getting that patch by @jghazally into 3.5,
as in its current form it does indeed mess up the database as @smub mentioned above...

Last edited 11 years ago by axwax (previous) (diff)

#17 @creativeslice
11 years ago

  • Keywords has-patch added

We've been able to get this to work with a hack to the Advanced Export plugin, however it's quite brittle and only allows you to filter by date and author, not category. It would be great to have this fixed in core so exporting a range of posts works without dropping images.

#18 @lachlanj
11 years ago

  • Cc lachlan@… added

#19 @dlocc
11 years ago

Thanks to the export_attachments_for_cpt.diff for working great! I'm happy I found this... saved me bunches of time. Why wasn't this included in 3.5? It should definitely be rolled out.

#20 @jghazally
11 years ago

@dlocc the export system is getting overhauled and a new API is being developed see #22435

#21 @betzster
11 years ago

  • Cc j@… added

#22 @nacin
11 years ago

  • Milestone changed from Awaiting Review to 3.7
  • Type changed from feature request to enhancement

#23 @nacin
10 years ago

  • Type changed from enhancement to defect (bug)

Really, this is a bug.

The patch seems OK, but I'm not sure about it. A few issues:

  • How well will that query work when there are a lot of post IDs? It's possible that you could be exporting tens of thousands of post IDs of a single type. The IN would get too long at some point.
  • Unless my memory is failing me, featured images aren't necessarily attached to posts. We'd need to check each post's metadata and append the post to the posts to export if it is missing.

#24 @nacin
10 years ago

  • Milestone changed from 3.7 to 3.8

#25 @nacin
10 years ago

  • Milestone changed from 3.8 to Future Release

Some concerns still.

#26 @wonderboymusic
10 years ago

  • Keywords needs-patch added; has-patch removed

Featured images are always related by a post meta entry, not necessarily by post_parent. Needs a new patch.

@Ganon
10 years ago

Export with attachments and thumbnails

#27 @Ganon
10 years ago

I've attached a patch that should comply with your requirements, gets the thumbnail from the postmeta and doesn't creates long queries.

#28 @SergeyBiryukov
10 years ago

  • Keywords has-patch added; needs-patch removed

#29 @Ganon
10 years ago

Hmm, could we have this scheduled for the next release?

#30 @hlashbrooke
9 years ago

Just to note - I made a few significant improvements to the export function in #27048 - I wasn't directly intending to fix this issue with attachments, but it was indirectly fixed in that patch.

#31 @chriscct7
8 years ago

  • Owner set to chriscct7
  • Status changed from new to reviewing

This ticket was mentioned in PR #4245 on WordPress/wordpress-develop by nate-allen.


12 months ago
#32

  • Keywords has-unit-tests added

This pull request fixes an issue where attachments are not included when exporting posts, unless you choose the "all" option.

A unit test is also included.

Trac ticket: 17379

#33 @nateallen
12 months ago

  • Keywords has-testing-info added

I cleaned up the code a bit and adding a new unit test. I'm hopeful we can finally merge this fix into WordPress core. Given that the bug has caused frustration for WordPress users for more than a decade, I'm eager to see it resolved at last!

To test this patch:

  1. Create a post and add a featured image
  2. Go to Tools > Export
  3. Select the Posts option
  4. Choose an author
  5. Click "Download Export File"

The export file should contain your post and the attachment. Without the patch, you should only see the post.

#34 @fischfood
12 months ago

Test Report

This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/4245/
Environment
OS: macOS 12.4
PHP: 8.0.16
WordPress: 6.1.1
Browser: Brave 1.48.164, Chrome 111.0.5563.64
Theme: Twenty Twenty-Two


Steps

  • Updated wp-admin/includes/export.php on a live website for public image access
  • Added a post to the live site with a featured image, and an image within the content
  • On that site, I ran two exports, one for all posts with "Posts", and one for all posts by a specific author
  • On a clean local site, I ran an import for each xml file, checking off the "Download and import file attachments" option, sacking the post and images in between the tests

Results

  • On both imports, a post was created with the featured image as well as the image within the content. Both images were uploaded into the Media Gallery.
Last edited 12 months ago by fischfood (previous) (diff)

@hifidesign commented on PR #4245:


6 months ago
#35

If support for PHP versions < v7 has been dropped, why is this holding up the merge of a patch for a 12 year old Trac ticket?

#36 @hifidesign
6 months ago

@nateallen you're awesome!

Seems like closing this 12 year old Trac ticket would be a win. Now that support for PHP versions below v7 has been dropped, can anyone clarify why unit test requirements for PHP 5.6 holding up the merge for this patch?

@nateallen commented on PR #4245:


6 months ago
#37

@electricbrick Should I close this pull request and open a new one? That would trigger a new checks on the code that don't include PHP 5.6.

@hifidesign commented on PR #4245:


6 months ago
#38

@nate-allen Good question... By the way, my reply was meant more for maintainers to see activity on the ticket, and not shade @ you.

is a new PR against the rules? Because maybe it would work — are there potentially unforeseen consequences though? An alternative is someone could show up at the Make Slack contributors stand-up and advocate for it. I don't know if that's still held on Wednesdays.

This ticket was mentioned in PR #5720 on WordPress/wordpress-develop by @nateallen.


4 months ago
#39

I closed my previous PR on this issue because it was stuck on a failed PHP 5.6 test that doesn't apply anymore.

This pull request fixes an issue where attachments are not included when exporting posts, unless you choose the "all" option.

A unit test is also included.

Trac ticket: 17379

This ticket was mentioned in Slack in #core by nateallen. View the logs.


3 months ago

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


3 months ago

#42 @hellofromTonya
2 months ago

  • Keywords needs-testing added
  • Milestone set to 6.5
  • Owner changed from chriscct7 to hellofromTonya

After talking with @nateallen, the latest patch is ready for final review and testing, has already been tested and there's high confidence with the patch.

  • Moving into 6.5.
  • Also marking with needs-testing as there were some changes with the latest patch. Will drop in the slack core-testing channel to wrangle some testers.
  • Self-assigning ownership to help shepherd it forward to commit.

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


2 months ago

#44 @hellofromTonya
2 months ago

Dropped this ticket and its patch in Core's testing slack channel. A couple more test reports for this patch will be helpful and appreciated.

Patch: https://github.com/WordPress/wordpress-develop/pull/5720
Testing instructions: found here.

#45 @petitphp
2 months ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5720.diff
Testing instructions: comment:33

Environment

  • OS: macOS 13.6.1
  • Web Server: Nginx
  • PHP: 7.4.33
  • WordPress: WordPress 6.5-alpha-56966-src
  • Browser: Firefox 122b9
  • Theme: Twenty Twenty-Four
  • Active Plugins:
    • WordPress Importer 0.8.2

Actual Results

  • ✅ With the patch, exporting posts for a specific author also include all the children attachments of the posts and all the attachments used as thumbnails.
  • ✅ Importing the XML file with the Download and import file attachments option checked did correctly create the expected posts with their medias/thumbnail.

Additional Notes

  • While testing the patch, it appears that the new queries used to find related attachments would also run when exporting "Media" where it is not useful. I don't think it's a blocker for the current patch to be committed. I've added a comment in the PR to discuss a small change to avoid those extra queries in this special case.

#46 @Ankit K Gupta
2 months ago

Test Report ✅

Description

This report validates that the patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5720

Environment

  • WordPress: 6.5-alpha-20240117.204717
  • PHP: 7.4.30
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 5.7.28 / Client: mysqlnd 7.4.30)
  • Browser: Chrome 120.0.0.0
  • OS: macOS
  • Theme: Twenty Sixteen 3.1
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.0.0
    • WordPress Importer 0.8.2

Actual Results

  1. ✅ Issue resolved with patch https://github.com/WordPress/wordpress-develop/pull/5720

Additional Notes

  • After the patch, post attachment appears in the exported XML file when export is done for a specific author.

Supplemental Artifacts

XML for all Content Export: https://ibb.co/ww2rwS4
XML for a specific author: https://ibb.co/3NV5F0R

#47 @5um17
2 months ago

Test Report

Description

This report validates that the patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5720

Environment

  • WordPress: 6.5-alpha-57299
  • PHP: 8.1.10
  • Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1s PHP/8.1.10
  • Database: mysqli (Server: 8.0.30 / Client: mysqlnd 8.1.10)
  • Browser: Firefox 121.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Four 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.0.1
    • WordPress Importer 0.8.2

Actual Results

  1. ✅ Issue resolved with patch. The exported file contains all the attachments and featured image of a post.

Additional Notes

  • There was no error/warning logged during export/import process.

#48 @shailu25
2 months ago

Test Report

This Report validates that the patch works as expected.✅

Patch Tested: https://github.com/WordPress/wordpress-develop/pull/5720

Environment:

WordPress: 6.4.2
OS: Windows
Browser: Firefox
Theme: Twenty Fifteen
PHP: 8.0.18
Active Plugin: WordPress Importer 0.8.2

Actual Results:

  • After Applying patch, Exported XML file contains all the attachments & featured image of a post.✅

Screenshots:

Before Patch: https://prnt.sc/9FmBtJIe39XN
After Patch: https://prnt.sc/SeOe2Kk4rxrO

#49 @huzaifaalmesbah
5 weeks ago

Test Report

Description

after apply patch attachments file add on export xml file.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5720

Environment

  • WordPress: 6.5-alpha-56966-src
  • PHP: 8.2.15
  • Server: nginx/1.25.3
  • Database: mysqli (Server: 8.0.36 / Client: mysqlnd 8.2.15)
  • Browser: Chrome 121.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Four 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.0.1

Actual Results

  1. ✅ Issue resolved with patch.

Screenshots

https://i.ibb.co/dMhPDTr/Screenshot-2024-02-09-at-11-34-03-PM.png

@hellofromTonya commented on PR #5720:


5 weeks ago
#50

Request: Have Tools>Export "specific author" generate the same metadata as the "all content" export, so that Export "specific author" will also include metadata reference to the Featured Image.

The Trac ticket is focused on exporting for a _"specific author"_ rather than _all authors_. The PR works for both. Is this intentional to include when no author is selected (i.e. to do all authors)?

If yes it should also work for all authors, what might be the risks or impacts on sites with a large or massive amounts of content?

@nateallen commented on PR #5720:


5 weeks ago
#51

The Trac ticket is focused on exporting for a _"specific author"_ rather than _all authors_. The PR works for both. Is this intentional to include when no author is selected (i.e. to do all authors)?

The Trac ticket mentions the bug happens when you filter by specific author, but it actually happens when you do any filter other than "All content"

This patch fixes that by getting all the attachments for the posts being exported if $args['content'] isn't all. I'll update the patch to not do this if the posts being exported are attachment

If yes it should also work for all authors, what might be the risks or impacts on sites with a large or massive amounts of content?

The patch takes this into consideration by splitting the work into chunks of 20 post IDs at a time.

@hellofromTonya commented on PR #5720:


5 weeks ago
#52

The Trac ticket mentions the bug happens when you filter by specific author, but it actually happens when you do any filter other than "All content"

Aha thanks @nate-allen for clarifying. Makes sense 👍

@hellofromTonya commented on PR #5720:


5 weeks ago
#53

It's really close for commit. Left some comments to finalize it.

@hellofromTonya commented on PR #5720:


4 weeks ago
#54

Thank you @nate-allen and everyone for the follow-ups to code review and suggestions. Reviewing today for commit.

@hellofromTonya commented on PR #5720:


4 weeks ago
#55

To ensure there are no merge conflicts, a rebase is needed against the current WordPress Develop trunk. Will force push shortly.

#56 @hellofromTonya
4 weeks ago

  • Keywords commit added; needs-testing removed

Patch: https://github.com/WordPress/wordpress-develop/pull/5720

Patch is ready. Marking for commit. On my commit list for tomorrow.

#57 @hellofromTonya
4 weeks ago

Test Report

Description

This report validates that the patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5720 current version as of this test report.

Environment

  • WordPress: 6.5-beta1-57630-src
  • PHP: 7.4.33
  • Server: nginx/1.23.4
  • Database: server: mysqli 8.0.36 | client: mysqlnd 7.4.33
  • Browser: Firefox 122.0.1
  • OS: macOS
  • Theme: TT4
  • MU Plugins: None
  • Plugins: None

Steps

Note: All images I used were different, i.e. only used once.

Set up:

  1. Add at least one author or higher user. I added tester1 (author) and tester2 (editor).
  2. Add multiple new posts. I added:
    • Post 1 by tester1 with a featured image and an image within the content.
    • Post 2 by tester2 with a featured image.
    • Post 3 by tester2 with an image in the content but no featured image.
  3. Add multiple new pages. I added:
    • Page 1 by tester1 with a featured image and a different image within the content.
    • Page 2 by tester2 with a featured image.
    • Page 3 by tester2 with an image in the content but no featured image.

Test Posts with a specific author

  1. Go to Tools > Export
  2. Select Posts.
  3. In Posts > Authors, select a specific author. I selected tester2.
  4. Select the "Download Export File" button.
  5. Open and review the downloaded XML file.

Test Posts (without a specific author)

  1. Go to Tools > Export
  2. Select Posts. Do not select a specific author.
  3. Select the "Download Export File" button.
  4. Open and review the downloaded XML file.

Test Pages with a specific author

  1. Go to Tools > Export
  2. Select Pages.
  3. In Posts > Authors, select a specific author. I selected tester2.
  4. Select the "Download Export File" button.
  5. Open and review the downloaded XML file.

Test Pages (without a specific author)

  1. Go to Tools > Export
  2. Select Pages. Do not select a specific author.
  3. Select the "Download Export File" button.
  4. Open and review the downloaded XML file.

Expected Results

The following expected results are based on my set up.

Test Posts with a specific author

Should be an item for each post and an item for each post's featured image.

I selected tester2, who in my set up has 2 posts (Post 2 and 3) and 1 featured image (attached to Post 2). Thus, the expected XML download should have 3 items.

Test Posts (without a specific author)

Should be an item for each post (to include all posts) and an item for each post's featured image.

My set up has 3 posts (Post 1, Post 2, Post 3) and 2 featured images; thus, the expected XML download should have 5 items.

Test Pages with a specific author

See posts (above) - expect the same result, but for pages.

Test Pages (without a specific author)

See posts (above) - expect the same result, but for pages.

Test Results: before the patch

Test Posts with a specific author: downloaded XML items:

  • ❌ No item for Post 2's featured image 🐞
  • ✅ Item for Post 2
  • ✅ Item for Post 3

Test Posts (without a specific author): the downloaded XML items:

  • ❌ No item for Post 1's featured image 🐞
  • ❌ No item for Post 2's featured image 🐞
  • ✅ Item for Post 1
  • ✅ Item for Post 2
  • ✅ Item for Post 3

Test Pages with a specific author: downloaded XML items:

  • ❌ No item for Page 2's featured image 🐞
  • ✅ Item for Page 2
  • ✅ Item for Page 3

Test Pages (without a specific author): the downloaded XML items:

  • ❌ No item for Page 1's featured image 🐞
  • ❌ No item for Page 2's featured image 🐞
  • ✅ Item for Page 1
  • ✅ Item for Page 2
  • ✅ Item for Page 3

Test Results: after the patch

Confirmed the patch resolves the issue of including the featured image.

Test Posts with a specific author: downloaded XML items:

  • ✅ Item for Post 2's featured image
  • ✅ Item for Post 2
  • ✅ Item for Post 3

Test Posts (without a specific author): the downloaded XML items:

  • ✅ Item for Post 1's featured image
  • ✅ Item for Post 2's featured image
  • ✅ Item for Post 1
  • ✅ Item for Post 2
  • ✅ Item for Post 3

Test Pages with a specific author: downloaded XML items:

  • ✅ Item for Page 2's featured image
  • ✅ Item for Page 2
  • ✅ Item for Page 3

Test Pages (without a specific author): the downloaded XML items:

  • ✅ Item for Page 1's featured image
  • ✅ Item for Page 2's featured image
  • ✅ Item for Page 1
  • ✅ Item for Page 2
  • ✅ Item for Page 3

Additional Notes

Images/attachments within the content were not included when selecting Posts or Pages, but are included when selecting All content.

#58 @hellofromTonya
4 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 57681:

Export: Include featured image for posts or pages.

This bugfix resolves an issue in export_wp() with featured images.

When using Tools > Export and selecting either Posts or Pages (with or without a specific author), the resulting XML file now includes a XML item for each post|page's featured image attachment and its metadata.

Uses same chunking (for performance) and code patterns from existing code in the same file.

Adds a new test class for export_wp() with code coverage specific to this bugfix.

Follow-up to [34326], [14444], [6375], [6335].

Props billseymour, nateallen, petitphp, hellofromTonya, duck_, jane, rcain, jghazally, jghazally, smub, batmoo, axwax, creativeslice, dlocc, nacin, wonderboymusic, ganon, SergeyBiryukov, hlashbrooke, chriscct7, fischfood, hifidesign, ankit-k-gupta, 5um17, shailu25, huzaifaalmesbah, mukesh27.
Fixes #17379.

#60 @hellofromTonya
4 weeks ago

Thank you everyone who contributed to this ticket and its resolution. The bugfix has been committed to ship in WP 6.5, closing this issue first opened 13 years ago. Well done everyone :)

Note: Please test. If you find an issue or refinement for r57681, then please reopen this ticket (or create a new one) and share your findings.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


5 days ago

Note: See TracTickets for help on using tickets.