Bin: Add script to deactivate pledges.

This commit is contained in:
Ian Dunn 2022-03-17 14:38:19 -07:00
parent d22f13f2c1
commit 5c0b79fa86
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
2 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,71 @@
<?php
/*
* Deactivate pledges
*
* Usage: wp eval-file deactivate-pledges.php --url=https://wordpress.org/five-for-the-future/
*/
namespace WordPressDotOrg\FiveForTheFuture\Bin;
use function WordPressDotOrg\FiveForTheFuture\Pledge\{ deactivate };
use const WordPressDotOrg\FiveForTheFuture\Pledge\{ DEACTIVE_STATUS };
use WP_Post;
use WP_ClI;
defined( 'WP_CLI' ) || die( 'Nope' );
wp_debug_mode(); // re-set `display_errors` after WP-CLI overrides it, see https://github.com/wp-cli/wp-cli/issues/706#issuecomment-203610437
/** @var string $file The filename of the current script */
/** @var array $args The arguments passed to this script from the command line */
main( $file, $args );
/**
* The main controller
*/
function main( $file, $args ) {
WP_CLI::line();
// The 5ftf plugin has to be loaded.
if ( 'local' !== wp_get_environment_type() && 668 !== get_current_blog_id() ) {
WP_ClI::error( 'This must be ran on the 5ftF site, please use the `--url=https://wordpress.org/five-for-the-future/` argument.' );
}
$emails = array();
$reason = '';
$pledge_ids = array(
);
WP_ClI::warning( sprintf(
"The following pledge IDs will be deactivated: \n\t %s \n\nThe reason is: %s \n",
implode( ', ', $pledge_ids ),
$reason
) );
WP_ClI::confirm( 'Are you sure you want to proceed?' );
foreach ( $pledge_ids as $id ) {
$pledge = get_post( $id );
if ( ! $pledge instanceof WP_Post || '5ftf_pledge' !== $pledge->post_type ) {
WP_ClI::error( "$id is not a pledge post.", false );
continue;
}
// We don't want to email someone twice if they were already deactivated.
if ( DEACTIVE_STATUS === $pledge->post_status ) {
WP_ClI::warning( sprintf( "%s (%d) is already deactivated.", $pledge->post_title, $id ) );
continue;
}
$emails[] = get_post_meta( $id, '5ftf_org-pledge-email', true );
deactivate( $id, false, $reason );
}
WP_CLI::line( "\n" );
WP_CLI::success( 'Done' );
WP_ClI::line( "Email addresses of deactivated organizations: \n" );
WP_ClI::line( implode( ', ', $emails ) );
}

View file

@ -18,6 +18,7 @@ wp_debug_mode(); // re-set `display_errors` after WP-CLI overrides it, see ht
/** @var array $args The arguments passed to this script from the command line */
main( $file, $args );
defined( 'WP_CLI' ) || die( 'Nope' );
/**
* The main controller