Skip to content

Commit ac27362

Browse files
authored
Allow GravityFormsCLI to be Installed by Packagist (#49)
1 parent 265d442 commit ac27362

File tree

5 files changed

+148
-97
lines changed

5 files changed

+148
-97
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: 15 additions & 1 deletion
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
---------------
@@ -158,7 +172,7 @@ Requirements
158172

159173
1. Wordpress 4.2+
160174
2. Gravity Forms > 1.9.17.8
161-
3. WP-CLI v1.0+
175+
3. WP-CLI v2.5+
162176

163177

164178
Support

class-gf-cli.php

Lines changed: 96 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +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+
}
10+
11+
if ( ! class_exists( 'GFAddOn' ) ) {
12+
return;
13+
}
714

815
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;
16+
/**
17+
* Contains an instance of this class, if available.
18+
*
19+
* @since 1.0-beta-1
20+
* @access private
21+
* @var object $_instance If available, contains an instance of this class
22+
*/
23+
private static $_instance = null;
1724

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';
25+
/**
26+
* Defines the version of the WP-CLI add-on.
27+
*
28+
* @since 1.0-beta-1
29+
* @access protected
30+
* @var string $_version Contains the version, defined from cli.php
31+
*/
32+
protected $_version = GF_CLI_VERSION;
33+
/**
34+
* Defines the minimum Gravity Forms version required.
35+
* @since 1.0-beta-1
36+
* @access protected
37+
* @var string $_min_gravityforms_version The minimum version required.
38+
*/
39+
protected $_min_gravityforms_version = GF_CLI_MIN_GF_VERSION;
40+
/**
41+
* Defines the plugin slug.
42+
*
43+
* @since 1.0-beta-1
44+
* @access protected
45+
* @var string $_slug The slug used for this plugin.
46+
*/
47+
protected $_slug = 'gravityformscli';
48+
/**
49+
* Defines the main plugin file.
50+
*
51+
* @since 1.0-beta-1
52+
* @access protected
53+
* @var string $_path The path to the main plugin file, relative to the plugins folder.
54+
*/
55+
protected $_path = 'gravityformscli/cli.php';
56+
/**
57+
* Defines the full path to this class file.
58+
*
59+
* @since 1.0-beta-1
60+
* @access protected
61+
* @var string $_full_path The full path.
62+
*/
63+
protected $_full_path = __FILE__;
64+
/**
65+
* Defines the URL where this add-on can be found.
66+
*
67+
* @since 1.0-beta-1
68+
* @access protected
69+
* @var string
70+
*/
71+
protected $_url = 'http://www.gravityforms.com';
72+
/**
73+
* Defines the title of this add-on.
74+
*
75+
* @since 1.0-beta-1
76+
* @access protected
77+
* @var string $_title The title of the add-on.
78+
*/
79+
protected $_title = 'Gravity Forms CLI Add-On';
80+
/**
81+
* Defines the short title of the add-on.
82+
*
83+
* @since 1.0-beta-1
84+
* @access protected
85+
* @var string $_short_title The short title.
86+
*/
87+
protected $_short_title = 'CLI';
8188

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

95-
return self::$_instance;
96-
}
102+
return self::$_instance;
103+
}
97104

98-
private function __clone() {
99-
} /* do nothing */
105+
private function __clone() {
106+
} /* do nothing */
100107

101108
}
102109

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: 23 additions & 2 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,24 @@
1521
}
1622
],
1723
"require": {
18-
"php": ">=5.3.29"
24+
"php": ">=5.6",
25+
"wp-cli/wp-cli": "^2.5"
1926
},
2027
"autoload": {
2128
"files": [ "cli.php" ]
29+
},
30+
"extra": {
31+
"commands": [
32+
"gf",
33+
"gf form",
34+
"gf form notification",
35+
"gf form field",
36+
"gf notification",
37+
"gf field",
38+
"gf entry",
39+
"gf entry notification",
40+
"gf license",
41+
"gf tool"
42+
]
2243
}
2344
}

0 commit comments

Comments
 (0)