Skip to content

Instantly share code, notes, and snippets.

@allendav
Created March 6, 2018 16:34
Show Gist options
  • Save allendav/f741da604a16a662ab2c43f8a4663bac to your computer and use it in GitHub Desktop.
Save allendav/f741da604a16a662ab2c43f8a4663bac to your computer and use it in GitHub Desktop.
2018-Mar-6 Exporter Design

Mike J, Gerhard P, Lauren S, Allen S chatted about a personal data exporter design that could support WooCommerce and its extensions needs (and be applicable to core itself or any plugin)

In a nutshell, we eventually thought it would be best to try having plugins (and extensions) register a callback function(s) for the export of personal data, e.g. have a plugin do something like this):

add_filter( "wp_privacy_register_export_data_callback", array( $this, 'register_export_data_callback' ) );
 
function register_export_data_callback( $export_callbacks ) {
    $export_callbacks[] = array(
        'slug' => 'stripe',
        'plugin_friendly_name' => __( 'Stripe Payments for WooCommerce' ),
        'callback' => array( $this, 'export_data' )
    );
    return $export_callbacks;
}

The plugin’s actual data-exporting callback would then look something like this, accepting the search parameter (e.g. the email address to export for) and a page parameter (more about that below).

function export_data( $email_address, $page ) {
    // do something here to get the next page of data for the email address given
    return array(
        'data' => array(
            // data goes here
        ),
    'done' => true // or return false if we want to be called again for another page of data
    );
}

For now, we are thinking the data should be super simple, an array of name/value pairs, to keep the barrier to entry low – we could always add more things to the pairs later, e.g:

[
    {
        name: “billing address order #1000”,
        value:  “1444 Seattle Hill Rd”
    },
    {
        name: “billing address order #998”,
        value:  “17725 108th St SE”
    },
]

Then, ajax on a core provided wp-admin page (or the REST API) could be used to fetch a list of all the registered callbacks (and their plugins), e.g. ala:

$registered_callbacks_array = apply_filter( “wp_privacy_register_plugin_export_data_callback”, array() );

and work with each plugin in the $registered_callbacks_array in turn calling its callback(s) to fetch how ever many pages of data that plugin decides to return for the email address of interest.

The web CLIENT would assemble the responses in memory (not the server) and then the user could do whatever they want with the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment