Verified Commit 25358b92 authored by Erick Hitter's avatar Erick Hitter
Browse files

Initial setup for plugin's native CLI commands

Includes basics of a purge command
parent b75aa9f0
......@@ -22,6 +22,7 @@ class Main extends Singleton {
require __DIR__ . '/class-internal-events.php';
require __DIR__ . '/class-rest-api.php';
require __DIR__ . '/functions.php';
require __DIR__ . '/wp-cli.php';
// Block normal cron execution
$this->set_constants();
......
<?php
namespace Automattic\WP\Cron_Control;
if ( defined( '\WP_CLI' ) && \WP_CLI ) {
require __DIR__ . '/wp-cli/class-one-time-fixers.php';
}
<?php
namespace Automattic\WP\Cron_Control\CLI;
class One_Time_Fixers extends \WPCOM_VIP_CLI_Command {
/**
* Remove corrupt Cron Control data resulting from initial plugin deployment
*
* eg.: `wp --allow-root cron-control remove-all-plugin-data`
*
* @subcommand remove-all-plugin-data
*/
public function purge( $args, $assoc_args ) {
\WP_CLI::line( 'CRON CONTROL' );
\WP_CLI::line( "This process will remove all CPT data for the Cron Control plugin\n" );
global $wpdb;
$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s LIMIT 250;", 'a8c_cron_ctrl_event' ) );
if ( is_array( $items ) && ! empty( $items ) ) {
foreach ( $items as $item ) {
\WP_CLI::line( "{$item->ID}, `{$item->post_title}`" );
if ( isset( $assoc_args['dry-run'] ) && 'false' === $assoc_args['dry-run'] ) {
\WP_CLI::line( 'Removing...' );
wp_delete_post( $item->ID, true );
\WP_CLI::line( '' );
}
}
}
if ( isset( $assoc_args['dry-run'] ) && 'false' === $assoc_args['dry-run'] ) {
wp_cache_delete( 'a8c_cron_ctrl_option' );
\WP_CLI::line( "Cleared Cron Control cache\n" );
}
\WP_CLI::line( "\nAll done" );
}
}
\WP_CLI::add_command( 'cron-control', 'Automattic\WP\Cron_Control\CLI\One_Time_Fixers' );
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment