From d6a2e1533cf086d4cfdd368dbccd2c18d9e04567 Mon Sep 17 00:00:00 2001 From: isabeldoran Date: Tue, 10 Mar 2026 14:50:58 -0400 Subject: [PATCH] initial changes from #47 & #48 --- .gitattributes | 3 +- README.md | 14 ++++ class-gf-cli.php | 186 ++++++++++++++++++++++++----------------------- cli.php | 16 +++- composer.json | 24 +++++- 5 files changed, 145 insertions(+), 98 deletions(-) diff --git a/.gitattributes b/.gitattributes index f6faf5d..84f0a11 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,4 +6,5 @@ /.gitattributes export-ignore /.gitignore export-ignore /change_log.txt export-ignore -/readme.md export-ignore \ No newline at end of file +/README.md export-ignore +/composer.lock export-ignore \ No newline at end of file diff --git a/README.md b/README.md index 3bf10b2..6c4bcef 100644 --- a/README.md +++ b/README.md @@ -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 --------------- diff --git a/class-gf-cli.php b/class-gf-cli.php index 7845ecd..b9df953 100644 --- a/class-gf-cli.php +++ b/class-gf-cli.php @@ -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 */ + } } diff --git a/cli.php b/cli.php index ac069d9..3948f59 100644 --- a/cli.php +++ b/cli.php @@ -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 ); +} @@ -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' ); @@ -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; } diff --git a/composer.json b/composer.json index 1a17084..9e6bb6f 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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" + ] + } }