refactor: use internal function for filter to access local variables

This commit is contained in:
Glen Whitney 2021-02-08 15:45:38 -08:00
parent 9fd7ece471
commit d1ace607bf

View File

@ -3,7 +3,7 @@
Plugin Name: TablePress Extension: Pods tables Plugin Name: TablePress Extension: Pods tables
Plugin URI: https://code.studioinfinity.org/glen/tablepress-pods Plugin URI: https://code.studioinfinity.org/glen/tablepress-pods
Description: Custom Extension for TablePress to incorporate Pods information in tables Description: Custom Extension for TablePress to incorporate Pods information in tables
Version: 0.2.14 Version: 0.2.15
Author: Glen Whitney Author: Glen Whitney
Author URI: http://studioinfinity.org/ Author URI: http://studioinfinity.org/
*/ */
@ -194,15 +194,23 @@ function playground_handle_exportpods () {
if ( ! current_user_can( 'tablepress_export_tables' ) ) { if ( ! current_user_can( 'tablepress_export_tables' ) ) {
wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 );
} }
if ( empty( $_POST['export'] ) || ! is_array( $_POST['export'] ) ) {
TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export' ) );
} else {
$export = wp_unslash( $_POST['export'] );
}
/* Reset the nonce for forwarding the action */ /* Reset the nonce for forwarding the action */
$_REQUEST['_wpnonce'] = wp_create_nonce( TablePress::nonce( 'export' ) ); $_REQUEST['_wpnonce'] = wp_create_nonce( TablePress::nonce( 'export' ) );
/* Temporarily set a filter on exporting */ /* Set up the filter using the pod params */
add_filter( 'tablepress_export_data', 'playground_expand_export_pod', 10, 4); $pod_name = $export['pod_name']
do_action( 'admin_post_tablepress_export' ); $filter = function( $data, $tab, $fmt, $delim ) use ($pod_name) {
remove_filter( 'tablepress_export_data', 'playground_expand_export_pod', 10 ); return $data . "\nExpanded by " . $pod_name;
} }
function playground_expand_export_pod ( $data, $tab, $fmt, $delim ) { /* Temporarily set a filter on exporting */
return $data . "\nKilroy was here\n"; add_filter( 'tablepress_export_data', $filter, 10, 4);
do_action( 'admin_post_tablepress_export' );
remove_filter( 'tablepress_export_data', $filter, 10 );
} }