Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
= 1.3.1 =
- Added support for using `--version=beta` with the `wp gf install` and `wp gf update` commands. Add-On beta releases are not currently supported.

= 1.3 =
- Fixed an error occurring when using the `wp gf form notification create` command.

Expand Down
4 changes: 2 additions & 2 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Gravity Forms CLI
Plugin URI: https://gravityforms.com
Description: Manage Gravity Forms with the WP CLI.
Version: 1.3
Version: 1.3.1
Author: Rocketgenius
Author URI: https://gravityforms.com
License: GPL-2.0+
Expand All @@ -30,7 +30,7 @@
defined( 'ABSPATH' ) || die();

// Defines the current version of the CLI add-on
define( 'GF_CLI_VERSION', '1.3' );
define( 'GF_CLI_VERSION', '1.3.1' );

define( 'GF_CLI_MIN_GF_VERSION', '1.9.17.8' );

Expand Down
92 changes: 74 additions & 18 deletions includes/class-gf-cli-root.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GF_CLI_Root extends WP_CLI_Command {
* wp gf version gravityformspolls
*/
public function version( $args, $assoc_args ) {
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
$slug = $this->get_slug( $args );

if ( $slug == 'gravityforms' ) {
if ( class_exists( 'GFForms' ) ) {
Expand All @@ -51,7 +51,7 @@ public function version( $args, $assoc_args ) {
}

if ( ! $addon_found ) {
WP_CLI::error( 'Invalid pluging slug: ' . $slug );
WP_CLI::error( 'Invalid plugin slug: ' . $slug );
}
}
}
Expand All @@ -71,7 +71,7 @@ public function version( $args, $assoc_args ) {
* : The license key if not already available in the GF_LICENSE_KEY constant.
*
* [--version=<version>]
* : The version to be installed. Accepted values: auto-update, hotfix. Default: hotfix.
* : The version to be installed. Accepted values: auto-update, hotfix, or beta. Default: hotfix.
*
* [--force]
* : If set, the command will overwrite any installed version of the plugin, without prompting for confirmation.
Expand All @@ -92,9 +92,8 @@ public function version( $args, $assoc_args ) {
* @synopsis [<slug>] [--key=<key>] [--version=<version>] [--force] [--activate] [--activate-network]
*/
public function install( $args, $assoc_args ) {
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';

$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
$slug = $this->get_slug( $args, true );
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();

if ( empty( $key ) ) {
WP_CLI::error( 'A valid license key must be specified either in the GF_LICENSE_KEY constant or the --key option.' );
Expand All @@ -104,9 +103,8 @@ public function install( $args, $assoc_args ) {

$key = md5( $key );

$plugin_info = $this->get_plugin_info( $slug, $key );

$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
$plugin_info = $version === 'beta' ? $this->get_beta_plugin_info( $slug, $key ) : $this->get_plugin_info( $slug, $key );

if ( $version == 'hotfix' ) {
$download_url = isset( $plugin_info['download_url_latest'] ) ? $plugin_info['download_url_latest'] : '';
Expand Down Expand Up @@ -171,7 +169,7 @@ public function install( $args, $assoc_args ) {
* : The license key if not already available in the GF_LICENSE_KEY constant.
*
* [--version=<version>]
* : The version to be installed. Accepted values: auto-update, hotfix. Default: hotfix.
* : The version to be installed. Accepted values: auto-update, hotfix, or beta. Default: hotfix.
*
*
* ## EXAMPLES
Expand All @@ -187,9 +185,8 @@ public function update( $args, $assoc_args ) {
WP_CLI::error( 'Gravity Forms is not active.' );
}

$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';

$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
$slug = $this->get_slug( $args, true );
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();

if ( empty( $key ) ) {
$key = GFCommon::get_key();
Expand All @@ -202,9 +199,8 @@ public function update( $args, $assoc_args ) {
WP_CLI::error( 'A valid license key must be saved in the settings or specified in the GF_LICENSE_KEY constant or the --key option.' );
}

$plugin_info = $this->get_plugin_info( $slug, $key );

$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
$plugin_info = $version === 'beta' ? $this->get_beta_plugin_info( $slug, $key ) : $this->get_plugin_info( $slug, $key );

if ( $version == 'hotfix' ) {
$available_version = isset( $plugin_info['version_latest'] ) ? $plugin_info['version_latest'] : '';
Expand Down Expand Up @@ -266,7 +262,7 @@ public function update( $args, $assoc_args ) {
*/
public function setup( $args, $assoc_args ) {

$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
$slug = $this->get_slug( $args );

$force = WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );

Expand Down Expand Up @@ -321,7 +317,7 @@ public function setup( $args, $assoc_args ) {
* @alias check-update
*/
public function check_update( $args, $assoc_args ) {
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
$slug = $this->get_slug( $args );

$plugin_info = $this->get_plugin_info( $slug );

Expand Down Expand Up @@ -381,4 +377,64 @@ private function get_plugin_info( $slug, $key = '' ) {
$plugin_info = unserialize( $body );
return $plugin_info;
}

/**
* Gets the plugin info for beta releases.
*
* @since 1.4
*
* @param string $slug The plugin or add-on slug.
* @param string $key The license key.
*
* @return mixed
* @throws \WP_CLI\ExitException
*/
private function get_beta_plugin_info( $slug, $key = '' ) {
if ( $slug !== 'gravityforms' ) {
WP_CLI::error( '--version=beta is not currently supported by add-ons.' );
}

$beta_info = $this->get_plugin_info( $slug . '-beta', $key );
$beta_version = isset( $beta_info['version'] ) ? $beta_info['version'] : '';
$no_beta_msg = 'There is no beta release available at this time.';

if ( empty( $beta_version ) ) {
WP_CLI::error( $no_beta_msg );
}

$stable_info = $this->get_plugin_info( $slug, $key );
$stable_version = isset( $stable_info['version'] ) ? $stable_info['version'] : '';

if ( $stable_version && version_compare( $stable_version, $beta_version, '>=' ) ) {
WP_CLI::error( $no_beta_msg );
}

return $beta_info;
}

/**
* Gets the plugin slug for the current command.
*
* @since 1.4
*
* @param array $args The command arguments.
* @param false $beta_check Should we check for the -beta suffix and display an error if found?
*
* @return string
* @throws \WP_CLI\ExitException
*/
private function get_slug( $args, $beta_check = false ) {
if ( empty( $args[0] ) ) {
return 'gravityforms';
}

$slug = $args[0];

if ( $beta_check && strpos( $slug, '-beta' ) ) {
WP_CLI::error( 'Appending -beta to the slug is not supported. Use --version=beta instead.' );
}

return $slug;
}

}
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ If you have any ideas for improvements please submit your idea at https://www.gr

== ChangeLog ==

= 1.3.1 =
- Added support for using `--version=beta` with the `wp gf install` and `wp gf update` commands. Add-On beta releases are not currently supported.

= 1.3 =
- Fixed an error occurring when using the `wp gf form notification create` command.

Expand Down