Skip to content
Open
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: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/change_log.txt export-ignore
/readme.md export-ignore
/README.md export-ignore
/composer.lock export-ignore
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ The Gravity Forms CLI Add-On allows WP-CLI users to manage installation, forms a

[Documentation](https://docs.gravityforms.com/category/add-ons-gravity-forms/wp-cli-add-on/)

Installation
------------
**As a WP-CLI package:**

wp package install gravityforms/gravityformscli

**As a WordPress plugin:**

wp plugin install gravityformscli --activate

**Installing from GitHub:**

wp package install https://github.com/gravityforms/gravityformscli.git


Getting started
---------------
Expand Down
186 changes: 96 additions & 90 deletions class-gf-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,108 @@

defined( 'ABSPATH' ) || defined( 'WP_CLI' ) || die();

// Include the Gravity Forms add-on framework
GFForms::include_addon_framework();
// Include the Gravity Forms add-on framework, if available.
// When running as a standalone WP-CLI package, GFForms is not loaded.
if ( class_exists('GFForms' ) ) {
GFForms::include_addon_framework();
}

class GF_CLI extends GFAddOn {
/**
* Contains an instance of this class, if available.
*
* @since 1.0-beta-1
* @access private
* @var object $_instance If available, contains an instance of this class
*/
private static $_instance = null;
if ( class_exists( 'GFAddOn' ) ) {

/**
* Defines the version of the WP-CLI add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_version Contains the version, defined from cli.php
*/
protected $_version = GF_CLI_VERSION;
/**
* Defines the minimum Gravity Forms version required.
* @since 1.0-beta-1
* @access protected
* @var string $_min_gravityforms_version The minimum version required.
*/
protected $_min_gravityforms_version = GF_CLI_MIN_GF_VERSION;
/**
* Defines the plugin slug.
*
* @since 1.0-beta-1
* @access protected
* @var string $_slug The slug used for this plugin.
*/
protected $_slug = 'gravityformscli';
/**
* Defines the main plugin file.
*
* @since 1.0-beta-1
* @access protected
* @var string $_path The path to the main plugin file, relative to the plugins folder.
*/
protected $_path = 'gravityformscli/cli.php';
/**
* Defines the full path to this class file.
*
* @since 1.0-beta-1
* @access protected
* @var string $_full_path The full path.
*/
protected $_full_path = __FILE__;
/**
* Defines the URL where this add-on can be found.
*
* @since 1.0-beta-1
* @access protected
* @var string
*/
protected $_url = 'http://www.gravityforms.com';
/**
* Defines the title of this add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_title The title of the add-on.
*/
protected $_title = 'Gravity Forms CLI Add-On';
/**
* Defines the short title of the add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_short_title The short title.
*/
protected $_short_title = 'CLI';
class GF_CLI extends GFAddOn {
/**
* Contains an instance of this class, if available.
*
* @since 1.0-beta-1
* @access private
* @var object $_instance If available, contains an instance of this class
*/
private static $_instance = null;

/**
* Returns an instance of this class, and stores it in the $_instance property.
*
* @since 1.0-beta-1
* @access public
* @static
* @return object $_instance An instance of the GF_CLI class
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new GF_CLI();
}
/**
* Defines the version of the WP-CLI add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_version Contains the version, defined from cli.php
*/
protected $_version = GF_CLI_VERSION;
/**
* Defines the minimum Gravity Forms version required.
* @since 1.0-beta-1
* @access protected
* @var string $_min_gravityforms_version The minimum version required.
*/
protected $_min_gravityforms_version = GF_CLI_MIN_GF_VERSION;
/**
* Defines the plugin slug.
*
* @since 1.0-beta-1
* @access protected
* @var string $_slug The slug used for this plugin.
*/
protected $_slug = 'gravityformscli';
/**
* Defines the main plugin file.
*
* @since 1.0-beta-1
* @access protected
* @var string $_path The path to the main plugin file, relative to the plugins folder.
*/
protected $_path = 'gravityformscli/cli.php';
/**
* Defines the full path to this class file.
*
* @since 1.0-beta-1
* @access protected
* @var string $_full_path The full path.
*/
protected $_full_path = __FILE__;
/**
* Defines the URL where this add-on can be found.
*
* @since 1.0-beta-1
* @access protected
* @var string
*/
protected $_url = 'http://www.gravityforms.com';
/**
* Defines the title of this add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_title The title of the add-on.
*/
protected $_title = 'Gravity Forms CLI Add-On';
/**
* Defines the short title of the add-on.
*
* @since 1.0-beta-1
* @access protected
* @var string $_short_title The short title.
*/
protected $_short_title = 'CLI';

return self::$_instance;
}
/**
* Returns an instance of this class, and stores it in the $_instance property.
*
* @since 1.0-beta-1
* @access public
* @static
* @return object $_instance An instance of the GF_CLI class
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new GF_CLI();
}

private function __clone() {
} /* do nothing */
return self::$_instance;
}

private function __clone() {
} /* do nothing */

}
}


Expand Down
16 changes: 12 additions & 4 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
define( 'GF_CLI_MIN_GF_VERSION', '1.9.17.8' );

// After GF is loaded, load the CLI add-on
defined( 'ABSPATH' ) && add_action( 'gform_loaded', array( 'GF_CLI_Bootstrap', 'load_addon' ), 1 );
// When running as a standalone WP-CLI package, add_action is not available.
if ( defined( 'ABSPATH' ) && function_exists( 'add_action' ) ) {
add_action( 'gform_loaded', array( 'GF_CLI_Bootstrap', 'load_addon' ), 1 );
}



Expand All @@ -58,7 +61,8 @@ class GF_CLI_Bootstrap {
public static function load_addon() {

// Requires the class file
require_once( plugin_dir_path( __FILE__ ) . '/class-gf-cli.php' );
// Using dirname() for standalone WP-CLI package compatibility.
require_once( dirname( __FILE__ ) . '/class-gf-cli.php' );

// Registers the class name with GFAddOn
GFAddOn::register( 'GF_CLI' );
Expand Down Expand Up @@ -105,9 +109,13 @@ public static function before_invoke() {
* Returns an instance of the GF_CLI class
*
* @since 1.0-beta-1
* @return object An instance of the GF_CLI class
* @return object|null An instance of the GF_CLI class, or null if not available.
*/
function gf_cli() {
return GF_CLI::get_instance();
if (class_exists( 'GF_CLI' ) ) {
return GF_CLI::get_instance();
}

return null;
}

24 changes: 21 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"name": "gravityforms/gravityformscli",
"description": "A set of WP-CLI commands to manage Gravity Forms.",
"type": "wp-cli-package",
"keywords": [
"wp-cli",
"gravityforms",
"cli",
"wordpress"
],
"homepage": "https://github.com/gravityforms/gravityformscli",
"support": {
"issues": "https://gravityforms.com"
},
"license": "GPLv3",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Rocketgenius",
Expand All @@ -15,9 +21,21 @@
}
],
"require": {
"php": ">=5.3.29"
"php": ">=5.6",
"wp-cli/wp-cli": "^2.5"

},
"autoload": {
"files": [ "cli.php" ]
}
},
"extra": {
"commands": [
"gf",
"gf form",
"gf field",
"gf entry",
"gf license",
"gf tool"
]
}
}