Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Forked from premanshup/astra-wp-cli.php
Last active March 23, 2020 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/16d4b24dea31b017fd51dbf6808ceb69 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/16d4b24dea31b017fd51dbf6808ceb69 to your computer and use it in GitHub Desktop.
Delete Astra single option from multisites.
<?php
/**
* Plugin Name: Astra Dev WP CLI
*
* @package Astra Dev
* @since 1.0.0
*/
if ( class_exists( 'WP_CLI_Command' ) && ! class_exists( 'Astra_Dev_WP_CLI' ) ) :
/**
* WP-Cli commands to manage Astra Starter Sites.
*
* @since 1.0.0
*/
class Astra_Dev_WP_CLI extends WP_CLI_Command {
/**
* Delete Astra Settings Key
*
* # Examples
*
* * Single Site
* wp astra-dev delete --key={astra-settings key}
*
* * Multisite
* wp site list --field=url | xargs -n1 -I % wp --url=% astra-dev delete --key={astra-settings key}
*
* @since 1.0.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
*/
public function delete( $args = array(), $assoc_args = array() ) {
$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}' );
}
if( ! function_exists( 'astra_delete_option' ) ) {
WP_CLI::error( 'Function astra_delete_option() not exist.' );
}
astra_delete_option( $option_key );
WP_CLI::log( sprintf( 'Option %s for Site - %s is deleted!', $option_key, get_current_blog_id() ) );
}
}
/**
* Add Command
*/
WP_CLI::add_command( 'astra-dev', 'Astra_Dev_WP_CLI' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment