Completed
Push — master ( 022e44...5d3455 )
by Zack
08:11 queued 31s
created

GravityView_Admin::get_plugin_status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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 3 and the first side effect is on line 480.

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
class GravityView_Admin {
4
5
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6
7
		if( ! is_admin() ) { return; }
8
9
		// If Gravity Forms isn't active or compatibile, stop loading
10
		if( false === GravityView_Compatibility::is_valid() ) {
11
			return;
12
		}
13
14
		$this->include_required_files();
15
		$this->add_hooks();
16
	}
17
18
	/**
19
	 * @since 1.15
20
	 * @return void
21
	 */
22
	private function include_required_files() {
23
24
		// Migrate Class
25
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-migrate.php' );
26
27
		// Don't load tooltips if on Gravity Forms, otherwise it overrides translations
28
		if( class_exists( 'GFCommon' ) && class_exists( 'GFForms' ) && !GFForms::is_gravity_page() ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
29
			require_once( GFCommon::get_base_path() . '/tooltips.php' );
30
		}
31
32
		require_once( GRAVITYVIEW_DIR . 'includes/admin/metaboxes/class-gravityview-admin-metaboxes.php' );
33
		require_once( GRAVITYVIEW_DIR . 'includes/admin/entry-list.php' );
34
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
35
36
		/** @since 1.15 **/
37
		require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-support-port.php' );
38
39
		/** @since 1.6 */
40
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-duplicate-view.php' );
41
	}
42
43
	/**
44
	 * @since 1.7.5
45
	 * @return void
46
	 */
47
	private function add_hooks() {
48
49
		// Filter Admin messages
50
		add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
51
		add_filter( 'bulk_post_updated_messages', array( $this, 'post_updated_messages' ) );
52
53
		add_filter( 'plugin_action_links_'. plugin_basename( GRAVITYVIEW_FILE ) , array( $this, 'plugin_action_links' ) );
54
55
		add_action( 'plugins_loaded', array( $this, 'backend_actions' ), 100 );
56
57
		//Hooks for no-conflict functionality
58
		add_action( 'wp_print_scripts', array( $this, 'no_conflict_scripts' ), 1000);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
59
		add_action( 'admin_print_footer_scripts', array( $this, 'no_conflict_scripts' ), 9);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
60
61
		add_action( 'wp_print_styles', array( $this, 'no_conflict_styles' ), 1000);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
62
		add_action( 'admin_print_styles', array( $this, 'no_conflict_styles' ), 11);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
63
		add_action( 'admin_print_footer_scripts', array( $this, 'no_conflict_styles' ), 1);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
64
		add_action( 'admin_footer', array( $this, 'no_conflict_styles' ), 1);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
65
66
	}
67
68
	/**
69
	 * Function to launch admin objects
70
	 *
71
	 * @access public
72
	 * @return void
73
	 */
74
	public function backend_actions() {
75
76
		/** @define "GRAVITYVIEW_DIR" "../" */
77
		include_once( GRAVITYVIEW_DIR .'includes/admin/class.field.type.php' );
78
		include_once( GRAVITYVIEW_DIR .'includes/admin/class.render.settings.php' );
79
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-label.php' );
80
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-views.php' );
81
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-welcome.php' );
82
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-add-shortcode.php' );
83
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
84
85
		/**
86
		 * @action `gravityview_include_backend_actions` Triggered after all GravityView admin files are loaded
87
		 *
88
		 * Nice place to insert extensions' backend stuff
89
		 */
90
		do_action('gravityview_include_backend_actions');
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...
91
	}
92
93
	/**
94
	 * Modify plugin action links at plugins screen
95
	 *
96
	 * @since 1.15 Added check for `gravityview_view_settings` and `gravityview_support_port` capabilities
97
	 * @access public
98
	 * @static
99
	 * @param array $links Array of action links under GravityView on the plugin page
100
	 * @return array Action links with Settings and Support included, if the user has the appropriate caps
101
	 */
102
	public static function plugin_action_links( $links ) {
103
104
		$actions = array();
105
106
		if( GVCommon::has_cap( 'gravityview_view_settings' ) ) {
107
			$actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ), esc_html__( 'Settings', 'gravityview' ) );
