Skip to content

Commit d6a2e15

Browse files
committed
initial changes from #47 & #48
1 parent 9cf035f commit d6a2e15

File tree

5 files changed

+145
-98
lines changed

5 files changed

+145
-98
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
/.gitattributes export-ignore
77
/.gitignore export-ignore
88
/change_log.txt export-ignore
9-
/readme.md export-ignore
9+
/README.md export-ignore
10+
/composer.lock export-ignore

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ The Gravity Forms CLI Add-On allows WP-CLI users to manage installation, forms a
55

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

8+
Installation
9+
------------
10+
**As a WP-CLI package:**
11+
12+
wp package install gravityforms/gravityformscli
13+
14+
**As a WordPress plugin:**
15+
16+
wp plugin install gravityformscli --activate
17+
18+
**Installing from GitHub:**
19+
20+
wp package install https://github.com/gravityforms/gravityformscli.git
21+
822

923
Getting started
1024
---------------

class-gf-cli.php

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,108 @@
22

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

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

8-
class GF_CLI extends GFAddOn {
9-
/**
10-
* Contains an instance of this class, if available.
11-
*
12-
* @since 1.0-beta-1
13-
* @access private
14-
* @var object $_instance If available, contains an instance of this class
15-
*/
16-
private static $_instance = null;
11+
if ( class_exists( 'GFAddOn' ) ) {
1712

18-
/**
19-
* Defines the version of the WP-CLI add-on.
20-
*
21-
* @since 1.0-beta-1
22-
* @access protected
23-
* @var string $_version Contains the version, defined from cli.php
24-
*/
25-
protected $_version = GF_CLI_VERSION;
26-
/**
27-
* Defines the minimum Gravity Forms version required.
28-
* @since 1.0-beta-1
29-
* @access protected
30-
* @var string $_min_gravityforms_version The minimum version required.
31-
*/
32-
protected $_min_gravityforms_version = GF_CLI_MIN_GF_VERSION;
33-
/**
34-
* Defines the plugin slug.
35-
*
36-
* @since 1.0-beta-1
37-
* @access protected
38-
* @var string $_slug The slug used for this plugin.
39-
*/
40-
protected $_slug = 'gravityformscli';
41-
/**
42-
* Defines the main plugin file.
43-
*
44-
* @since 1.0-beta-1
45-
* @access protected
46-
* @var string $_path The path to the main plugin file, relative to the plugins folder.
47-
*/
48-
protected $_path = 'gravityformscli/cli.php';
49-
/**
50-
* Defines the full path to this class file.
51-
*
52-
* @since 1.0-beta-1
53-
* @access protected
54-
* @var string $_full_path The full path.
55-
*/
56-
protected $_full_path = __FILE__;
57-
/**
58-
* Defines the URL where this add-on can be found.
59-
*
60-
* @since 1.0-beta-1
61-
* @access protected
62-
* @var string
63-
*/
64-
protected $_url = 'http://www.gravityforms.com';
65-
/**
66-
* Defines the title of this add-on.
67-
*
68-
* @since 1.0-beta-1
69-
* @access protected
70-
* @var string $_title The title of the add-on.
71-
*/
72-
protected $_title = 'Gravity Forms CLI Add-On';
73-
/**
74-
* Defines the short title of the add-on.
75-
*
76-
* @since 1.0-beta-1
77-
* @access protected
78-
* @var string $_short_title The short title.
79-
*/
80-
protected $_short_title = 'CLI';
13+
class GF_CLI extends GFAddOn {
14+
/**
15+
* Contains an instance of this class, if available.
16+
*
17+
* @since 1.0-beta-1
18+
* @access private
19+
* @var object $_instance If available, contains an instance of this class
20+
*/
21+
private static $_instance = null;
8122

82-
/**
83-
* Returns an instance of this class, and stores it in the $_instance property.
84-
*
85-
* @since 1.0-beta-1
86-
* @access public
87-
* @static
88-
* @return object $_instance An instance of the GF_CLI class
89-
*/
90-
public static function get_instance() {
91-
if ( self::$_instance == null ) {
92-
self::$_instance = new GF_CLI();
93-
}
23+
/**
24+
* Defines the version of the WP-CLI add-on.
25+
*
26+
* @since 1.0-beta-1
27+
* @access protected
28+
* @var string $_version Contains the version, defined from cli.php
29+
*/
30+
protected $_version = GF_CLI_VERSION;
31+
/**
32+
* Defines the minimum Gravity Forms version required.
33+
* @since 1.0-beta-1
34+
* @access protected
35+
* @var string $_min_gravityforms_version The minimum version required.
36+
*/
37+
protected $_min_gravityforms_version = GF_CLI_MIN_GF_VERSION;
38+
/**
39+
* Defines the plugin slug.
40+
*
41+
* @since 1.0-beta-1
42+
* @access protected
43+
* @var string $_slug The slug used for this plugin.
44+
*/
45+
protected $_slug = 'gravityformscli';
46+
/**
47+
* Defines the main plugin file.
48+
*
49+
* @since 1.0-beta-1
50+
* @access protected
51+
* @var string $_path The path to the main plugin file, relative to the plugins folder.
52+
*/
53+
protected $_path = 'gravityformscli/cli.php';
54+
/**
55+
* Defines the full path to this class file.
56+
*
57+
* @since 1.0-beta-1
58+
* @access protected
59+
* @var string $_full_path The full path.
60+
*/
61+
protected $_full_path = __FILE__;
62+
/**
63+
* Defines the URL where this add-on can be found.
64+
*
65+
* @since 1.0-beta-1
66+
* @access protected
67+
* @var string
68+
*/
69+
protected $_url = 'http://www.gravityforms.com';
70+
/**
71+
* Defines the title of this add-on.
72+
*
73+
* @since 1.0-beta-1
74+
* @access protected
75+
* @var string $_title The title of the add-on.
76+
*/
77+
protected $_title = 'Gravity Forms CLI Add-On';
78+
/**
79+
* Defines the short title of the add-on.
80+
*
81+
* @since 1.0-beta-1
82+
* @access protected
83+
* @var string $_short_title The short title.
84+
*/
85+
protected $_short_title = 'CLI';
9486

95-
return self::$_instance;
96-
}
87+
/**
88+
* Returns an instance of this class, and stores it in the $_instance property.
89+
*
90+
* @since 1.0-beta-1
91+
* @access public
92+
* @static
93+
* @return object $_instance An instance of the GF_CLI class
94+
*/
95+
public static function get_instance() {
96+
if ( self::$_instance == null ) {
97+
self::$_instance = new GF_CLI();
98+
}
9799

98-
private function __clone() {
99-
} /* do nothing */
100+
return self::$_instance;
101+
}
102+
103+
private function __clone() {
104+
} /* do nothing */
100105

106+
}
101107
}
102108

103109

cli.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
define( 'GF_CLI_MIN_GF_VERSION', '1.9.17.8' );
3636

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

4043

4144

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

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

6367
// Registers the class name with GFAddOn
6468
GFAddOn::register( 'GF_CLI' );
@@ -105,9 +109,13 @@ public static function before_invoke() {
105109
* Returns an instance of the GF_CLI class
106110
*
107111
* @since 1.0-beta-1
108-
* @return object An instance of the GF_CLI class
112+
* @return object|null An instance of the GF_CLI class, or null if not available.
109113
*/
110114
function gf_cli() {
111-
return GF_CLI::get_instance();
115+
if (class_exists( 'GF_CLI' ) ) {
116+
return GF_CLI::get_instance();
117+
}
118+
119+
return null;
112120
}
113121

composer.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
"name": "gravityforms/gravityformscli",
33
"description": "A set of WP-CLI commands to manage Gravity Forms.",
44
"type": "wp-cli-package",
5+
"keywords": [
6+
"wp-cli",
7+
"gravityforms",
8+
"cli",
9+
"wordpress"
10+
],
511
"homepage": "https://github.com/gravityforms/gravityformscli",
612
"support": {
713
"issues": "https://gravityforms.com"
814
},
9-
"license": "GPLv3",
15+
"license": "GPL-3.0-or-later",
1016
"authors": [
1117
{
1218
"name": "Rocketgenius",
@@ -15,9 +21,21 @@
1521
}
1622
],
1723
"require": {
18-
"php": ">=5.3.29"
24+
"php": ">=5.6",
25+
"wp-cli/wp-cli": "^2.5"
26+
1927
},
2028
"autoload": {
2129
"files": [ "cli.php" ]
22-
}
30+
},
31+
"extra": {
32+
"commands": [
33+
"gf",
34+
"gf form",
35+
"gf field",
36+
"gf entry",
37+
"gf license",
38+
"gf tool"
39+
]
40+
}
2341
}

0 commit comments

Comments
 (0)