forked from AxeWP/wp-graphql-gravity-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-graphql-gravity-forms.php
117 lines (101 loc) · 2.84 KB
/
wp-graphql-gravity-forms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Plugin Name: WPGraphQL for Gravity Forms
* Plugin URI: https://github.com/harness-software/wp-graphql-gravity-forms
* GitHub Plugin URI: https://github.com/harness-software/wp-graphql-gravity-forms
* Description: Adds Gravity Forms functionality to the WPGraphQL schema.
* Author: Harness Software
* Author URI: https://www.harnessup.com
* Update URI: https://github.com/harness-software/wp-graphql-gravity-forms/releases
* Version: 0.11.3
* Text Domain: wp-graphql-gravity-forms
* Domain Path: /languages
* Requires at least: 5.4.1
* Tested up to: 6.0.1
* Requires PHP: 7.4
* WPGraphQL requires at least: 1.7.0
* GravityForms requires at least: 2.5.0
* License: GPL-3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* @package WPGraphQL\GF
* @author harnessup
* @license GPL-3
*/
/**
* Define plugin constants.
*/
function gf_graphql_constants() : void {
// Plugin version.
if ( ! defined( 'WPGRAPHQL_GF_VERSION' ) ) {
define( 'WPGRAPHQL_GF_VERSION', '0.11.3' );
}
// Plugin Folder Path.
if ( ! defined( 'WPGRAPHQL_GF_PLUGIN_DIR' ) ) {
define( 'WPGRAPHQL_GF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPGRAPHQL_GF_PLUGIN_URL' ) ) {
define( 'WPGRAPHQL_GF_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'WPGRAPHQL_GF_PLUGIN_FILE' ) ) {
define( 'WPGRAPHQL_GF_PLUGIN_FILE', __FILE__ );
}
// Whether to autoload the files or not.
if ( ! defined( 'WPGRAPHQL_GF_AUTOLOAD' ) ) {
define( 'WPGRAPHQL_GF_AUTOLOAD', true );
}
// Whether to enable untested form fields the files or not.
if ( ! defined( 'WPGRAPHQL_GF_EXPERIMENTAL_FIELDS' ) ) {
define( 'WPGRAPHQL_GF_EXPERIMENTAL_FIELDS', false );
}
}
/**
* Checks if all the the required plugins are installed and activated.
*/
function gf_graphql_dependencies_not_ready() : array {
$deps = [];
if ( ! class_exists( '\WPGraphQL' ) ) {
$deps[] = 'WPGraphQL';
}
if ( ! class_exists( 'GFAPI' ) ) {
$deps[] = 'Gravity Forms';
}
return $deps;
}
/**
* Initializes WPGraphQL for GF.
*
* @return \WPGraphQL\GF\GF|false
*/
function gf_graphql_init() {
gf_graphql_constants();
$not_ready = gf_graphql_dependencies_not_ready();
if ( empty( $not_ready ) && defined( 'WPGRAPHQL_GF_PLUGIN_DIR' ) ) {
require_once WPGRAPHQL_GF_PLUGIN_DIR . 'src/GF.php';
return \WPGraphQL\GF\GF::instance();
}
foreach ( $not_ready as $dep ) {
add_action(
'admin_notices',
function() use ( $dep ) {
?>
<div class="error notice">
<p>
<?php
printf(
/* translators: dependency not ready error message */
esc_html__( '%1$s must be active for WPGraphQL for Gravity Forms to work.', 'wp-graphql-gravity-forms' ),
esc_html( $dep )
);
?>
</p>
</div>
<?php
}
);
}
return false;
}
add_action( 'graphql_init', 'gf_graphql_init' );