Skip to content

Instantly share code, notes, and snippets.

@premanshup
Created March 24, 2020 10:02
Show Gist options
  • Select an option

  • Save premanshup/4d78e6b72f2fb09ca9c3196c922df809 to your computer and use it in GitHub Desktop.

Select an option

Save premanshup/4d78e6b72f2fb09ca9c3196c922df809 to your computer and use it in GitHub Desktop.
Astra WP CLI Plugin
<?php
/**
* Plugin Name: Astra WP CLI
* Plugin URI: https://www.yourwebsiteurl.com/
* Description: This is the very first plugin I ever created.
* Version: 1.0
* Author: Your Name Here
* Author URI: http://yourwebsiteurl.com/
**/
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