Completed
Push — develop ( 4659b8...3ce645 )
by Zack
16:21
created

GravityView_Plugin::add_hooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 17.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Plugin Name:       	GravityView
4
 * Plugin URI:        	https://gravityview.co
5
 * Description:       	The best, easiest way to display Gravity Forms entries on your website.
6
 * Version:          	1.19.3
7
 * Author:            	GravityView
8
 * Author URI:        	https://gravityview.co
9
 * Text Domain:       	gravityview
10
 * License:           	GPLv2 or later
11
 * License URI: 		http://www.gnu.org/licenses/gpl-2.0.html
12
 * Domain Path:			/languages
13
 */
14
15
/** If this file is called directly, abort. */
16
if ( ! defined( 'ABSPATH' ) ) {
17
	die;
18
}
19
20
/** Constants */
21
22
/**
23
 * Full path to the GravityView file
24
 * @define "GRAVITYVIEW_FILE" "./gravityview.php"
25
 */
26
define( 'GRAVITYVIEW_FILE', __FILE__ );
27
28
/**
29
 * The URL to this file, with trailing slash
30
 */
31
define( 'GRAVITYVIEW_URL', plugin_dir_url( __FILE__ ) );
32
33
34
/** @define "GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory */
35
define( 'GRAVITYVIEW_DIR', plugin_dir_path( __FILE__ ) );
36
37
/**
38
 * GravityView requires at least this version of Gravity Forms to function properly.
39
 */
40
define( 'GV_MIN_GF_VERSION', '1.9.14' );
41
42
/**
43
 * GravityView requires at least this version of WordPress to function properly.
44
 * @since 1.12
45
 */
46
define( 'GV_MIN_WP_VERSION', '3.5.0' );
47
48
/**
49
 * GravityView requires at least this version of PHP to function properly.
50
 * @since 1.12
51
 */
52
define( 'GV_MIN_PHP_VERSION', '5.2.4' );
53
54
/**
55
 * GravityView will require this version of PHP soon. False if no future PHP version changes are planned.
56
 * @since 1.19.2
57
 * @var string|false
58
 */
59
define( 'GV_FUTURE_MIN_PHP_VERSION', '5.3' );
60
61
/**
62
 * GravityView will soon require at least this version of Gravity Forms to function properly.
63
 * @since 1.19.4
64
 */
65
define( 'GV_FUTURE_MIN_GF_VERSION', '2.0.0-rc-1' );
66
67
68
/** Register hooks that are fired when the plugin is activated and deactivated. */
69
register_activation_hook( __FILE__, array( 'GravityView_Plugin', 'activate' ) );
70
71
register_deactivation_hook( __FILE__, array( 'GravityView_Plugin', 'deactivate' ) );
72
73
/**
74
 * GravityView_Plugin main class.
75
 */
