From 089f0206b4338a1a37d8acd341cb86d16c2cd9d6 Mon Sep 17 00:00:00 2001 From: Hugo Cox Date: Tue, 24 Dec 2024 16:01:44 +0100 Subject: [PATCH] (feat): add PronamicIdealCleanupCommand --- .../Commands/PronamicIdealCleanupCommand.php | 46 +++++++++++++++++++ .../src/Providers/CommandServiceProvider.php | 20 ++++++++ 2 files changed, 66 insertions(+) create mode 100644 htdocs/wp-content/themes/hollandskroon/src/Commands/PronamicIdealCleanupCommand.php create mode 100644 htdocs/wp-content/themes/hollandskroon/src/Providers/CommandServiceProvider.php diff --git a/htdocs/wp-content/themes/hollandskroon/src/Commands/PronamicIdealCleanupCommand.php b/htdocs/wp-content/themes/hollandskroon/src/Commands/PronamicIdealCleanupCommand.php new file mode 100644 index 0000000..31095ad --- /dev/null +++ b/htdocs/wp-content/themes/hollandskroon/src/Commands/PronamicIdealCleanupCommand.php @@ -0,0 +1,46 @@ + 'pronamic_payment', + 'post_status' => 'payment_completed', + 'posts_per_page' => $postsPerPage, + 'paged' => $paged, + 'date_query' => [ + 'before' => '5 days ago', + ], + ]); + + if (!$payments->have_posts()) { + WP_CLI::success('No fulfilled payments found to clean up.'); + } + + foreach ($payments->posts as $payment) { + if (!wp_delete_post($payment->ID, true)) { + WP_CLI::warning('Failed to delete post with ID: ' . $payment->ID); + } + } + + $paged++; + } while ($payments->have_posts()); + + WP_CLI::success('Pronamic fulfilled payments cleaned up successfully.'); + } +} \ No newline at end of file diff --git a/htdocs/wp-content/themes/hollandskroon/src/Providers/CommandServiceProvider.php b/htdocs/wp-content/themes/hollandskroon/src/Providers/CommandServiceProvider.php new file mode 100644 index 0000000..737d7ed --- /dev/null +++ b/htdocs/wp-content/themes/hollandskroon/src/Providers/CommandServiceProvider.php @@ -0,0 +1,20 @@ +