Making our plugins WP CLI Friendly

I always thought WP CLI development would be hard.

But I was wrong!

After recieving a ticket from one of our power users, they asked,

"We install Beaver Team Pro via the command line, is there any way we can activate it via CLI?"

So I had a quick dig around, and surprisingly (gutenberg has made me salty) WP CLI is ultra easy to implement!

Below is the code we're adding to all our premium plugins, so that you can activate our plugins via the command line.

WP CLI activation now available in version 1.3.4 of Beaver Team Pro. AB Split Test and WP Shots soon.


# Register a custom 'activate-bt-pro' command to output a supplied positional param.
#
# $ wp activate-bt-pro yourLicenceKey
# Success: Beaver Team Pro activated

/**
 *
 * @when before_wp_load
 */
$activateBtPro = function( $args, $assoc_args ) {

  $licenceKey = $args[0];
  $domain = home_url();

  $plugin = "bt-pro"; // your plugin name
  
  //specific to our plugin, you should replace this stuff with your plugin activate function

  $multisite = is_multisite();
    
  $lstatus  = bt_pro_verify_licence($licenceKey ,$domain,$plugin,$multisite);
  
  if(!empty($lstatus)) // if we have a result
  {
    if( $lstatus->active == 1){ // if we're now active
      WP_CLI::log( $lstatus->status);
      WP_CLI::success( 'BT Pro on '. $domain . ' now: ' . $lstatus->status);
    }
    else
      WP_CLI::error( 'Error activating BT Pro on '. $domain . '. Status: ' . $lstatus->status , $exit = false );

  }

  FLBuilderModel::delete_asset_cache_for_all_posts();

};

if ( class_exists( 'WP_CLI' ) ) {
  WP_CLI::add_command( 'activate-bt-pro', $activateBtPro );
}


Leave a Comment





Level up your Beaver Builder skills

Join 3,264 Beaver Builders and get our monthly-ish dish

We've got a million ideas that we've implemented on over 300+ BB enabled websites. Pop in your email below, and we'll let you know when a new post or plugin is available :)

Newsletter

This field is for validation purposes and should be left unchanged.

Spam sucks.