108
		}
109
110
		if( GVCommon::has_cap( 'gravityview_support_port' ) ) {
111
			$actions[] = '<a href="http://docs.gravityview.co">' . esc_html__( 'Support', 'gravityview' ) . '</a>';
112
		}
113
114
		return array_merge( $actions, $links );
115
	}
116
117
	/**
118
	 * Get an image of our intrepid explorer friend
119
	 * @return string HTML image tag with floaty's cute mug on it
120
	 */
121
	public static function get_floaty() {
122
		return gravityview_get_floaty();
123
	}
124
125
	/**
126
	 * Filter Admin messages
127
	 *
128
	 * @param  array      $messages Existing messages
129
	 * @return array                Messages with GravityView views!
130
	 */
131
	function post_updated_messages( $messages, $bulk_counts = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
132
		global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
133
134
		$post_id = isset($_GET['post']) ? intval($_GET['post']) : ( is_object( $post ) && isset( $post->ID ) ? $post->ID : NULL );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
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...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
135
136
		// By default, there will only be one item being modified.
137
		// When in the `bulk_post_updated_messages` filter, there will be passed a number
138
		// of modified items that will override this array.
139
		$bulk_counts = is_null( $bulk_counts ) ? array( 'updated' => 1 , 'locked' => 1 , 'deleted' => 1 , 'trashed' => 1, 'untrashed' => 1 ) : $bulk_counts;
0 ignored issues
show
introduced by
Expected 0 spaces between "1" and comma; 1 found
Loading history...
140
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
141
142
		// If we're starting fresh, a new form was created.
143
		// We should let the user know this is the case.
144
		$start_fresh = get_post_meta( $post_id, '_gravityview_start_fresh', true );
145
146
		$new_form_text = '';
147
148
		if( !empty( $start_fresh ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
149
150
			// Get the form that was created
151
			$connected_form = gravityview_get_form_id( $post_id );
152
153
			if( !empty( $connected_form ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
154
				$form = gravityview_get_form( $connected_form );
155
				$form_name = esc_attr( $form['title'] );
156
				$image = self::get_floaty();
157
				$new_form_text .= '<h3>'.$image.sprintf( __( 'A new form was created for this View: "%s"', 'gravityview' ), $form_name ).'</h3>';
158
				$new_form_text .=  sprintf( __( '%sThere are no entries for the new form, so the View will also be empty.%s To start collecting entries, you can add submissions through %sthe preview form%s and also embed the form on a post or page using this code: %s
0 ignored issues
show
introduced by
Expected 1 space after ".="; 2 found
Loading history...
159
160
					You can %sedit the form%s in Gravity Forms and the updated fields will be available here. Don&rsquo;t forget to %scustomize the form settings%s.
161
					', 'gravityview' ), '<strong>', '</strong>', '<a href="'.site_url( '?gf_page=preview&amp;id='.$connected_form ).'">', '</a>', '<code>[gravityform id="'.$connected_form.'" name="'.$form_name.'"]</code>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&amp;id='.$connected_form ).'">', '</a>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&amp;view=settings&amp;id='.$connected_form ).'">', '</a>');
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'site_url'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$connected_form'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$form_name'
Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
162
				$new_form_text = wpautop( $new_form_text );
163
164
				delete_post_meta( $post_id, '_gravityview_start_fresh' );
165
			}
166
		}
167
168
		$messages['gravityview'] = array(
169
			0  => '', // Unused. Messages start at index 1.
170
			/* translators: %s and %s are HTML tags linking to the View on the website */
171
			1  => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
172
			/* translators: %s and %s are HTML tags linking to the View on the website */
173
			2  => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
174
			3  => __( 'View deleted.', 'gravityview' ),
175
			/* translators: %s and %s are HTML tags linking to the View on the website */
176
			4  => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
177
			/* translators: %s: date and time of the revision */
178
			5  => isset( $_GET['revision'] ) ? sprintf( __( 'View restored to revision from %s', 'gravityview' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
179
			/* translators: %s and %s are HTML tags linking to the View on the website */
180
			6  => sprintf(__( 'View published. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text,
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$new_form_text'
Loading history...
181
			/* translators: %s and %s are HTML tags linking to the View on the website */
182
			7  => sprintf(__( 'View saved. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text,
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$new_form_text'
Loading history...
183
			8  => __( 'View submitted.', 'gravityview' ),
184
			9  => sprintf(
185
		        /* translators: Date and time the View is scheduled to be published */
186
				__( 'View scheduled for: %1$s.', 'gravityview' ),
187
				// translators: Publish box date format, see http://php.net/date
188
				date_i18n( __( 'M j, Y @ G:i', 'gravityview' ), strtotime( ( isset( $post->post_date ) ? $post->post_date : NULL )  ) )
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 2 found
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
189
			) . $new_form_text,
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$new_form_text'
Loading history...
190
			/* translators: %s and %s are HTML tags linking to the View on the website */
191
			10  => sprintf(__( 'View draft updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'),
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 a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_permalink'
Loading history...
192
193
			/**
194
			 * These apply to `bulk_post_updated_messages`
195
			 * @file wp-admin/edit.php
196
			 */
197
			'updated'   => _n( '%s View updated.', '%s Views updated.', $bulk_counts['updated'], 'gravityview' ),
198
			'locked'    => _n( '%s View not updated, somebody is editing it.', '%s Views not updated, somebody is editing them.', $bulk_counts['locked'], 'gravityview' ),
199
			'deleted'   => _n( '%s View permanently deleted.', '%s Views permanently deleted.', $bulk_counts['deleted'], 'gravityview' ),
200
			'trashed'   => _n( '%s View moved to the Trash.', '%s Views moved to the Trash.', $bulk_counts['trashed'], 'gravityview' ),
201
			'untrashed' => _n( '%s View restored from the Trash.', '%s Views restored from the Trash.', $bulk_counts['untrashed'], 'gravityview' ),
202
		);
203
204
		return $messages;
205
	}
206
207
	/**
208
	 * Callback to eliminate any non-registered script
209
	 * @return void
210
	 */
211
	function no_conflict_scripts() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
212
		global $wp_scripts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
213
214
		if( ! gravityview_is_admin_page() ) {
215
			return;
216
		}
217
218
		$no_conflict_mode = GravityView_Settings::getSetting('no-conflict-mode');
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...
219
220
		if( empty( $no_conflict_mode ) ) {
221
			return;
222
		}
223
224
		$wp_allowed_scripts = array(
225
            'common',
226
            'admin-bar',
227
            'autosave',
228
            'post',
229
			'inline-edit-post',
230
            'utils',
231
            'svg-painter',
232
            'wp-auth-check',
233
            'heartbeat',
234
			'media-editor',
235
			'media-upload',
236
            'thickbox',
237
			'wp-color-picker',
238
239
            // Settings
240
			'gv-admin-edd-license',
241
242
            // Common
243
            'select2-js',
244
            'qtip-js',
245
246
            // jQuery
247
			'jquery',
248
            'jquery-ui-core',
249
            'jquery-ui-sortable',
250
            'jquery-ui-datepicker',
251
            'jquery-ui-dialog',
252
            'jquery-ui-slider',
253
			'jquery-ui-dialog',
254
			'jquery-ui-tabs',
255
			'jquery-ui-draggable',
256
			'jquery-ui-droppable',
257
            'jquery-ui-accordion',
258
		);
259
260
		$this->remove_conflicts( $wp_scripts, $wp_allowed_scripts, 'scripts' );
261
	}
262
263
	/**
264
	 * Callback to eliminate any non-registered style
265
	 * @return void
266
	 */
267
	function no_conflict_styles() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
268
		global $wp_styles;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
269
270
		if( ! gravityview_is_admin_page() ) {
271
			return;
272
		}
273
274
		// Dequeue other jQuery styles even if no-conflict is off.
275
		// Terrible-looking tabs help no one.
276
		if( !empty( $wp_styles->registered ) )  {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
277
			foreach ($wp_styles->registered as $key => $style) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
278
				if( preg_match( '/^(?:wp\-)?jquery/ism', $key ) ) {
279
					wp_dequeue_style( $key );
280
				}
281
			}
282
		}
283
284
		$no_conflict_mode = GravityView_Settings::getSetting('no-conflict-mode');
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...
285
286
		// If no conflict is off, jQuery will suffice.
287
		if( empty( $no_conflict_mode ) ) {
288
			return;
289
		}
290
291
        $wp_allowed_styles = array(
292
	        'admin-bar',
293
        	'colors',
294
	        'ie',
295
	        'wp-auth-check',
296
	        'media-views',
297
			'thickbox',
298
			'dashicons',
299
	        'wp-jquery-ui-dialog',
300
	        'jquery-ui-sortable',
301
302
            // Settings
303
	        'gravityview_settings',
304
305
	        // @todo qTip styles not loading for some reason!
306
	        'jquery-qtip.js',
307
	    );
308
309
		$this->remove_conflicts( $wp_styles, $wp_allowed_styles, 'styles' );
310
311
		/**
312
		 * @action `gravityview_remove_conflicts_after` Runs after no-conflict styles are removed. You can re-add styles here.
313
		 */
314
		do_action('gravityview_remove_conflicts_after');
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...
315
	}
316
317
	/**
318
	 * Remove any style or script non-registered in the no conflict mode
319
	 * @todo  Move this to GravityView_Admin_Views
320
	 * @param  WP_Dependencies $wp_objects        Object of WP_Styles or WP_Scripts
321
	 * @param  string[] $required_objects   List of registered script/style handles
322
	 * @param  string $type              Either 'styles' or 'scripts'
323
	 * @return void
324
	 */
325
	private function remove_conflicts( &$wp_objects, $required_objects, $type = 'scripts' ) {
326
327
        /**
328
         * @filter `gravityview_noconflict_{$type}` Modify the list of no conflict scripts or styles\n
329
         * Filter is `gravityview_noconflict_scripts` or `gravityview_noconflict_styles`
330
         * @param array $required_objects
331
         */
332
        $required_objects = apply_filters( "gravityview_noconflict_{$type}", $required_objects );
333
334
        //reset queue
335
        $queue = array();
336
        foreach( $wp_objects->queue as $object ) {
337
	        if( in_array( $object, $required_objects ) || preg_match('/gravityview|gf_|gravityforms/ism', $object ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
338
                $queue[] = $object;
339
            }
340
        }
341
        $wp_objects->queue = $queue;
342
343
        $required_objects = $this->add_script_dependencies( $wp_objects->registered, $required_objects );
344
345
        //unregistering scripts
346
        $registered = array();
347
        foreach( $wp_objects->registered as $handle => $script_registration ){
348
            if( in_array( $handle, $required_objects ) ){
349
                $registered[ $handle ] = $script_registration;
350
            }
351
        }
352
        $wp_objects->registered = $registered;
353
	}
354
355
	/**
356
	 * Add dependencies
357
	 *
358
	 * @param [type] $registered [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
359
	 * @param [type] $scripts    [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
360
	 */
361
	private function add_script_dependencies($registered, $scripts) {
362
363
		//gets all dependent scripts linked to the $scripts array passed
364
		do {
365
			$dependents = array();
366
			foreach ( $scripts as $script ) {
367
				$deps = isset( $registered[ $script ] ) && is_array( $registered[ $script ]->deps ) ? $registered[ $script ]->deps : array();
368
				foreach ( $deps as $dep ) {
369
					if ( ! in_array( $dep, $scripts ) && ! in_array( $dep, $dependents ) ) {
370
						$dependents[] = $dep;
371
					}
372
				}
373
			}
374
			$scripts = array_merge( $scripts, $dependents );
375
		} while ( ! empty( $dependents ) );
376
377
		return $scripts;
378
	}
379
380
381
	/**
382
	 * Get admin notices
383
	 * @deprecated since 1.12
384
	 * @return array
385
	 */
386
	public static function get_notices() {
387
		return GravityView_Admin_Notices::get_notices();
388
	}
389
390
	/**
391
	 * Add a notice to be displayed in the admin.
392
	 * @deprecated since 1.12
393
	 * @param array $notice Array with `class` and `message` keys. The message is not escaped.
394
	 */
395
	public static function add_notice( $notice = array() ) {
396
		GravityView_Admin_Notices::add_notice( $notice );
397
	}
398
399
	/**
400
	 * Check if Gravity Forms plugin is active and show notice if not.
401
	 *
402
	 * @deprecated since 1.12
403
	 * @see GravityView_Compatibility::get_plugin_status()
404
	 * @return boolean True: checks have been passed; GV is fine to run; False: checks have failed, don't continue loading
405
	 */
406
	public static function check_gravityforms() {
407
		return GravityView_Compatibility::check_gravityforms();
408
	}
409
410
	/**
411
	 * Check if specified plugin is active, inactive or not installed
412
	 *
413
	 * @deprecated since 1.12
414
	 * @see GravityView_Compatibility::get_plugin_status()
415
416
	 * @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive
417
	 */
418
	static function get_plugin_status( $location = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
419
		return GravityView_Compatibility::get_plugin_status( $location );
420
	}
421
422
	/**
423
	 * Is the current admin page a GravityView-related page?
424
	 *
425
	 * @todo Convert to use WP_Screen
426
	 * @param string $hook
427
	 * @param null|string $page Optional. String return value of page to compare against.
428
	 *
429
	 * @return bool|string|void If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`)
430
	 */
431
	static function is_admin_page( $hook = '', $page = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
432
		global $current_screen, $plugin_page, $pagenow, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
433
434
		if( ! is_admin() ) { return false; }
435
436
		$is_page = false;
437
438
		$is_gv_screen = (!empty($current_screen) && isset($current_screen->post_type) && $current_screen->post_type === 'gravityview');
0 ignored issues
show
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
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...
439
440
		$is_gv_post_type_get = (isset($_GET['post_type']) && $_GET['post_type'] === 'gravityview');
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
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
441
442
		$is_gv_settings_get = isset( $_GET['page'] ) && $_GET['page'] === 'gravityview_settings';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
443
444
		if( empty( $post ) && $pagenow === 'post.php' && !empty( $_GET['post'] ) ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
445
			$gv_post = get_post( intval( $_GET['post'] ) );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
446
			$is_gv_post_type = (!empty($gv_post) && !empty($gv_post->post_type) && $gv_post->post_type === 'gravityview');
0 ignored issues
show
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
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...
447
		} else {
448
			$is_gv_post_type = (!empty($post) && !empty($post->post_type) && $post->post_type === 'gravityview');
0 ignored issues
show
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
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...
449
		}
450
451
		if( $is_gv_screen || $is_gv_post_type || $is_gv_post_type || $is_gv_post_type_get || $is_gv_settings_get ) {
452
453
			// $_GET `post_type` variable
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
454
			if(in_array($pagenow, array( 'post.php' , 'post-new.php' )) ) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
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 "'post.php'" and comma; 1 found
Loading history...
455
				$is_page = 'single';
456
			} else if ( in_array( $plugin_page, array( 'gravityview_settings', 'gravityview_page_gravityview_settings' ) ) || ( !empty( $_GET['page'] ) && $_GET['page'] === 'gravityview_settings' ) ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
457
				$is_page = 'settings';
458
			} else {
459
				$is_page = 'views';
460
			}
461
		}
462
463
		/**
464
		 * @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page?
465
		 * @param[in,out] string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`)
466
		 * @param[in] string $hook The name of the page to check against. Is passed to the method.
467
		 */
468
		$is_page = apply_filters( 'gravityview_is_admin_page', $is_page, $hook );
469
470
		// If the current page is the same as the compared page
471
		if( !empty( $page ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
472
			return $is_page === $page;
473
		}
474
475
		return $is_page;
476
	}
477
478
}
479
480
new GravityView_Admin;
481
482
/**
483
 * Alias for GravityView_Admin::is_admin_page()
484
 *
485
 * @see GravityView_Admin::is_admin_page
486
 *
487
 * @param string $hook
488
 * @param null|string $page Optional. String return value of page to compare against.
489
 *
490
 * @return bool|string|void If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`)
491
 */
492
function gravityview_is_admin_page($hook = '', $page = NULL) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
493
	return GravityView_Admin::is_admin_page( $hook, $page );
494
}
495