fix: add the data needed by the exportpods action

This commit is contained in:
Glen Whitney 2021-02-08 12:06:36 -08:00
parent 065b0df0ef
commit 30d8b4cd55
2 changed files with 24 additions and 3 deletions

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.6 Version: 0.2.7
Author: Glen Whitney Author: Glen Whitney
Author URI: http ://studioinfinity.org/ Author URI: http ://studioinfinity.org/
*/ */
@ -60,6 +60,7 @@ add_filter( 'tablepress_shortcode_table_default_shortcode_atts',
add_filter( 'tablepress_table_raw_render_data', 'playground_expand_pod', 10, 2 ); add_filter( 'tablepress_table_raw_render_data', 'playground_expand_pod', 10, 2 );
add_filter( 'tablepress_admin_view_actions', 'playground_add_export_pod_action'); add_filter( 'tablepress_admin_view_actions', 'playground_add_export_pod_action');
add_filter( 'tablepress_load_file_full_path', 'playground_exportpods_path', 10, 3); add_filter( 'tablepress_load_file_full_path', 'playground_exportpods_path', 10, 3);
add_filter( 'tablepress_view_data', 'playground_exportpods_data', 10, 2);
function playground_add_shortcode_parameter_pods( $default_atts ) { function playground_add_shortcode_parameter_pods( $default_atts ) {
$default_atts['pod_name'] = ''; $default_atts['pod_name'] = '';
@ -84,6 +85,26 @@ function playground_exportpods_path( $fullpath, $filename, $directory ) {
return plugin_dir_path( __FILE__ ) . $filename; return plugin_dir_path( __FILE__ ) . $filename;
} }
function playground_exportpods_data( $data, $act ) {
if ($action !== 'exportpods') return $data;
// Load all table IDs without priming the post meta cache, as table options/visibility are not needed.
$data['table_ids'] = TablePress::$model_table->load_all( false );
$data['tables_count'] = TablePress::$model_table->count_tables();
if ( ! empty( $_GET['table_id'] ) ) {
$data['export_ids'] = explode( ',', $_GET['table_id'] );
} else {
// Just show empty export form.
$data['export_ids'] = array();
}
$exporter = TablePress::load_class( 'TablePress_Export', 'class-export.php', 'classes' );
$data['zip_support_available'] = $exporter->zip_support_available;
$data['export_formats'] = $exporter->export_formats;
$data['csv_delimiters'] = $exporter->csv_delimiters;
$data['export_format'] = ( ! empty( $_GET['export_format'] ) ) ? $_GET['export_format'] : false;
$data['csv_delimiter'] = ( ! empty( $_GET['csv_delimiter'] ) ) ? $_GET['csv_delimiter'] : _x( ',', 'Default CSV delimiter in the translated language (";", ",", or "tab")', 'tablepress' );
return $data;
}
function playground_expand_pod( $table, $render_options) { function playground_expand_pod( $table, $render_options) {
if (empty($render_options['pod_name'])) return $table; if (empty($render_options['pod_name'])) return $table;
$pod_params = array('limit'=>-1); $pod_params = array('limit'=>-1);

View File

@ -60,11 +60,11 @@ class TablePress_ExportPods_View extends TablePress_View {
public function textbox_head( array $data, array $box ) { public function textbox_head( array $data, array $box ) {
?> ?>
<p> <p>
<?php _e( 'Exporting a table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?> <?php _e( 'Exporting a PODS table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?>
<?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?> <?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?>
</p> </p>
<p> <p>
<?php _e( 'To export, select the tables and the desired export format.', 'tablepress' ); ?> <?php _e( 'To export, select the tables, the PODS parameters, and the desired export format.', 'tablepress' ); ?>
<?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?> <?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?>
<br /> <br />
<?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?> <?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?>