← All changes
|
includes/abstracts/abstract-class-charitable-export.php
+19
-8
1.7.0
→
1.8.13
View file →
| @@ -3,12 +3,12 @@ | ||
| 3 | 3 | * Abstract class defining Export model. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Export |
| 6 | 6 | * @author David Bisset |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.0.0 |
| 10 | - * @version 1.6.40 | |
| 10 | + * @version 1.8.0.3 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if accessed directly. |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -90,9 +90,9 @@ | ||
| 90 | 90 | * @param string $key The key to set. |
| 91 | 91 | * @param array $data The set of data. |
| 92 | 92 | * @return mixed |
| 93 | 93 | */ |
| 94 | - public function set_custom_field_data( $value, $key, $data ) { | |
| 94 | + public function set_custom_field_data( $value, $key, $data ) { // phpcs:ignore | |
| 95 | 95 | return $value; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| @@ -109,8 +109,9 @@ | ||
| 109 | 109 | /** |
| 110 | 110 | * Export the CSV file. |
| 111 | 111 | * |
| 112 | 112 | * @since 1.0.0 |
| 113 | + * @version 1.8.5 - Added filter for columns and data. | |
| 113 | 114 | * |
| 114 | 115 | * @return void |
| 115 | 116 | */ |
| 116 | 117 | protected function export() { |
| @@ -115,8 +116,18 @@ | ||
| 115 | 116 | */ |
| 116 | 117 | protected function export() { |
| 117 | 118 | $data = array_map( array( $this, 'map_data' ), $this->get_data() ); |
| 118 | 119 | |
| 120 | + /** | |
| 121 | + * Last chance for filtering the data to be exported. | |
| 122 | + * | |
| 123 | + * @since 1.8.5 | |
| 124 | + * | |
| 125 | + * @param array $data The data to be exported. | |
| 126 | + */ | |
| 127 | + $data = apply_filters( 'charitable_export_data', $data ); | |
| 128 | + $columns = apply_filters( 'charitable_export_columns', $this->columns ); | |
| 129 | + | |
| 119 | 130 | $this->print_headers(); |
| 120 | 131 | |
| 121 | 132 | /* Create a file pointer connected to the output stream */ |
| 122 | 133 | $output = fopen( 'php://output', 'w' ); |
| @@ -121,9 +132,9 @@ | ||
| 121 | 132 | /* Create a file pointer connected to the output stream */ |
| 122 | 133 | $output = fopen( 'php://output', 'w' ); |
| 123 | 134 | |
| 124 | 135 | /* Print first row headers. */ |
| 125 | - fputcsv( $output, array_values( $this->columns ) ); | |
| 136 | + fputcsv( $output, array_values( $columns ) ); | |
| 126 | 137 | |
| 127 | 138 | /* Print the data */ |
| 128 | 139 | foreach ( $data as $row ) { |
| 129 | 140 | fputcsv( $output, $row ); |
| @@ -128,9 +139,9 @@ | ||
| 128 | 139 | foreach ( $data as $row ) { |
| 129 | 140 | fputcsv( $output, $row ); |
| 130 | 141 | } |
| 131 | 142 | |
| 132 | - fclose( $output ); | |
| 143 | + fclose( $output ); // phpcs:ignore | |
| 133 | 144 | |
| 134 | 145 | exit(); |
| 135 | 146 | } |
| 136 | 147 | |
| @@ -138,9 +149,9 @@ | ||
| 138 | 149 | * Receives a row of data and maps it to the keys defined in the columns. |
| 139 | 150 | * |
| 140 | 151 | * @since 1.0.0 |
| 141 | 152 | * |
| 142 | - * @param object|array $data | |
| 153 | + * @param object|array $data Data. | |
| 143 | 154 | * @return mixed |
| 144 | 155 | */ |
| 145 | 156 | protected function map_data( $data ) { |
| 146 | 157 | /* Cast the data to array */ |
| @@ -199,9 +210,9 @@ | ||
| 199 | 210 | protected function print_headers() { |
| 200 | 211 | ignore_user_abort( true ); |
| 201 | 212 | |
| 202 | 213 | if ( ! charitable_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
| 203 | - set_time_limit( 0 ); | |
| 214 | + set_time_limit( 0 ); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged | |
| 204 | 215 | } |
| 205 | 216 | |
| 206 | 217 | /* Check for PHP 5.3+ */ |
| 207 | 218 | if ( function_exists( 'get_called_class' ) ) { |
| @@ -212,9 +223,9 @@ | ||
| 212 | 223 | } |
| 213 | 224 | |
| 214 | 225 | nocache_headers(); |
| 215 | 226 | header( 'Content-Type: text/csv; charset=utf-8' ); |
| 216 | - header( 'Content-Disposition: attachment; filename=charitable-export-' . $export . '-' . date( 'm-d-Y' ) . '.csv' ); | |
| 227 | + header( 'Content-Disposition: attachment; filename=charitable-export-' . $export . '-' . date( 'm-d-Y' ) . '.csv' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 217 | 228 | header( 'Expires: 0' ); |
| 218 | 229 | } |
| 219 | 230 | |
| 220 | 231 | /** |