WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 18 months ago

Last modified 18 months ago

#19863 closed enhancement (fixed)

Add filters to export_wp() process for granular export control

Reported by: scottconnerly Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.3.1
Component: Export Keywords: has-patch commit
Focuses: Cc:

Description

The only hook that allows for export customization right now is do_action('export_wp'). There should be a filter on the $args in the same area as well as actions in the export form so additional export filters can be defined on any post type (especially the custom post types)

Use case example would be the shopping experience I'm building as a plugin. Administrators need to be able to export order CSVs for fulfillment systems, inventory systems, accounting systems, etc. I need to be able to filter by date range as well as some custom taxonomies I have defined to manage the order's present status.

Then I need to be able to generate CSVs rather than XMLs in the output. For that I can currently hijack the process at do_action('export_wp'), but it'd be better if there were hooks all through the export process that allowed me to output different headers, adjust the query, and manipulate the retrieved data.

Essentially, we're currently allowed to import any custom post content via CSV in a bespoke manner, but there's no way to get it back out in a similar format.

Attachments (2)

export_patch.patch (1.2 KB) - added by MartyThornley 2 years ago.
19863.refresh.diff (643 bytes) - added by brandondove 18 months ago.

Download all attachments as: .zip

Change History (16)

comment:1 scribu2 years ago

+1 for being able to filter which posts get exported through a hook.

Not so sure about the hooks for manipulating the export format.

MartyThornley2 years ago

comment:2 MartyThornley2 years ago

  • Cc marty@… added
  • Keywords has-patch added; needs-patch removed

Working on a bunch of ideas for importing/exporting and was looking for this exact thing. Here is a quick patch with a filter for export $args and two do_action calls to help add to the potential filters.

Ideally, that whole section of filters could be filtered to make it really customizable. But this is a start.

comment:3 scribu21 months ago

  • Milestone changed from Awaiting Review to 3.5
  • Summary changed from Add filters to export_wp() process for granular export control to Addd filters to export_wp() process for granular export control

Essentially, we're currently allowed to import any custom post content via CSV in a bespoke manner, but there's no way to get it back out in a similar format.

Writing a CSV exporter from scratch is not hard. Query the posts and output them to a file using fputcsv().

Anyway, the current patch looks good.

comment:4 scribu21 months ago

  • Summary changed from Addd filters to export_wp() process for granular export control to Add filters to export_wp() process for granular export control

comment:5 nacin19 months ago

A single 'export_filters' hook at the end is probably sufficient. The args filter also seems sufficient.

comment:6 nacin19 months ago

  • Keywords needs-refresh added

comment:7 nacin19 months ago

  • Keywords commit added

brandondove18 months ago

comment:8 brandondove18 months ago

Patch refreshed based on Nacin's recommendations.

comment:9 brandondove18 months ago

  • Cc brandon@… added

comment:10 kovshenin18 months ago

  • Keywords needs-refresh removed

comment:11 nacin18 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 22392:

Add the export_filters and wp_export_args hooks. props MartyThornley, brandondove. fixes #19863.

comment:12 follow-up: duck_18 months ago

Should that be export_wp_args to match the name of the function?

comment:13 in reply to: ↑ 12 nacin18 months ago

Replying to duck_:

Should that be export_wp_args to match the name of the function?

Thought about that. The filter is outside the function itself because it is essentially a way to alter arguments based on export_filters. If we were to add a filter inside, "export_wp_args" would work there. "export_args" probably makes the most sense here, with the wp_ prefix not needed. Thoughts?

comment:14 duck_18 months ago

In 22402:

Rename filter on $args sent to export_wp() for clarity. See #19863.

Note: See TracTickets for help on using tickets.