76
final class GravityView_Plugin {
77
78
	const version = '1.19.3';
79
80
	private static $instance;
81
82
	/**
83
	 * Singleton instance
84
	 *
85
	 * @return GravityView_Plugin   GravityView_Plugin object
86
	 */
87
	public static function getInstance() {
0 ignored issues
show
Coding Style introduced by
The function name getInstance is in camel caps, but expected get_instance instead as per the coding standard.
Loading history...
88
89
		if( empty( self::$instance ) ) {
90
			self::$instance = new self;
91
		}
92
93
		return self::$instance;
94
	}
95
96
	private function __construct() {
97
98
		self::require_files();
99
100
		if( ! GravityView_Compatibility::is_valid() ) {
101
			return;
102
		}
103
104
		$this->include_files();
105
106
		$this->add_hooks();
107
	}
108
109
	/**
110
	 * Include files that are required by the plugin
111
	 * @since 1.18
112
	 */
113
	private static function require_files() {
114
		require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' );
115
		require_once( GRAVITYVIEW_DIR . 'includes/class-common.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
116
		require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
117
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' );
118
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' );
119
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' );
120
		require_once( GRAVITYVIEW_DIR .'includes/class-admin.php' );
121
		require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
122
		require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
123
	}
124
125
	/**
126
	 * Add hooks to set up the plugin
127
	 *
128
	 * @since 1.12
129
	 */
130
	private function add_hooks() {
131
		// Load plugin text domain
132
		add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
133
134
		// Load frontend files
135
		add_action( 'init', array( $this, 'frontend_actions' ), 20 );
136
	}
137
138
	/**
139
	 * Include global plugin files
140
	 *
141
	 * @since 1.12
142
	 */
143
	public function include_files() {
144
145
		// Load fields
146
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' );
147
		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
148
149
		// Load all field files automatically
150
		foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) {
151
			include_once( $gv_field_filename );
152
		}
153
154
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' );
155
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-approval.php' );
156
157
		include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' );
158
		include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' );
159
160
		// Load Extensions
161
		// @todo: Convert to a scan of the directory or a method where this all lives
162
		include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' );
163
		include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' );
164
		include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' );
165
166
		// Load WordPress Widgets
167
		include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' );
168
169
		// Load GravityView Widgets
170
		include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' );
171
172
		// Add oEmbed
173
		include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' );
174
175
		// Add logging
176
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' );
177
178
		include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' );
179
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' );
180
		include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' );
181
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' );
182
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' );
183
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
184
		include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' );
185
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' );
186
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' );
187
		include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' );
188
		include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' );
189
190
	}
191
192
	/**
193
	 * Check whether GravityView is network activated
194
	 * @since 1.7.6
195
	 * @return bool
196
	 */
197
	public static function is_network_activated() {
198
		return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
199
	}
200
201
202
	/**
203
	 * Plugin activate function.
204
	 *
205
	 * @access public
206
	 * @static
207
	 * @return void
208
	 */
209
	public static function activate() {
210
211
		self::require_files();
212
213
		// register post types
214
		GravityView_Post_Types::init_post_types();
215
216
		// register rewrite rules
217
		GravityView_Post_Types::init_rewrite();
218
219
		flush_rewrite_rules();
220
221
		// Update the current GV version
222
		update_option( 'gv_version', self::version );
223
224
		// Add the transient to redirect to configuration page
225
		set_transient( '_gv_activation_redirect', true, 60 );
226
227
		// Clear settings transient
228
		delete_transient( 'gravityview_edd-activate_valid' );
229
230
		GravityView_Roles_Capabilities::get_instance()->add_caps();
231
	}
232
233
234
	/**
235
	 * Plugin deactivate function.
236
	 *
237
	 * @access public
238
	 * @static
239
	 * @return void
240
	 */
241
	public static function deactivate() {
242
		flush_rewrite_rules();
243
	}
244
245
	/**
246
	 * Include the extension class
247
	 *
248
	 * @since 1.5.1
249
	 * @return void
250
	 */
251
	public static function include_extension_framework() {
252
		if ( ! class_exists( 'GravityView_Extension' ) ) {
253
			require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' );
254
		}
255
	}
256
257
	/**
258
	 * Load GravityView_Widget class
259
	 *
260
	 * @since 1.7.5.1
261
	 */
262
	public static function include_widget_class() {
263
		include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' );
264
	}
265
266
267
	/**
268
	 * Loads the plugin's translated strings.
269
	 *
270
	 * @access public
271
	 * @return void
272
	 */
273
	public function load_plugin_textdomain() {
274
275
		$loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
276
		
277
		if ( ! $loaded ) {
278
			$loaded = load_muplugin_textdomain( 'gravityview', '/languages/' );
279
		}
280
		if ( ! $loaded ) {
281
			$loaded = load_theme_textdomain( 'gravityview', '/languages/' );
282
		}
283
		if ( ! $loaded ) {
284
			$locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' );
285
			$mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo';
286
			load_textdomain( 'gravityview', $mofile );
287
		}
288
289
	}
290
291
	/**
292
	 * Check if is_admin(), and make sure not DOING_AJAX
293
	 * @since 1.7.5
294
	 * @return bool
295
	 */
296
	public static function is_admin() {
297
298
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
299
300
		return is_admin() && ! $doing_ajax;
301
	}
302
303
	/**
304
	 * Function to launch frontend objects
305
	 *
306
	 * @since 1.17 Added $force param
307
	 *
308
	 * @access public
309
	 *
310
	 * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true
311
	 *
312
	 * @return void
313
	 */
314
	public function frontend_actions( $force = false ) {
315
316
		if( self::is_admin() && ! $force ) { return; }
317
318
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' );
319
		include_once( GRAVITYVIEW_DIR .'includes/class-template.php' );
320
		include_once( GRAVITYVIEW_DIR .'includes/class-api.php' );
321
		include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' );
322
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
323
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
324
325
        /**
326
         * When an entry is created, check if we need to update the custom slug meta
327
         * todo: move this to its own class..
328
         */
329
        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
330
331
		/**
332
		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
333
		 *
334
		 * Nice place to insert extensions' frontend stuff
335
		 */
336
		do_action( 'gravityview_include_frontend_actions' );
337
	}
338
339
	/**
340
	 * helper function to define the default widget areas
341
	 * @todo Move somewhere logical
342
	 * @return array definition for default widget areas
343
	 */
344
	public static function get_default_widget_areas() {
345
		$default_areas = array(
346
			array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
introduced by
Expected 0 spaces between ")" and comma; 1 found
Loading history...
347
			array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected 0 spaces between ")" and comma; 1 found
Loading history...
348
		);
349
350
		/**
351
		 * @filter `gravityview_widget_active_areas` Array of zones available for widgets to be dropped into
352
		 * @param array $default_areas Definition for default widget areas
353
		 */
354
		return apply_filters( 'gravityview_widget_active_areas', $default_areas );
355
	}
356
357
	/** DEBUG */
358
359
    /**
360
     * Logs messages using Gravity Forms logging add-on
361
     * @param  string $message log message
362
     * @param mixed $data Additional data to display
363
     * @return void
364
     */
365
    public static function log_debug( $message, $data = null ){
366
	    /**
367
	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
368
	     * @param string $message Message to display
369
	     * @param mixed $data Supporting data to print alongside it
370
	     */
371
    	do_action( 'gravityview_log_debug', $message, $data );
372
    }
373
374
    /**
375
     * Logs messages using Gravity Forms logging add-on
376
     * @param  string $message log message
377
     * @return void
378
     */
379
    public static function log_error( $message, $data = null ){
380
	    /**
381
	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
382
	     * @param string $message Error message to display
383
	     * @param mixed $data Supporting data to print alongside it
384
	     */
385
    	do_action( 'gravityview_log_error', $message, $data );
386
    }
387
388
} // end class GravityView_Plugin
389
390
add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
391