WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 21 months ago

#48180 new enhancement

extend export with filter for join and where clause

Reported by: mgleich Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2.3
Component: Export Keywords:
Focuses: Cc:

Description

In attachment I send a patch to add two lines for filters to change external the join and where clause to make it possible to export only the right posts.

I hope your can take it into the core.

Background: I have an user defined post type "bp-blog", which extends the default blog with buddypress group functionality. Therefor I save the buddy press group id in postmeta.

Now I want export only the "bp-blog" posts for a specific group. Without the filter I cannot modify the request query and all "bp-blog" posts are exported.

Here my usage of the the new filter:

<?php
    add_filter('export_filter_join', 'export_filter_join', 0, 2);
    public function export_filter_join($join, $args = array()) {
        if ($args['content'] != 'bp-blog' && !isset($args['group'])) {
            return $join;
        }

        global $wpdb;

        $join .= " INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)";

        return $join;
    }

and

<?php
    add_filter('export_filter_where', 'export_filter_where', 0, 2);
    public function export_filter_where($where, $args = array()) {
        if ($args['content'] != 'bp-blog' && !isset($args['group'])) {
            return $where;
        }

        global $wpdb;

        $where .= " AND wp_postmeta.meta_key = '_bp_group' AND wp_postmeta.meta_value = {$args['group']}";

        return $where;
    }

Attachments (2)

extend_export_with_filter_for_join_and_where_clause.patch (888 bytes) - added by mgleich 21 months ago.
Patch to insert two lines with filters
add_action_add_import_options.patch (676 bytes) - added by mgleich 21 months ago.
this patch adds do_action add_import_options to add import options e.g. for user defined post type

Download all attachments as: .zip

Change History (5)

@mgleich
21 months ago

Patch to insert two lines with filters

@mgleich
21 months ago

this patch adds do_action add_import_options to add import options e.g. for user defined post type

#1 follow-up: @subrataemfluence
21 months ago

  • Keywords reporter-feedback added

@mgleich thanks for the ticket and proposed patch!

A core functionality does not address a specific purpose. It has to be generic.

Apart from the situation you have described, how you think these two filters can benefit if embedded in core functionality?

An explanation would be great.

#2 in reply to: ↑ description @mgleich
21 months ago

  • Keywords reporter-feedback removed

I have additionally added a patch to make it possible to add import options. I do not use the action anymore. So do not know if she's useful. If in doubt, ignore it.

#3 in reply to: ↑ 1 @mgleich
21 months ago

Replying to subrataemfluence:

@mgleich thanks for the ticket and proposed patch!

A core functionality does not address a specific purpose. It has to be generic.

Apart from the situation you have described, how you think these two filters can benefit if embedded in core functionality?

An explanation would be great.

I understand and try to give the right explanation.

I think anyone who creates a custom post type that has dependencies on plugins and wants to export them must have the ability to change the export query.

On the other hand, the generic usage is not damaged or only slightly influenced.

So it's more of an extension of the way plugins can interact better with export functionality.

It may also be useful without custom post types. The possibilities of filtering, what should be exported, are not very user friendly. Why I can not select the individual posts or filter the title via regular expression? Since anybody will want to develop plugins that improve the export and allow additional filter parameters. These developer will appreciate these two new filters.

If I continue to think I would even wish that I can extend the XML structure of the export file and thus the parser to its own sections to better store the export and import relationships in the file and restore it in other systems. Currently that is not possible.

Note: See TracTickets for help on using tickets.