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
11 changes: 9 additions & 2 deletions class-gf-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

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();
}

if ( class_exists( 'GFAddOn' ) ) {

class GF_CLI extends GFAddOn {
/**
Expand Down Expand Up @@ -100,5 +105,7 @@ private function __clone() {

}

} // End class_exists( 'GFAddOn' ) check.



18 changes: 13 additions & 5 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

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 );
// After GF is loaded, load the CLI add-on.
// 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' );
// Use dirname() instead of plugin_dir_path() 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;
}