@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if accessed directly. |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 14 | +if ( ! defined('ABSPATH')) { |
|
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 17 | |
@@ -109,32 +109,32 @@ discard block |
||
| 109 | 109 | $donor_ids = array(); |
| 110 | 110 | |
| 111 | 111 | // Check if the ajax request if running for the first time. |
| 112 | - if ( 1 === (int) $this->step ) { |
|
| 112 | + if (1 === (int) $this->step) { |
|
| 113 | 113 | // Delete all the donation ids. |
| 114 | - $this->delete_option( $this->donation_key ); |
|
| 114 | + $this->delete_option($this->donation_key); |
|
| 115 | 115 | // Delete all the donor ids. |
| 116 | - $this->delete_option( $this->donor_key ); |
|
| 116 | + $this->delete_option($this->donor_key); |
|
| 117 | 117 | |
| 118 | 118 | // Delete all the step and set to 'count' which if the first step in the process of deleting the donors. |
| 119 | - $this->update_option( $this->step_key, 'count' ); |
|
| 119 | + $this->update_option($this->step_key, 'count'); |
|
| 120 | 120 | |
| 121 | 121 | // Delete tha page count of the step. |
| 122 | - $this->update_option( $this->step_on_key, '0' ); |
|
| 122 | + $this->update_option($this->step_on_key, '0'); |
|
| 123 | 123 | } else { |
| 124 | 124 | // Get the old donors list. |
| 125 | - $donor_ids = $this->get_option( $this->donor_key ); |
|
| 125 | + $donor_ids = $this->get_option($this->donor_key); |
|
| 126 | 126 | |
| 127 | 127 | // Get the old donation list. |
| 128 | - $donation_ids = $this->get_option( $this->donation_key ); |
|
| 128 | + $donation_ids = $this->get_option($this->donation_key); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Get the step and check for it if it's on the first step( 'count' ) or not. |
| 132 | 132 | $step = (int) $this->get_step(); |
| 133 | - if ( 1 === $step ) { |
|
| 133 | + if (1 === $step) { |
|
| 134 | 134 | /** |
| 135 | 135 | * Will add or update the donation and donor data by running wp query. |
| 136 | 136 | */ |
| 137 | - $this->count( $step, $donation_ids, $donor_ids ); |
|
| 137 | + $this->count($step, $donation_ids, $donor_ids); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | * @param array $donation_ids Contain the list of all the donation id's that has being add before this |
| 146 | 146 | * @param array $donor_ids Contain the list of all the donors id's that has being add before this |
| 147 | 147 | */ |
| 148 | - private function count( $step, $donation_ids = array(), $donor_ids = array() ) { |
|
| 148 | + private function count($step, $donation_ids = array(), $donor_ids = array()) { |
|
| 149 | 149 | |
| 150 | 150 | // Get the Page count by default it's zero. |
| 151 | 151 | $paged = (int) $this->get_step_page(); |
| 152 | 152 | // Incresed the page count by one. |
| 153 | - ++ $paged; |
|
| 153 | + ++$paged; |
|
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * Filter add to alter the argument before the wp quest run |
| 157 | 157 | */ |
| 158 | - $args = apply_filters( 'give_tools_reset_stats_total_args', array( |
|
| 158 | + $args = apply_filters('give_tools_reset_stats_total_args', array( |
|
| 159 | 159 | 'post_type' => 'give_payment', |
| 160 | 160 | 'post_status' => 'any', |
| 161 | 161 | 'posts_per_page' => $this->per_step, |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | // ONLY TEST MODE TRANSACTIONS!!! |
| 164 | 164 | 'meta_key' => '_give_payment_mode', |
| 165 | 165 | 'meta_value' => 'test' |
| 166 | - ) ); |
|
| 166 | + )); |
|
| 167 | 167 | |
| 168 | 168 | // Reset the post data. |
| 169 | 169 | wp_reset_postdata(); |
| 170 | 170 | // Getting the new donation. |
| 171 | - $donation_posts = new WP_Query( $args ); |
|
| 171 | + $donation_posts = new WP_Query($args); |
|
| 172 | 172 | |
| 173 | 173 | // The Loop. |
| 174 | - if ( $donation_posts->have_posts() ) { |
|
| 175 | - while ( $donation_posts->have_posts() ) { |
|
| 174 | + if ($donation_posts->have_posts()) { |
|
| 175 | + while ($donation_posts->have_posts()) { |
|
| 176 | 176 | $donation_posts->the_post(); |
| 177 | 177 | global $post; |
| 178 | 178 | // Add the donation id in side the array. |
@@ -191,23 +191,23 @@ discard block |
||
| 191 | 191 | $max_num_pages = (int) $donation_posts->max_num_pages; |
| 192 | 192 | |
| 193 | 193 | // Check current page is less then max number of page or not |
| 194 | - if ( $paged < $max_num_pages ) { |
|
| 194 | + if ($paged < $max_num_pages) { |
|
| 195 | 195 | // Update the curretn page virable for the next step |
| 196 | - $this->update_option( $this->step_on_key, $paged ); |
|
| 196 | + $this->update_option($this->step_on_key, $paged); |
|
| 197 | 197 | |
| 198 | 198 | // Calculating percentage. |
| 199 | 199 | $page_remain = $max_num_pages - $paged; |
| 200 | - $this->total_step = (int) $max_num_pages + ( $total_donation / $this->per_step ) + ( ( $page_remain * 2 ) * count( $donor_ids ) ); |
|
| 200 | + $this->total_step = (int) $max_num_pages + ($total_donation / $this->per_step) + (($page_remain * 2) * count($donor_ids)); |
|
| 201 | 201 | $this->step_completed = $paged; |
| 202 | 202 | } else { |
| 203 | - $donation_ids_count = count( $donor_ids ); |
|
| 204 | - $this->update_option( $this->step_key, 'donation' ); |
|
| 205 | - $this->update_option( $this->step_on_key, '0' ); |
|
| 203 | + $donation_ids_count = count($donor_ids); |
|
| 204 | + $this->update_option($this->step_key, 'donation'); |
|
| 205 | + $this->update_option($this->step_on_key, '0'); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $donor_ids = array_unique( $donor_ids ); |
|
| 209 | - $this->update_option( $this->donor_key, $donor_ids ); |
|
| 210 | - $this->update_option( $this->donation_key, $donation_ids ); |
|
| 208 | + $donor_ids = array_unique($donor_ids); |
|
| 209 | + $this->update_option($this->donor_key, $donor_ids); |
|
| 210 | + $this->update_option($this->donation_key, $donation_ids); |
|
| 211 | 211 | |
| 212 | 212 | wp_reset_postdata(); |
| 213 | 213 | } |
@@ -219,34 +219,34 @@ discard block |
||
| 219 | 219 | * @return int |
| 220 | 220 | */ |
| 221 | 221 | public function get_percentage_complete() { |
| 222 | - return ceil( ( 100 * $this->step_completed ) / $this->total_step ); |
|
| 222 | + return ceil((100 * $this->step_completed) / $this->total_step); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | public function process_step() { |
| 226 | 226 | |
| 227 | - if ( ! $this->can_export() ) { |
|
| 228 | - wp_die( __( 'You do not have permission to delete test transactions.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 227 | + if ( ! $this->can_export()) { |
|
| 228 | + wp_die(__('You do not have permission to delete test transactions.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $had_data = $this->get_data(); |
| 232 | 232 | |
| 233 | - if ( $had_data ) { |
|
| 233 | + if ($had_data) { |
|
| 234 | 234 | $this->done = false; |
| 235 | 235 | |
| 236 | 236 | return true; |
| 237 | 237 | } else { |
| 238 | - update_option( 'give_earnings_total', give_get_total_earnings( true ) ); |
|
| 239 | - Give_Cache::delete( Give_Cache::get_key( 'give_estimated_monthly_stats' ) ); |
|
| 238 | + update_option('give_earnings_total', give_get_total_earnings(true)); |
|
| 239 | + Give_Cache::delete(Give_Cache::get_key('give_estimated_monthly_stats')); |
|
| 240 | 240 | |
| 241 | - $this->delete_option( $this->donation_key ); |
|
| 241 | + $this->delete_option($this->donation_key); |
|
| 242 | 242 | |
| 243 | 243 | // Reset the sequential order numbers |
| 244 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
| 245 | - delete_option( 'give_last_payment_number' ); |
|
| 244 | + if (give_get_option('enable_sequential')) { |
|
| 245 | + delete_option('give_last_payment_number'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | $this->done = true; |
| 249 | - $this->message = __( 'Test donor and transactions successfully deleted.', 'give' ); |
|
| 249 | + $this->message = __('Test donor and transactions successfully deleted.', 'give'); |
|
| 250 | 250 | |
| 251 | 251 | return false; |
| 252 | 252 | } |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | public function get_data() { |
| 265 | 265 | |
| 266 | 266 | // Get the donation id's. |
| 267 | - $donation_ids = $this->get_option( $this->donation_key ); |
|
| 267 | + $donation_ids = $this->get_option($this->donation_key); |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Return false id not test donation is found. |
| 271 | 271 | */ |
| 272 | - if ( empty( $donation_ids ) ) { |
|
| 272 | + if (empty($donation_ids)) { |
|
| 273 | 273 | $this->is_empty = true; |
| 274 | 274 | $this->total_step = 1; |
| 275 | 275 | |
@@ -280,81 +280,81 @@ discard block |
||
| 280 | 280 | $step = (int) $this->get_step(); |
| 281 | 281 | |
| 282 | 282 | // get teh donor ids. |
| 283 | - $donor_ids = $this->get_option( $this->donor_key ); |
|
| 283 | + $donor_ids = $this->get_option($this->donor_key); |
|
| 284 | 284 | |
| 285 | 285 | // In step to we delete all the donation in loop. |
| 286 | - if ( 2 === $step ) { |
|
| 286 | + if (2 === $step) { |
|
| 287 | 287 | $pass_to_donor = false; |
| 288 | 288 | $page = (int) $this->get_step_page(); |
| 289 | - $page ++; |
|
| 290 | - $count = count( $donation_ids ); |
|
| 289 | + $page++; |
|
| 290 | + $count = count($donation_ids); |
|
| 291 | 291 | |
| 292 | - $this->total_step = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids ); |
|
| 292 | + $this->total_step = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids); |
|
| 293 | 293 | $this->step_completed = $page; |
| 294 | 294 | |
| 295 | 295 | |
| 296 | - if ( $count > $this->per_step ) { |
|
| 296 | + if ($count > $this->per_step) { |
|
| 297 | 297 | |
| 298 | - $this->update_option( $this->step_on_key, $page ); |
|
| 299 | - $donation_ids = $this->get_delete_ids( $donation_ids, $page ); |
|
| 300 | - $current_page = (int) ceil( $count / $this->per_step ); |
|
| 298 | + $this->update_option($this->step_on_key, $page); |
|
| 299 | + $donation_ids = $this->get_delete_ids($donation_ids, $page); |
|
| 300 | + $current_page = (int) ceil($count / $this->per_step); |
|
| 301 | 301 | |
| 302 | - if ( $page === $current_page ) { |
|
| 302 | + if ($page === $current_page) { |
|
| 303 | 303 | $pass_to_donor = true; |
| 304 | 304 | } |
| 305 | 305 | } else { |
| 306 | 306 | $pass_to_donor = true; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( true === $pass_to_donor ) { |
|
| 310 | - $this->update_option( $this->step_key, 'donor' ); |
|
| 311 | - $this->update_option( $this->step_on_key, '0' ); |
|
| 309 | + if (true === $pass_to_donor) { |
|
| 310 | + $this->update_option($this->step_key, 'donor'); |
|
| 311 | + $this->update_option($this->step_on_key, '0'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | global $wpdb; |
| 315 | - foreach ( $donation_ids as $item ) { |
|
| 315 | + foreach ($donation_ids as $item) { |
|
| 316 | 316 | |
| 317 | 317 | // will delete the payment log first. |
| 318 | - $parent_query = $wpdb->prepare( "SELECT post_id as id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_give_log_payment_id', (int) $item ); |
|
| 319 | - $log_id = $wpdb->get_row( $parent_query, ARRAY_A ); |
|
| 318 | + $parent_query = $wpdb->prepare("SELECT post_id as id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_give_log_payment_id', (int) $item); |
|
| 319 | + $log_id = $wpdb->get_row($parent_query, ARRAY_A); |
|
| 320 | 320 | // Check if payment has it log or not if yes then delete it. |
| 321 | - if ( ! empty( $log_id['id'] ) ) { |
|
| 321 | + if ( ! empty($log_id['id'])) { |
|
| 322 | 322 | // Deleting the payment log. |
| 323 | - wp_delete_post( $log_id['id'], true ); |
|
| 323 | + wp_delete_post($log_id['id'], true); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // Delete the main payment. |
| 327 | - wp_delete_post( $item, true ); |
|
| 327 | + wp_delete_post($item, true); |
|
| 328 | 328 | } |
| 329 | - do_action( 'give_delete_log_cache' ); |
|
| 329 | + do_action('give_delete_log_cache'); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
| 333 | 333 | // Here we delete all the donor |
| 334 | - if ( 3 === $step ) { |
|
| 334 | + if (3 === $step) { |
|
| 335 | 335 | $page = (int) $this->get_step_page(); |
| 336 | - $count = count( $donor_ids ); |
|
| 336 | + $count = count($donor_ids); |
|
| 337 | 337 | |
| 338 | - $this->total_step = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids ); |
|
| 339 | - $this->step_completed = $page + ( count( $donation_ids ) / $this->per_step ); |
|
| 338 | + $this->total_step = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids); |
|
| 339 | + $this->step_completed = $page + (count($donation_ids) / $this->per_step); |
|
| 340 | 340 | |
| 341 | - $args = apply_filters( 'give_tools_reset_stats_total_args', array( |
|
| 341 | + $args = apply_filters('give_tools_reset_stats_total_args', array( |
|
| 342 | 342 | 'post_type' => 'give_payment', |
| 343 | 343 | 'post_status' => 'any', |
| 344 | 344 | 'posts_per_page' => 1, |
| 345 | 345 | 'meta_key' => '_give_payment_mode', |
| 346 | 346 | 'meta_value' => 'live', |
| 347 | - 'author' => $donor_ids[ $page ] |
|
| 348 | - ) ); |
|
| 347 | + 'author' => $donor_ids[$page] |
|
| 348 | + )); |
|
| 349 | 349 | |
| 350 | - $donation_posts = get_posts( $args ); |
|
| 351 | - if ( empty( $donation_posts ) ) { |
|
| 352 | - Give()->donors->delete_by_user_id( $donor_ids[ $page ] ); |
|
| 350 | + $donation_posts = get_posts($args); |
|
| 351 | + if (empty($donation_posts)) { |
|
| 352 | + Give()->donors->delete_by_user_id($donor_ids[$page]); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - $page ++; |
|
| 356 | - $this->update_option( $this->step_on_key, $page ); |
|
| 357 | - if ( $count === $page ) { |
|
| 355 | + $page++; |
|
| 356 | + $this->update_option($this->step_on_key, $page); |
|
| 357 | + if ($count === $page) { |
|
| 358 | 358 | $this->is_empty = false; |
| 359 | 359 | |
| 360 | 360 | return false; |
@@ -366,24 +366,24 @@ discard block |
||
| 366 | 366 | return true; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - public function get_delete_ids( $donation_ids, $page ) { |
|
| 370 | - $index = $page --; |
|
| 371 | - $count = count( $donation_ids ); |
|
| 369 | + public function get_delete_ids($donation_ids, $page) { |
|
| 370 | + $index = $page--; |
|
| 371 | + $count = count($donation_ids); |
|
| 372 | 372 | $temp = 0; |
| 373 | 373 | $current_page = 0; |
| 374 | 374 | $post_delete = $this->per_step; |
| 375 | 375 | $page_donation_id = array(); |
| 376 | 376 | |
| 377 | - foreach ( $donation_ids as $item ) { |
|
| 378 | - $temp ++; |
|
| 379 | - $page_donation_id[ $current_page ][] = $item; |
|
| 380 | - if ( $temp === $post_delete ) { |
|
| 381 | - $current_page ++; |
|
| 377 | + foreach ($donation_ids as $item) { |
|
| 378 | + $temp++; |
|
| 379 | + $page_donation_id[$current_page][] = $item; |
|
| 380 | + if ($temp === $post_delete) { |
|
| 381 | + $current_page++; |
|
| 382 | 382 | $temp = 0; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - return $page_donation_id[ $page ]; |
|
| 386 | + return $page_donation_id[$page]; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * |
| 396 | 396 | * @return mixed Returns the data from the database |
| 397 | 397 | */ |
| 398 | - public function get_option( $key, $defalut_value = false ) { |
|
| 399 | - return get_option( $key, $defalut_value ); |
|
| 398 | + public function get_option($key, $defalut_value = false) { |
|
| 399 | + return get_option($key, $defalut_value); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * |
| 410 | 410 | * @return void |
| 411 | 411 | */ |
| 412 | - public function update_option( $key, $value ) { |
|
| 413 | - update_option( $key, $value, false ); |
|
| 412 | + public function update_option($key, $value) { |
|
| 413 | + update_option($key, $value, false); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | * |
| 423 | 423 | * @return void |
| 424 | 424 | */ |
| 425 | - public function delete_option( $key ) { |
|
| 426 | - delete_option( $key ); |
|
| 425 | + public function delete_option($key) { |
|
| 426 | + delete_option($key); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | * @return int|string |
| 435 | 435 | */ |
| 436 | 436 | private function get_step() { |
| 437 | - $step_key = (string) $this->get_option( $this->step_key, false ); |
|
| 438 | - if ( 'count' === $step_key ) { |
|
| 437 | + $step_key = (string) $this->get_option($this->step_key, false); |
|
| 438 | + if ('count' === $step_key) { |
|
| 439 | 439 | return 1; |
| 440 | - } elseif ( 'donation' === $step_key ) { |
|
| 440 | + } elseif ('donation' === $step_key) { |
|
| 441 | 441 | return 2; |
| 442 | - } elseif ( 'donor' === $step_key ) { |
|
| 442 | + } elseif ('donor' === $step_key) { |
|
| 443 | 443 | return 3; |
| 444 | 444 | } else { |
| 445 | 445 | return $step_key; |
@@ -450,6 +450,6 @@ discard block |
||
| 450 | 450 | * Get the current $page value in the ajax. |
| 451 | 451 | */ |
| 452 | 452 | private function get_step_page() { |
| 453 | - return $this->get_option( $this->step_on_key, false ); |
|
| 453 | + return $this->get_option($this->step_on_key, false); |
|
| 454 | 454 | } |
| 455 | 455 | } |