← All changes
|
includes/admin/export-items/class-charitable-export-items.php
+61
-40
1.7.0.12
→
1.8.13
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * This class is responsible for adding the Charitable admin pages. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Export_Items |
| 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.7.0.7 |
| 10 | 10 | */ |
| 11 | 11 | |
| @@ -36,10 +36,8 @@ | ||
| 36 | 36 | * |
| 37 | 37 | * @since 1.7.0.7 |
| 38 | 38 | */ |
| 39 | 39 | private function __construct() { |
| 40 | - | |
| 41 | - | |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | /** |
| 45 | 43 | * Returns and/or create the single instance of this class. |
| @@ -72,23 +70,23 @@ | ||
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | // Array ( [charitable_nonce] => 56a1cf267c [_wp_http_referer] => /wp-admin/admin.php?page=charitable-settings&tab=tools [charitable_settings] => Array ( [export] => Array ( [export_campaign] => 5 ) ) ) good |
| 75 | 73 | |
| 76 | - if (! isset( $_POST['charitable_nonce'] ) || ! wp_verify_nonce( $_POST['charitable_nonce'], 'export_campaign' ) ) { | |
| 74 | + if ( ! isset( $_POST['charitable_nonce'] ) || ! wp_verify_nonce( $_POST['charitable_nonce'], 'export_campaign' ) ) { // phpcs:ignore | |
| 77 | 75 | return; |
| 78 | 76 | } |
| 79 | 77 | |
| 80 | - if ( ! isset( $_POST['charitable_settings']['tools'] ) ) { | |
| 78 | + if ( ! isset( $_POST['charitable_settings']['export'] ) ) { | |
| 81 | 79 | return; |
| 82 | 80 | } |
| 83 | 81 | |
| 84 | - $export_args = $_POST['charitable_settings']['tools']; | |
| 82 | + $export_args = $_POST['charitable_settings']['export']; // phpcs:ignore | |
| 85 | 83 | |
| 86 | 84 | if ( ! isset( $export_args['export_campaign'] ) || intval( $export_args['export_campaign'] ) === 0 ) { |
| 87 | - if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) { | |
| 88 | - error_log ('admin_accept_export_campaign_request: '); | |
| 89 | - error_log ( print_r( $export_args, true ) ); | |
| 90 | - } | |
| 85 | + if ( charitable_is_debug() ) { | |
| 86 | + error_log( 'admin_accept_export_campaign_request: ' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 87 | + error_log( print_r( $export_args, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log,WordPress.PHP.DevelopmentFunctions.error_log_print_r | |
| 88 | + } | |
| 91 | 89 | return; |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | 92 | // Ignore the user aborting the action. |
| @@ -94,16 +92,16 @@ | ||
| 94 | 92 | // Ignore the user aborting the action. |
| 95 | 93 | ignore_user_abort( true ); |
| 96 | 94 | |
| 97 | 95 | // Grab the proper data. |
| 98 | - $campaign_id = ( isset( $export_args['export_campaign'] ) ) ? absint( $export_args['export_campaign'] ) : false; | |
| 96 | + $campaign_id = ( isset( $export_args['export_campaign'] ) ) ? absint( $export_args['export_campaign'] ) : false; | |
| 99 | 97 | $campaign_post = get_post( $campaign_id ); |
| 100 | 98 | |
| 101 | - // Metadata rows | |
| 102 | - $meta_sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '_campaign_%' AND post_id = " . $campaign_id; | |
| 103 | - $meta_raw = $wpdb->get_results( $wpdb->prepare( $meta_sql ), OBJECT_K ); | |
| 99 | + // Metadata rows. | |
| 100 | + $meta_sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '_campaign_%' AND post_id = " . intval( $campaign_id ); | |
| 101 | + $meta_raw = $wpdb->get_results( $wpdb->prepare( $meta_sql ), OBJECT_K ); // phpcs:ignore | |
| 104 | 102 | |
| 105 | - // author / campaign_creator | |
| 103 | + // author / campaign_creator. | |
| 106 | 104 | $author_data = array(); |
| 107 | 105 | $author_meta = ( $campaign_post->post_author !== 0 ) ? get_userdata( $campaign_post->post_author ) : array(); |
| 108 | 106 | if ( $author_meta ) { |
| 109 | 107 | $author_data = $author_meta->data; |
| @@ -109,17 +107,24 @@ | ||
| 109 | 107 | $author_data = $author_meta->data; |
| 110 | 108 | unset( $author_data->user_pass ); |
| 111 | 109 | } |
| 112 | 110 | |
| 113 | - // categories and tags | |
| 111 | + // categories and tags. | |
| 114 | 112 | $categories = get_the_terms( $campaign_id, 'campaign_category' ); |
| 115 | 113 | $tags = get_the_terms( $campaign_id, 'campaign_tag' ); |
| 116 | 114 | |
| 117 | - // feature image | |
| 115 | + // feature image. | |
| 118 | 116 | $thumbnail = get_the_post_thumbnail_url( $campaign_id, 'full' ); |
| 119 | 117 | |
| 120 | - // Wrapper | |
| 121 | - $data = array( 'post' => $campaign_post, 'meta' => $meta_raw, 'campaign_creator' => $author_data, 'campaign_category' => $categories, 'campaign_tag' => $tags, 'thumbnail' => $thumbnail ); | |
| 118 | + // Wrapper. | |
| 119 | + $data = array( | |
| 120 | + 'post' => $campaign_post, | |
| 121 | + 'meta' => $meta_raw, | |
| 122 | + 'campaign_creator' => $author_data, | |
| 123 | + 'campaign_category' => $categories, | |
| 124 | + 'campaign_tag' => $tags, | |
| 125 | + 'thumbnail' => $thumbnail, | |
| 126 | + ); | |
| 122 | 127 | |
| 123 | 128 | // Allow Addons to add to the Campaign export. |
| 124 | 129 | $data = apply_filters( 'charitable_export_campaign_data', $data, $campaign_id ); |
| 125 | 130 | |
| @@ -130,11 +135,10 @@ | ||
| 130 | 135 | header( 'Expires: 0' ); |
| 131 | 136 | |
| 132 | 137 | // Make the settings downloadable to a JSON file and die. |
| 133 | 138 | die( wp_json_encode( $data ) ); |
| 139 | + } | |
| 134 | 140 | |
| 135 | - } | |
| 136 | - | |
| 137 | 141 | /** |
| 138 | 142 | * This forces the charitable menu to be open for category and tag pages. |
| 139 | 143 | * |
| 140 | 144 | * @since 1.7.0.7 |
| @@ -148,24 +152,22 @@ | ||
| 148 | 152 | if ( ! is_admin() || empty( $_POST ) ) { |
| 149 | 153 | return; |
| 150 | 154 | } |
| 151 | 155 | |
| 152 | - // Array ( [charitable_nonce] => 56a1cf267c [_wp_http_referer] => /wp-admin/admin.php?page=charitable-settings&tab=tools [charitable_settings] => Array ( [export] => Array ( [export_campaign] => 5 ) ) ) good | |
| 153 | - | |
| 154 | - if ( ! isset( $_POST['charitable_nonce'] ) || ! wp_verify_nonce( $_POST['charitable_nonce'], 'export_donations_from_campaign' ) ) { | |
| 156 | + if ( ! isset( $_POST['charitable_nonce'] ) || ! wp_verify_nonce( $_POST['charitable_nonce'], 'export_donations_from_campaign' ) ) { // phpcs:ignore | |
| 155 | 157 | return; |
| 156 | 158 | } |
| 157 | 159 | |
| 158 | - if ( ! isset( $_POST['charitable_settings']['tools'] ) ) { | |
| 160 | + if ( ! isset( $_POST['charitable_settings']['export'] ) ) { | |
| 159 | 161 | return; |
| 160 | 162 | } |
| 161 | 163 | |
| 162 | - $export_args = $_POST['charitable_settings']['tools']; | |
| 164 | + $export_args = $_POST['charitable_settings']['export']; // phpcs:ignore | |
| 163 | 165 | |
| 164 | 166 | if ( ! isset( $export_args['export_donations'] ) || intval( $export_args['export_donations'] ) === 0 ) { |
| 165 | - if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) { | |
| 166 | - error_log ('admin_accept_export_donations_request: '); | |
| 167 | - error_log ( print_r( $export_args, true ) ); | |
| 167 | + if ( charitable_is_debug() ) { | |
| 168 | + error_log( 'admin_accept_export_donations_request: ' ); // phpcs:ignore | |
| 169 | + error_log( print_r( $export_args, true ) ); // phpcs:ignore | |
| 168 | 170 | } |
| 169 | 171 | return; |
| 170 | 172 | } |
| 171 | 173 | |
| @@ -172,14 +174,14 @@ | ||
| 172 | 174 | // Ignore the user aborting the action. |
| 173 | 175 | ignore_user_abort( true ); |
| 174 | 176 | |
| 175 | 177 | // Grab the proper data. |
| 176 | - $campaign_id = ( isset( $export_args['export_donations'] ) ) ? absint( $export_args['export_donations'] ) : false; | |
| 178 | + $campaign_id = ( isset( $export_args['export_donations'] ) ) ? absint( $export_args['export_donations'] ) : false; | |
| 177 | 179 | $campaign_post = get_post( $campaign_id ); |
| 178 | 180 | |
| 179 | - // Metadata rows | |
| 180 | - $meta_sql = "SELECT * FROM " . $wpdb->prefix . "charitable_campaign_donations WHERE campaign_id = " . $campaign_id; | |
| 181 | - $meta_campaign_donations = $wpdb->get_results( $meta_sql, OBJECT_K ); | |
| 181 | + // Metadata rows. | |
| 182 | + $meta_sql = 'SELECT * FROM ' . $wpdb->prefix . 'charitable_campaign_donations WHERE campaign_id = ' . $campaign_id; | |
| 183 | + $meta_campaign_donations = $wpdb->get_results( $meta_sql, OBJECT_K ); // phpcs:ignore | |
| 182 | 184 | |
| 183 | 185 | if ( empty( $meta_campaign_donations ) ) { |
| 184 | 186 | return; |
| 185 | 187 | } |
| @@ -187,9 +189,9 @@ | ||
| 187 | 189 | $campaigns = array(); |
| 188 | 190 | $donations = array(); |
| 189 | 191 | foreach ( $meta_campaign_donations as $index => $campaign_donation ) { |
| 190 | 192 | if ( ! array_key_exists( $campaign_donation->campaign_id, $campaigns ) ) { |
| 191 | - $campaigns[ $campaign_donation->campaign_id ] = array(); | |
| 193 | + $campaigns[ $campaign_donation->campaign_id ] = array(); | |
| 192 | 194 | $campaigns[ $campaign_donation->campaign_id ]['donation_posts'] = array(); |
| 193 | 195 | } |
| 194 | 196 | $donation_post = get_post( $campaign_donation->donation_id ); |
| 195 | 197 | if ( $donation_post ) : |
| @@ -194,9 +196,30 @@ | ||
| 194 | 196 | $donation_post = get_post( $campaign_donation->donation_id ); |
| 195 | 197 | if ( $donation_post ) : |
| 196 | 198 | $campaigns[ $campaign_donation->campaign_id ]['donation_posts'][ $campaign_donation->donation_id ]['post'] = $donation_post; |
| 197 | 199 | $meta_sql = "SELECT * FROM $wpdb->postmeta WHERE post_id = " . $campaign_donation->donation_id; |
| 198 | - $meta_raw = $wpdb->get_results( $meta_sql, ARRAY_A ); | |
| 200 | + $meta_raw = $wpdb->get_results( $meta_sql, ARRAY_A ); // phpcs:ignore | |
| 201 | + | |
| 202 | + // if 'meta_key' of '_donation_log' exists, then we need to dejson the value and remove any html, then rejson it. | |
| 203 | + foreach ( $meta_raw as $meta_key => $meta_value ) { | |
| 204 | + if ( ! empty( $meta_value['meta_key'] ) && $meta_value['meta_key'] === '_donation_log' ) { | |
| 205 | + | |
| 206 | + if ( empty( $meta_value['meta_value'] ) ) { | |
| 207 | + continue; | |
| 208 | + } | |
| 209 | + $donation_log = maybe_unserialize( $meta_value['meta_value'] ); | |
| 210 | + if ( ! empty( $donation_log ) ) { | |
| 211 | + // this is an array. | |
| 212 | + foreach ( $donation_log as $index => $log ) { | |
| 213 | + $donation_log[ $index ] = array_map( 'strip_tags', $log ); | |
| 214 | + } | |
| 215 | + $donation_log = serialize( $donation_log ); | |
| 216 | + $meta_raw[ $meta_key ]['meta_value'] = $donation_log; // phpcs:ignore | |
| 217 | + } | |
| 218 | + | |
| 219 | + } | |
| 220 | + } | |
| 221 | + | |
| 199 | 222 | $campaigns[ $campaign_donation->campaign_id ]['donation_posts'][ $campaign_donation->donation_id ]['meta'] = $meta_raw; |
| 200 | 223 | |
| 201 | 224 | $author_data = false; |
| 202 | 225 | $author_meta = ( $donation_post->post_author !== 0 ) ? get_userdata( $donation_post->post_author ) : false; |
| @@ -207,13 +230,13 @@ | ||
| 207 | 230 | } |
| 208 | 231 | |
| 209 | 232 | $campaigns[ $campaign_donation->campaign_id ]['donation_posts'][ $campaign_donation->donation_id ]['author'] = $author_data; |
| 210 | 233 | endif; |
| 211 | - $campaigns[ $campaign_donation->campaign_id ]['campaign'] = get_post( $campaign_donation->campaign_id ); | |
| 234 | + $campaigns[ $campaign_donation->campaign_id ]['campaign'] = get_post( $campaign_donation->campaign_id ); | |
| 212 | 235 | $campaigns[ $campaign_donation->campaign_id ]['charitable_campaign_donations'] = $meta_campaign_donations; |
| 213 | 236 | } |
| 214 | 237 | |
| 215 | - // Wrapper | |
| 238 | + // Wrapper. | |
| 216 | 239 | $data = array( 'campaigns' => $campaigns ); |
| 217 | 240 | |
| 218 | 241 | // Allow Addons to add to the Campaign export. |
| 219 | 242 | $data = apply_filters( 'charitable_export_campaign_donations_data', $data, $campaign_id ); |
| @@ -225,10 +248,8 @@ | ||
| 225 | 248 | header( 'Expires: 0' ); |
| 226 | 249 | |
| 227 | 250 | // Make the settings downloadable to a JSON file and die. |
| 228 | 251 | die( wp_json_encode( $data ) ); |
| 229 | - | |
| 230 | - } | |
| 231 | - | |
| 252 | + } | |
| 232 | 253 | } |
| 233 | 254 | |
| 234 | 255 | endif; |