Completed
Push — master ( 9cf7be...029c15 )
by Zack
04:07
created

GravityView_Plugin::include_widget_class()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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 39 and the first side effect is on line 30.

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