Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#19863 closed enhancement (fixed)

Add filters to export_wp() process for granular export control

Reported by: scottconnerly's profile scottconnerly Owned by: nacin's profile 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 13 years ago.
19863.refresh.diff (643 bytes) - added by brandondove 12 years ago.

Download all attachments as: .zip

Change History (16)

#1 @scribu
13 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.

#2 @MartyThornley
13 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.

#3 @scribu
12 years 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.

#4 @scribu
12 years 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

#5 @nacin
12 years ago

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

#6 @nacin
12 years ago

  • Keywords needs-refresh added

#7 @nacin
12 years ago

  • Keywords commit added

#8 @brandondove
12 years ago

Patch refreshed based on Nacin's recommendations.

#9 @brandondove
12 years ago

  • Cc brandon@… added

#10 @kovshenin
12 years ago

  • Keywords needs-refresh removed

#11 @nacin
12 years 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.

#12 follow-up: @duck_
12 years ago

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

#13 in reply to: ↑ 12 @nacin
12 years 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?

#14 @duck_
12 years ago

In 22402:

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

Note: See TracTickets for help on using tickets.