Skip to content

Instantly share code, notes, and snippets.

@premanshup
Created March 17, 2020 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save premanshup/8cee47fdfd1c2ebc7c232976b5ff26b1 to your computer and use it in GitHub Desktop.
Save premanshup/8cee47fdfd1c2ebc7c232976b5ff26b1 to your computer and use it in GitHub Desktop.
Delete Astra single option from multisites.
<?php
// Command - wp delete-astra-option delete --key={astra-settings key}
namespace DeleteAstraOption;
use WP_CLI, WP_CLI_Command;
if( class_exists( 'WP_CLI_Command' ) ) {
class Commands extends WP_CLI_Command {
public function delete( $args, $assoc_args ) {
$option_key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : false;
if( ! $option_key ) {
WP_CLI::error( 'Invalid arguments. Please enter vaild Key, ex. --key={key}' );
}
// Create progress bar.
$progress = \WP_CLI\Utils\make_progress_bar( 'Deleting key and its value from astra-settings ' . $option_key, 0 );
$blog_ids = get_sites();
foreach( $blog_ids as $b ) {
switch_to_blog( $b->blog_id );
// Delete astra-settings option one by one.
astra_delete_option( $option_key );
WP_CLI::log( sprintf( 'Option %s for Site - %s is deleted!', $option_key, $b->blog_id ) );
restore_current_blog();
$progress->tick();
}
$progress->finish();
// Success message.
WP_CLI::success( $option_key . ' astra-settings Option deleted!' );
}
}
WP_CLI::add_command( 'delete-astra-option', 'DeleteAstraOption\Commands' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment