From d1ace607bfda3c70be49bf2ed282e4d9dbe993f4 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Mon, 8 Feb 2021 15:45:38 -0800 Subject: [PATCH] refactor: use internal function for filter to access local variables --- tablepress-pods.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tablepress-pods.php b/tablepress-pods.php index c4d7ae1..d463016 100644 --- a/tablepress-pods.php +++ b/tablepress-pods.php @@ -3,7 +3,7 @@ Plugin Name: TablePress Extension: Pods tables Plugin URI: https://code.studioinfinity.org/glen/tablepress-pods Description: Custom Extension for TablePress to incorporate Pods information in tables -Version: 0.2.14 +Version: 0.2.15 Author: Glen Whitney Author URI: http://studioinfinity.org/ */ @@ -194,15 +194,23 @@ function playground_handle_exportpods () { if ( ! current_user_can( 'tablepress_export_tables' ) ) { 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 */ $_REQUEST['_wpnonce'] = wp_create_nonce( TablePress::nonce( 'export' ) ); - /* Temporarily set a filter on exporting */ - add_filter( 'tablepress_export_data', 'playground_expand_export_pod', 10, 4); - do_action( 'admin_post_tablepress_export' ); - remove_filter( 'tablepress_export_data', 'playground_expand_export_pod', 10 ); -} + /* Set up the filter using the pod params */ + $pod_name = $export['pod_name'] + $filter = function( $data, $tab, $fmt, $delim ) use ($pod_name) { + return $data . "\nExpanded by " . $pod_name; + } -function playground_expand_export_pod ( $data, $tab, $fmt, $delim ) { - return $data . "\nKilroy was here\n"; + /* Temporarily set a filter on exporting */ + add_filter( 'tablepress_export_data', $filter, 10, 4); + do_action( 'admin_post_tablepress_export' ); + remove_filter( 'tablepress_export_data', $filter, 10 ); }