|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GV; |
|
4
|
|
|
|
|
5
|
|
|
/** If this file is called directly, abort. */ |
|
6
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7
|
|
|
die(); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The GravityView WordPress plugin class. |
|
12
|
|
|
* |
|
13
|
|
|
* Contains functionality related to GravityView being |
|
14
|
|
|
* a WordPress plugin and doing WordPress pluginy things. |
|
15
|
|
|
* |
|
16
|
|
|
* Accessible via gravityview()->plugin |
|
17
|
|
|
*/ |
|
18
|
|
|
final class Plugin { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @since 2.0 |
|
22
|
|
|
* @api |
|
23
|
|
|
* @var string The plugin version. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
public static $version = GV_PLUGIN_VERSION; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string Minimum WordPress version. |
|
30
|
|
|
* |
|
31
|
|
|
* GravityView requires at least this version of WordPress to function properly. |
|
32
|
|
|
*/ |
|
33
|
|
|
private static $min_wp_version = GV_MIN_WP_VERSION; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string Minimum WordPress version. |
|
37
|
|
|
* |
|
38
|
|
|
* @since 2.9.3 |
|
39
|
|
|
* |
|
40
|
|
|
* GravityView will require this version of WordPress soon. |
|
41
|
|
|
*/ |
|
42
|
|
|
private static $future_min_wp_version = GV_FUTURE_MIN_WP_VERSION; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string Minimum Gravity Forms version. |
|
46
|
|
|
* |
|
47
|
|
|
* GravityView requires at least this version of Gravity Forms to function properly. |
|
48
|
|
|
*/ |
|
49
|
|
|
public static $min_gf_version = GV_MIN_GF_VERSION; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string Minimum PHP version. |
|
53
|
|
|
* |
|
54
|
|
|
* GravityView requires at least this version of PHP to function properly. |
|
55
|
|
|
*/ |
|
56
|
|
|
private static $min_php_version = GV_MIN_PHP_VERSION; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string|bool Minimum future PHP version. |
|
60
|
|
|
* |
|
61
|
|
|
* GravityView will require this version of PHP soon. False if no future PHP version changes are planned. |
|
62
|
|
|
*/ |
|
63
|
|
|
private static $future_min_php_version = GV_FUTURE_MIN_PHP_VERSION; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var string|bool Minimum future Gravity Forms version. |
|
67
|
|
|
* |
|
68
|
|
|
* GravityView will require this version of Gravity Forms soon. False if no future Gravity Forms version changes are planned. |
|
69
|
|
|
*/ |
|
70
|
|
|
private static $future_min_gf_version = GV_FUTURE_MIN_GF_VERSION; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var \GV\Plugin The \GV\Plugin static instance. |
|
74
|
|
|
*/ |
|
75
|
|
|
private static $__instance = null; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @since 2.0 |
|
79
|
|
|
* @api |
|
80
|
|
|
* @var \GV\Addon_Settings The plugin "addon" settings. |
|
81
|
|
|
* |
|
82
|
|
|
*/ |
|
83
|
|
|
public $settings; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var string The GFQuery functionality identifier. |
|
87
|
|
|
*/ |
|
88
|
|
|
const FEATURE_GFQUERY = 'gfquery'; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var string The joins functionality identifier. |
|
92
|
|
|
*/ |
|
93
|
|
|
const FEATURE_JOINS = 'joins'; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var string The unions functionality identifier. |
|
97
|
|
|
*/ |
|
98
|
|
|
const FEATURE_UNIONS = 'unions'; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var string The REST API functionality identifier. |
|
102
|
|
|
*/ |
|
103
|
|
|
const FEATURE_REST = 'rest_api'; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get the global instance of \GV\Plugin. |
|
107
|
|
|
* |
|
108
|
|
|
* @return \GV\Plugin The global instance of GravityView Plugin. |
|
109
|
|
|
*/ |
|
110
|
|
|
public static function get() { |
|
111
|
|
|
|
|
112
|
|
|
if ( ! self::$__instance instanceof self ) { |
|
113
|
|
|
self::$__instance = new self; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return self::$__instance; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function __construct() { |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Load translations. |
|
123
|
|
|
*/ |
|
124
|
|
|
add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Load some frontend-related legacy files. |
|
128
|
|
|
*/ |
|
129
|
|
|
add_action( 'gravityview/loaded', array( $this, 'include_legacy_frontend' ) ); |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* GFAddOn-backed settings, licensing. |
|
133
|
|
|
*/ |
|
134
|
|
|
add_action( 'plugins_loaded', array( $this, 'load_license_settings' ) ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function load_license_settings() { |
|
138
|
|
|
|
|
139
|
|
|
require_once $this->dir( 'future/includes/class-gv-license-handler.php' ); |
|
140
|
1 |
|
require_once $this->dir( 'future/includes/class-gv-settings-addon.php' ); |
|
141
|
|
|
if ( class_exists( '\GV\Addon_Settings' ) ) { |
|
142
|
1 |
|
$this->settings = new Addon_Settings(); |
|
143
|
|
|
include_once $this->dir( 'includes/class-gravityview-settings.php' ); |
|
144
|
1 |
|
} else { |
|
145
|
|
|
gravityview()->log->notice( '\GV\Addon_Settings not loaded. Missing \GFAddOn.' ); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Check whether Gravity Forms is v2.5-beta or newer |
|
151
|
|
|
* |
|
152
|
|
|
* @return bool |
|
153
|
|
|
* @todo add @since |
|
154
|
|
|
* |
|
155
|
|
|
*/ |
|
156
|
|
|
public function is_GF_25() { |
|
157
|
|
|
|
|
158
|
|
|
return version_compare( '2.5-beta', \GFForms::$version, '<=' ); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Check whether GravityView `is network activated. |
|
163
|
|
|
* |
|
164
|
|
|
* @return bool Whether it's network activated or not. |
|
165
|
|
|
*/ |
|
166
|
|
|
public static function is_network_activated() { |
|
167
|
|
|
|
|
168
|
|
|
$plugin_basename = plugin_basename( GRAVITYVIEW_FILE ); |
|
169
|
|
|
|
|
170
|
|
|
return is_multisite() && ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( $plugin_basename ) ); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Include more legacy stuff. |
|
175
|
|
|
* |
|
176
|
|
|
* @param boolean $force Whether to force the includes. |
|
177
|
|
|
* |
|
178
|
|
|
* @return void |
|
179
|
|
|
*/ |
|
180
|
|
|
public function include_legacy_frontend( $force = false ) { |
|
181
|
|
|
|
|
182
|
|
|
if ( gravityview()->request->is_admin() && ! $force ) { |
|
183
|
|
|
return; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
include_once $this->dir( 'includes/class-gravityview-image.php' ); |
|
187
|
|
|
include_once $this->dir( 'includes/class-template.php' ); |
|
188
|
|
|
include_once $this->dir( 'includes/class-api.php' ); |
|
189
|
|
|
include_once $this->dir( 'includes/class-frontend-views.php' ); |
|
190
|
|
|
include_once $this->dir( 'includes/class-gravityview-change-entry-creator.php' ); |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded |
|
194
|
|
|
* |
|
195
|
|
|
* @deprecated Use `gravityview/loaded` along with \GV\Request::is_admin(), etc. |
|
196
|
|
|
* |
|
197
|
|
|
* Nice place to insert extensions' frontend stuff |
|
198
|
|
|
*/ |
|
199
|
|
|
do_action( 'gravityview_include_frontend_actions' ); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Load more legacy core files. |
|
204
|
|
|
* |
|
205
|
|
|
* @return void |
|
206
|
|
|
*/ |
|
207
|
|
|
public function include_legacy_core() { |
|
208
|
|
|
|
|
209
|
|
|
if ( ! class_exists( '\GravityView_Extension' ) ) { |
|
210
|
|
|
include_once $this->dir( 'includes/class-gravityview-extension.php' ); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
if ( ! gravityview()->plugin->is_compatible() ) { |
|
214
|
|
|
return; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
// Load fields |
|
218
|
|
|
include_once $this->dir( 'includes/fields/class-gravityview-fields.php' ); |
|
219
|
|
|
include_once $this->dir( 'includes/fields/class-gravityview-field.php' ); |
|
220
|
|
|
|
|
221
|
|
|
// Load all field files automatically |
|
222
|
|
|
foreach ( glob( $this->dir( 'includes/fields/class-gravityview-field*.php' ) ) as $gv_field_filename ) { |
|
223
|
|
|
include_once $gv_field_filename; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
include_once $this->dir( 'includes/class-gravityview-entry-approval-status.php' ); |
|
227
|
|
|
include_once $this->dir( 'includes/class-gravityview-entry-approval.php' ); |
|
228
|
|
|
|
|
229
|
|
|
include_once $this->dir( 'includes/class-gravityview-entry-notes.php' ); |
|
230
|
|
|
include_once $this->dir( 'includes/load-plugin-and-theme-hooks.php' ); |
|
231
|
|
|
|
|
232
|
|
|
// Load Extensions |
|
233
|
|
|
// @todo: Convert to a scan of the directory or a method where this all lives |
|
234
|
|
|
include_once $this->dir( 'includes/extensions/edit-entry/class-edit-entry.php' ); |
|
235
|
|
|
include_once $this->dir( 'includes/extensions/delete-entry/class-delete-entry.php' ); |
|
236
|
|
|
include_once $this->dir( 'includes/extensions/duplicate-entry/class-duplicate-entry.php' ); |
|
237
|
|
|
include_once $this->dir( 'includes/extensions/entry-notes/class-gravityview-field-notes.php' ); |
|
238
|
|
|
|
|
239
|
|
|
// Load WordPress Widgets |
|
240
|
|
|
include_once $this->dir( 'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
|
241
|
|
|
|
|
242
|
|
|
// Load GravityView Widgets |
|
243
|
|
|
include_once $this->dir( 'includes/widgets/register-gravityview-widgets.php' ); |
|
244
|
|
|
|
|
245
|
|
|
// Add oEmbed |
|
246
|
|
|
include_once $this->dir( 'includes/class-api.php' ); |
|
247
|
|
|
include_once $this->dir( 'includes/class-oembed.php' ); |
|
248
|
|
|
|
|
249
|
|
|
// Add logging |
|
250
|
|
|
include_once $this->dir( 'includes/class-gravityview-logging.php' ); |
|
251
|
|
|
|
|
252
|
|
|
include_once $this->dir( 'includes/class-ajax.php' ); |
|
253
|
|
|
include_once $this->dir( 'includes/class-gravityview-html-elements.php' ); |
|
254
|
|
|
include_once $this->dir( 'includes/class-frontend-views.php' ); |
|
255
|
|
|
include_once $this->dir( 'includes/class-gravityview-admin-bar.php' ); |
|
256
|
|
|
include_once $this->dir( 'includes/class-gravityview-entry-list.php' ); |
|
257
|
|
|
include_once $this->dir( 'includes/class-gravityview-merge-tags.php' ); |
|
258
|
|
|
/** @since 1.8.4 */ |
|
259
|
|
|
include_once $this->dir( 'includes/class-data.php' ); |
|
260
|
|
|
include_once $this->dir( 'includes/class-gravityview-shortcode.php' ); |
|
261
|
|
|
include_once $this->dir( 'includes/class-gravityview-entry-link-shortcode.php' ); |
|
262
|
|
|
include_once $this->dir( 'includes/class-gvlogic-shortcode.php' ); |
|
263
|
|
|
include_once $this->dir( 'includes/presets/register-default-templates.php' ); |
|
264
|
|
|
|
|
265
|
|
|
if ( class_exists( '\GFFormsModel' ) ) { |
|
266
|
|
|
include_once $this->dir( 'includes/class-gravityview-gfformsmodel.php' ); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Load the translations. |
|
272
|
|
|
* |
|
273
|
|
|
* Order of look-ups: |
|
274
|
|
|
* |
|
275
|
|
|
* 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core) |
|
276
|
|
|
* 2. /wp-content/mu-plugins/gravityview-{locale}.mo |
|
277
|
|
|
* 3. /wp-content/mu-plugins/languages/gravityview-{locale}.mo |
|
278
|
|
|
* 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo |
|
279
|
|
|
* |
|
280
|
|
|
* @return void |
|
281
|
|
|
*/ |
|
282
|
|
|
public function load_textdomain() { |
|
283
|
|
|
|
|
284
|
|
|
$domain = 'gravityview'; |
|
285
|
|
|
|
|
286
|
|
|
// 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core) |
|
287
|
|
|
if ( is_textdomain_loaded( $domain ) ) { |
|
288
|
|
|
return; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
// 2. /wp-content/languages/plugins/gravityview-{locale}.mo |
|
292
|
|
|
// 3. /wp-content/mu-plugins/plugins/languages/gravityview-{locale}.mo |
|
293
|
|
|
$loaded = load_muplugin_textdomain( $domain, '/languages/' ); |
|
294
|
|
|
|
|
295
|
|
|
if ( $loaded ) { |
|
296
|
|
|
return; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
// 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo |
|
300
|
|
|
$loaded = load_plugin_textdomain( $domain, false, $this->relpath( '/languages/' ) ); |
|
301
|
|
|
|
|
302
|
|
|
if ( $loaded ) { |
|
303
|
|
|
return; |
|
304
|
1 |
|
} |
|
305
|
1 |
|
|
|
306
|
|
|
// Pre-4.6 loading |
|
307
|
1 |
|
// TODO: Remove when GV minimum version is WordPress 4.6.0 |
|
308
|
|
|
$locale = apply_filters( 'plugin_locale', ( ( function_exists( 'get_user_locale' ) && is_admin() ) ? get_user_locale() : get_locale() ), 'gravityview' ); |
|
309
|
|
|
|
|
310
|
|
|
$loaded = load_textdomain( 'gravityview', sprintf( '%s/%s-%s.mo', $this->dir( 'languages' ), $domain, $locale ) ); |
|
311
|
|
|
|
|
312
|
1 |
|
if ( $loaded ) { |
|
313
|
1 |
|
return; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
1 |
|
gravityview()->log->error( sprintf( 'Unable to load textdomain for %s locale.', $locale ) ); |
|
317
|
1 |
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
1 |
|
* Register hooks that are fired when the plugin is activated and deactivated. |
|
321
|
|
|
* |
|
322
|
1 |
|
* @return void |
|
323
|
|
|
*/ |
|
324
|
|
|
public function register_activation_hooks() { |
|
325
|
1 |
|
|
|
326
|
|
|
register_activation_hook( $this->dir( 'gravityview.php' ), array( $this, 'activate' ) ); |
|
327
|
|
|
register_deactivation_hook( $this->dir( 'gravityview.php' ), array( $this, 'deactivate' ) ); |
|
328
|
1 |
|
} |
|
329
|
|
|
|
|
330
|
1 |
|
/** |
|
331
|
1 |
|
* Plugin activation function. |
|
332
|
|
|
* |
|
333
|
|
|
* @return void |
|
334
|
|
|
* @internal |
|
335
|
|
|
*/ |
|
336
|
|
|
public function activate() { |
|
337
|
|
|
|
|
338
|
|
|
gravityview(); |
|
339
|
|
|
|
|
340
|
|
|
if ( ! $this->is_compatible() ) { |
|
341
|
|
|
return; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** Register the gravityview post type upon WordPress core init. */ |
|
345
|
|
|
require_once $this->dir( 'future/includes/class-gv-view.php' ); |
|
346
|
|
|
View::register_post_type(); |
|
347
|
|
|
|
|
348
|
|
|
/** Add the entry rewrite endpoint. */ |
|
349
|
|
|
require_once $this->dir( 'future/includes/class-gv-entry.php' ); |
|
350
|
|
|
Entry::add_rewrite_endpoint(); |
|
351
|
|
|
|
|
352
|
114 |
|
/** Flush all URL rewrites. */ |
|
353
|
114 |
|
flush_rewrite_rules(); |
|
354
|
|
|
|
|
355
|
|
|
update_option( 'gv_version', self::$version ); |
|
356
|
|
|
|
|
357
|
|
|
/** Add the transient to redirect to configuration page. */ |
|
358
|
|
|
set_transient( '_gv_activation_redirect', true, 60 ); |
|
359
|
|
|
|
|
360
|
|
|
/** Clear settings transient. */ |
|
361
|
|
|
delete_transient( 'gravityview_edd-activate_valid' ); |
|
362
|
|
|
|
|
363
|
|
|
\GravityView_Roles_Capabilities::get_instance()->add_caps(); |
|
364
|
|
|
} |
|
365
|
1 |
|
|
|
366
|
|
|
/** |
|
367
|
1 |
|
* Plugin deactivation function. |
|
368
|
|
|
* |
|
369
|
1 |
|
* @return void |
|
370
|
|
|
* @internal |
|
371
|
|
|
*/ |
|
372
|
|
|
public function deactivate() { |
|
373
|
|
|
|
|
374
|
|
|
flush_rewrite_rules(); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Retrieve an absolute path within the GravityView plugin directory. |
|
379
|
|
|
* |
|
380
|
|
|
* @since 2.0 |
|
381
|
1 |
|
* |
|
382
|
1 |
|
* @param string $path Optional. Append this extra path component. |
|
383
|
|
|
* @return string The absolute path to the plugin directory. |
|
384
|
|
|
* @api |
|
385
|
|
|
*/ |
|
386
|
|
|
public function dir( $path = '' ) { |
|
387
|
|
|
|
|
388
|
|
|
return wp_normalize_path( GRAVITYVIEW_DIR . ltrim( $path, '/' ) ); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Retrieve a relative path to the GravityView plugin directory from the WordPress plugin directory |
|
393
|
5 |
|
* |
|
394
|
|
|
* @since 2.2.3 |
|
395
|
5 |
|
* |
|
396
|
5 |
|
* @param string $path Optional. Append this extra path component. |
|
397
|
5 |
|
* @return string The relative path to the plugin directory from the plugin directory. |
|
398
|
|
|
* @api |
|
399
|
|
|
*/ |
|
400
|
|
|
public function relpath( $path = '' ) { |
|
401
|
|
|
|
|
402
|
|
|
$dirname = trailingslashit( dirname( plugin_basename( GRAVITYVIEW_FILE ) ) ); |
|
403
|
|
|
|
|
404
|
|
|
return wp_normalize_path( $dirname . ltrim( $path, '/' ) ); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
5 |
|
* Retrieve a URL within the GravityView plugin directory. |
|
409
|
5 |
|
* |
|
410
|
|
|
* @since 2.0 |
|
411
|
|
|
* |
|
412
|
|
|
* @param string $path Optional. Extra path appended to the URL. |
|
413
|
|
|
* @return string The URL to this plugin, with trailing slash. |
|
414
|
|
|
* @api |
|
415
|
|
|
*/ |
|
416
|
|
|
public function url( $path = '/' ) { |
|
417
|
|
|
|
|
418
|
|
|
return plugins_url( $path, $this->dir( 'gravityview.php' ) ); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Is everything compatible with this version of GravityView? |
|
423
|
|
|
* |
|
424
|
|
|
* @since 2.0 |
|
425
|
|
|
* |
|
426
|
|
|
* @return bool |
|
427
|
|
|
* @api |
|
428
|
|
|
*/ |
|
429
|
|
|
public function is_compatible() { |
|
430
|
|
|
|
|
431
|
|
|
return |
|
432
|
|
|
$this->is_compatible_php() |
|
433
|
|
|
&& $this->is_compatible_wordpress() |
|
434
|
5 |
|
&& $this->is_compatible_gravityforms(); |
|
435
|
|
|
} |
|
436
|
5 |
|
|
|
437
|
5 |
|
/** |
|
438
|
|
|
* Is this version of GravityView compatible with the current version of PHP? |
|
439
|
|
|
* |
|
440
|
5 |
|
* @since 2.0 |
|
441
|
|
|
* |
|
442
|
|
|
* @return bool true if compatible, false otherwise. |
|
443
|
|
|
* @api |
|
444
|
|
|
*/ |
|
445
|
|
|
public function is_compatible_php() { |
|
446
|
|
|
|
|
447
|
|
|
return version_compare( $this->get_php_version(), self::$min_php_version, '>=' ); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
5 |
|
* Is this version of GravityView compatible with the future required version of PHP? |
|
452
|
5 |
|
* |
|
453
|
5 |
|
* @since 2.0 |
|
454
|
|
|
* |
|
455
|
|
|
* @return bool true if compatible, false otherwise. |
|
456
|
|
|
* @api |
|
457
|
|
|
*/ |
|
458
|
|
|
public function is_compatible_future_php() { |
|
459
|
|
|
|
|
460
|
|
|
return version_compare( $this->get_php_version(), self::$future_min_php_version, '>=' ); |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* Is this version of GravityView compatible with the current version of WordPress? |
|
465
|
|
|
* |
|
466
|
|
|
* @since 2.0 |
|
467
|
|
|
* |
|
468
|
|
|
* @param string $version Version to check against; otherwise uses GV_MIN_WP_VERSION |
|
469
|
|
|
* |
|
470
|
|
|
* @return bool true if compatible, false otherwise. |
|
471
|
|
|
* @api |
|
472
|
|
|
*/ |
|
473
|
|
|
public function is_compatible_wordpress( $version = null ) { |
|
474
|
|
|
|
|
475
|
|
|
if ( ! $version ) { |
|
|
|
|
|
|
476
|
4 |
|
$version = self::$min_wp_version; |
|
477
|
4 |
|
} |
|
478
|
4 |
|
|
|
479
|
|
|
return version_compare( $this->get_wordpress_version(), $version, '>=' ); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Is this version of GravityView compatible with the future version of WordPress? |
|
484
|
|
|
* |
|
485
|
|
|
* @since 2.9.3 |
|
486
|
|
|
* |
|
487
|
|
|
* @return bool true if compatible, false otherwise |
|
488
|
4 |
|
* @api |
|
489
|
4 |
|
*/ |
|
490
|
4 |
|
public function is_compatible_future_wordpress() { |
|
491
|
|
|
|
|
492
|
|
|
$version = $this->get_wordpress_version(); |
|
493
|
|
|
|
|
494
|
|
|
return $version ? version_compare( $version, self::$future_min_wp_version, '>=' ) : false; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Is this version of GravityView compatible with the current version of Gravity Forms? |
|
499
|
|
|
* |
|
500
|
4 |
|
* @since 2.0 |
|
501
|
4 |
|
* |
|
502
|
|
|
* @return bool true if compatible, false otherwise (or not active/installed). |
|
503
|
|
|
* @api |
|
504
|
|
|
*/ |
|
505
|
|
|
public function is_compatible_gravityforms() { |
|
506
|
4 |
|
|
|
507
|
4 |
|
$version = $this->get_gravityforms_version(); |
|
508
|
|
|
|
|
509
|
|
|
return $version ? version_compare( $version, self::$min_gf_version, '>=' ) : false; |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* Is this version of GravityView compatible with the future version of Gravity Forms? |
|
514
|
|
|
* |
|
515
|
|
|
* @since 2.0 |
|
516
|
|
|
* |
|
517
|
194 |
|
* @return bool true if compatible, false otherwise (or not active/installed). |
|
518
|
194 |
|
* @api |
|
519
|
|
|
*/ |
|
520
|
|
|
public function is_compatible_future_gravityforms() { |
|
521
|
|
|
|
|
522
|
|
|
$version = $this->get_gravityforms_version(); |
|
523
|
194 |
|
|
|
524
|
74 |
|
return $version ? version_compare( $version, self::$future_min_gf_version, '>=' ) : false; |
|
525
|
194 |
|
} |
|
526
|
194 |
|
|
|
527
|
181 |
|
/** |
|
528
|
194 |
|
* Retrieve the current PHP version. |
|
529
|
194 |
|
* |
|
530
|
|
|
* Overridable with GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE during testing. |
|
531
|
|
|
* |
|
532
|
|
|
* @return string The version of PHP. |
|
533
|
|
|
*/ |
|
534
|
|
|
private function get_php_version() { |
|
535
|
|
|
|
|
536
|
|
|
return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] ) ? |
|
537
|
|
|
$GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion(); |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
/** |
|
541
|
|
|
* Retrieve the current WordPress version. |
|
542
|
|
|
* |
|
543
|
|
|
* Overridable with GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE during testing. |
|
544
|
|
|
* |
|
545
|
|
|
* @return string The version of WordPress. |
|
546
|
|
|
*/ |
|
547
|
|
|
private function get_wordpress_version() { |
|
548
|
|
|
|
|
549
|
|
|
return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] ) ? |
|
550
|
|
|
$GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version']; |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* Retrieve the current Gravity Forms version. |
|
555
|
|
|
* |
|
556
|
|
|
* Overridable with GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE during testing. |
|
557
|
|
|
* |
|
558
|
|
|
* @return string|null The version of Gravity Forms or null if inactive. |
|
559
|
|
|
*/ |
|
560
|
|
|
private function get_gravityforms_version() { |
|
561
|
|
|
|
|
562
|
|
|
if ( ! class_exists( '\GFCommon' ) || ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'] ) ) { |
|
563
|
|
|
gravityview()->log->error( 'Gravity Forms is inactive or not installed.' ); |
|
564
|
|
|
|
|
565
|
|
|
return null; |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] ) ? |
|
569
|
|
|
$GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version; |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
/** |
|
573
|
|
|
* Feature support detection. |
|
574
|
|
|
* |
|
575
|
|
|
* @param string $feature Feature name. Check FEATURE_* class constants. |
|
576
|
|
|
* |
|
577
|
|
|
* @return boolean |
|
578
|
|
|
*/ |
|
579
|
|
|
public function supports( $feature ) { |
|
580
|
|
|
|
|
581
|
|
|
if ( ! is_null( $supports = apply_filters( "gravityview/plugin/feature/$feature", null ) ) ) { |
|
582
|
|
|
return $supports; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
switch ( $feature ): |
|
586
|
|
|
case self::FEATURE_GFQUERY: |
|
587
|
|
|
return class_exists( '\GF_Query' ); |
|
588
|
|
|
case self::FEATURE_JOINS: |
|
589
|
|
|
case self::FEATURE_UNIONS: |
|
590
|
|
|
return apply_filters( 'gravityview/query/class', false ) === '\GF_Patched_Query'; |
|
591
|
|
|
case self::FEATURE_REST: |
|
592
|
|
|
return class_exists( '\WP_REST_Controller' ); |
|
593
|
|
|
default: |
|
594
|
|
|
return false; |
|
595
|
|
|
endswitch; |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
/** |
|
599
|
|
|
* Delete GravityView Views, settings, roles, caps, etc. |
|
600
|
|
|
* |
|
601
|
|
|
* @return void |
|
602
|
|
|
*/ |
|
603
|
|
|
public function uninstall() { |
|
604
|
|
|
|
|
605
|
|
|
global $wpdb; |
|
606
|
|
|
|
|
607
|
|
|
$suppress = $wpdb->suppress_errors(); |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* Posts. |
|
611
|
|
|
*/ |
|
612
|
|
|
$items = get_posts( array( |
|
613
|
|
|
'post_type' => 'gravityview', |
|
614
|
|
|
'post_status' => 'any', |
|
615
|
|
|
'numberposts' => - 1, |
|
616
|
|
|
'fields' => 'ids', |
|
617
|
|
|
) ); |
|
618
|
|
|
|
|
619
|
|
|
foreach ( $items as $item ) { |
|
620
|
|
|
wp_delete_post( $item, true ); |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
/** |
|
624
|
|
|
* Meta. |
|
625
|
|
|
*/ |
|
626
|
|
|
$tables = array(); |
|
627
|
|
|
|
|
628
|
|
|
if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) { |
|
629
|
|
|
$tables [] = \GFFormsModel::get_entry_meta_table_name(); |
|
630
|
|
|
} elseif ( ! $this->is_GF_25() ) { |
|
631
|
|
|
$tables [] = \GFFormsModel::get_lead_meta_table_name(); |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
foreach ( $tables as $meta_table ) { |
|
635
|
|
|
$sql = " |
|
636
|
|
|
DELETE FROM $meta_table |
|
637
|
|
|
WHERE ( |
|
638
|
|
|
`meta_key` = 'is_approved' |
|
639
|
|
|
); |
|
640
|
|
|
"; |
|
641
|
|
|
$wpdb->query( $sql ); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
/** |
|
645
|
|
|
* Notes. |
|
646
|
|
|
*/ |
|
647
|
|
|
$tables = array(); |
|
648
|
|
|
|
|
649
|
|
|
if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_notes_table_name' ) ) { |
|
650
|
|
|
$tables[] = \GFFormsModel::get_entry_notes_table_name(); |
|
651
|
|
|
} elseif ( ! $this->is_GF_25() ) { |
|
652
|
|
|
$tables[] = \GFFormsModel::get_lead_notes_table_name(); |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
$disapproved = __( 'Disapproved the Entry for GravityView', 'gravityview' ); |
|
656
|
|
|
$approved = __( 'Approved the Entry for GravityView', 'gravityview' ); |
|
657
|
|
|
|
|
658
|
|
|
$suppress = $wpdb->suppress_errors(); |
|
659
|
|
|
foreach ( $tables as $notes_table ) { |
|
660
|
|
|
$sql = $wpdb->prepare( " |
|
661
|
|
|
DELETE FROM $notes_table |
|
662
|
|
|
WHERE ( |
|
663
|
|
|
`note_type` = 'gravityview' OR |
|
664
|
|
|
`value` = %s OR |
|
665
|
|
|
`value` = %s |
|
666
|
|
|
); |
|
667
|
|
|
", $approved, $disapproved ); |
|
668
|
|
|
$wpdb->query( $sql ); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
$wpdb->suppress_errors( $suppress ); |
|
672
|
|
|
|
|
673
|
|
|
/** |
|
674
|
|
|
* Capabilities. |
|
675
|
|
|
*/ |
|
676
|
|
|
\GravityView_Roles_Capabilities::get_instance()->remove_caps(); |
|
677
|
|
|
|
|
678
|
|
|
/** |
|
679
|
|
|
* Options. |
|
680
|
|
|
*/ |
|
681
|
|
|
delete_option( 'gravityview_cache_blacklist' ); |
|
682
|
|
|
delete_option( 'gv_version_upgraded_from' ); |
|
683
|
|
|
delete_transient( 'gravityview_edd-activate_valid' ); |
|
684
|
|
|
delete_transient( 'gravityview_edd-deactivate_valid' ); |
|
685
|
|
|
delete_transient( 'gravityview_dismissed_notices' ); |
|
686
|
|
|
delete_site_transient( 'gravityview_related_plugins' ); |
|
687
|
|
|
} |
|
688
|
|
|
|
|
689
|
|
|
private function __clone() { |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
private function __wakeup() { |
|
693
|
|
|
} |
|
694
|
|
|
} |
|
695
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: