| |
| <?php
|
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| require_once( dirname( __FILE__ ) . '/../wp-load.php' );
|
|
|
|
|
| if ( ! current_user_can( 'manage_options' ) ) {
|
|
|
| if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
|
| wp_die( 'You do not have permission to access this page.' );
|
| }
|
| }
|
|
|
|
|
| if ( ! class_exists( 'Charitable' ) ) {
|
| wp_die( 'Charitable plugin is not active.' );
|
| }
|
|
|
|
|
|
|
|
|
| function charitable_delete_all_pending_donations() {
|
| global $wpdb;
|
|
|
|
|
|
|
| $donation_ids = $wpdb->get_col( $wpdb->prepare(
|
| "SELECT ID FROM {$wpdb->posts}
|
| WHERE post_type = %s
|
| AND post_status = %s",
|
| 'donation',
|
| 'charitable-pending'
|
| ) );
|
|
|
| if ( empty( $donation_ids ) ) {
|
| return array(
|
| 'success' => true,
|
| 'count' => 0,
|
| 'message' => 'No pending donations found.'
|
| );
|
| }
|
|
|
| $deleted = 0;
|
| $failed = 0;
|
| $errors = array();
|
|
|
| foreach ( $donation_ids as $donation_id ) {
|
|
|
|
|
|
|
| $result = wp_delete_post( $donation_id, true );
|
|
|
| if ( $result ) {
|
| $deleted++;
|
| } else {
|
| $failed++;
|
| $errors[] = "Failed to delete donation ID: {$donation_id}";
|
| }
|
| }
|
|
|
|
|
| wp_cache_flush();
|
|
|
| return array(
|
| 'success' => true,
|
| 'total' => count( $donation_ids ),
|
| 'deleted' => $deleted,
|
| 'failed' => $failed,
|
| 'errors' => $errors,
|
| 'message' => sprintf(
|
| 'Deleted %d of %d pending donations.',
|
| $deleted,
|
| count( $donation_ids )
|
| )
|
| );
|
| }
|
|
|
|
|
| if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
|
|
|
| if ( ! isset( $_GET['confirm'] ) || 'yes' !== $_GET['confirm'] ) {
|
| ?>
|
| <!DOCTYPE html>
|
| <html>
|
| <head>
|
| <title>Delete Pending Donations</title>
|
| <style>
|
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
|
| .warning { background:
|
| .error { background:
|
| .success { background:
|
| .button { display: inline-block; padding: 10px 20px; background:
|
| .button:hover { background:
|
| .button-secondary { background:
|
| .button-secondary:hover { background:
|
| </style>
|
| </head>
|
| <body>
|
| <h1>Delete All Pending Donations</h1>
|
|
|
| <div class="warning">
|
| <strong>⚠️ WARNING:</strong> This will permanently delete ALL pending donations.
|
| This action cannot be undone. Please ensure you have backed up your database.
|
| </div>
|
|
|
| <?php
|
| global $wpdb;
|
| $count = $wpdb->get_var( $wpdb->prepare(
|
| "SELECT COUNT(*) FROM {$wpdb->posts}
|
| WHERE post_type = %s
|
| AND post_status = %s",
|
| 'donation',
|
| 'charitable-pending'
|
| ) );
|
|
|
| if ( $count > 0 ) {
|
| echo '<p><strong>Pending donations found: ' . esc_html( $count ) . '</strong></p>';
|
| echo '<a href="?confirm=yes" class="button" onclick="return confirm(\'Are you absolutely sure? This cannot be undone!\');">Delete All Pending Donations</a>';
|
| } else {
|
| echo '<div class="success"><strong>No pending donations found.</strong></div>';
|
| }
|
| ?>
|
|
|
| <a href="<?php echo esc_url( admin_url() ); ?>" class="button button-secondary">Cancel - Go to Admin</a>
|
| </body>
|
| </html>
|
| <?php
|
| exit;
|
| }
|
|
|
| // Execute deletion
|
| $result = charitable_delete_all_pending_donations();
|
|
|
| ?>
|
| <!DOCTYPE html>
|
| <html>
|
| <head>
|
| <title>Delete Pending Donations - Results</title>
|
| <style>
|
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
|
| .success { background:
|
| .error { background:
|
| .button { display: inline-block; padding: 10px 20px; background:
|
| </style>
|
| </head>
|
| <body>
|
| <h1>Deletion Results</h1>
|
|
|
| <?php if ( $result['success'] ) : ?>
|
| <div class="success">
|
| <strong>✓ Success!</strong><br>
|
| <?php echo esc_html( $result['message'] ); ?><br>
|
| Total found: <?php echo esc_html( $result['total'] ); ?><br>
|
| Successfully deleted: <?php echo esc_html( $result['deleted'] ); ?><br>
|
| <?php if ( $result['failed'] > 0 ) : ?>
|
| Failed: <?php echo esc_html( $result['failed'] ); ?><br>
|
| <?php endif; ?>
|
| </div>
|
|
|
| <?php if ( ! empty( $result['errors'] ) ) : ?>
|
| <div class="error">
|
| <strong>Errors:</strong><br>
|
| <?php foreach ( $result['errors'] as $error ) : ?>
|
| <?php echo esc_html( $error ); ?><br>
|
| <?php endforeach; ?>
|
| </div>
|
| <?php endif; ?>
|
| <?php else : ?>
|
| <div class="error">
|
| <strong>Error:</strong> <?php echo esc_html( $result['message'] ); ?>
|
| </div>
|
| <?php endif; ?>
|
|
|
| <a href="<?php echo esc_url( admin_url() ); ?>" class="button">Go to Admin</a>
|
| <p><small><strong>IMPORTANT:</strong> Delete this file (delete-pending-donations.php) from your server for security.</small></p>
|
| </body>
|
| </html>
|
| <?php
|
| exit;
|
| }
|
|
|
| // If running via WP-CLI
|
| if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
| $result = charitable_delete_all_pending_donations();
|
|
|
| if ( $result['success'] ) {
|
| WP_CLI::success( $result['message'] );
|
| if ( $result['failed'] > 0 ) {
|
| WP_CLI::warning( "Failed to delete {$result['failed']} donations." );
|
| }
|
| } else {
|
| WP_CLI::error( $result['message'] );
|
| }
|
| }
|
|
|
|
|
| |
| |
Comments