Completed
Push — develop ( fddcc1...c8b481 )
by Zack
08:02
created

GravityView_Admin::include_required_files()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 18
ccs 0
cts 9
cp 0
crap 2
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 3 and the first side effect is on line 362.

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() ) {
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Compatibility::is_valid() has been deprecated with message: 1.19.4

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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
		require_once( GRAVITYVIEW_DIR . 'includes/admin/metaboxes/class-gravityview-admin-metaboxes.php' );
28
		require_once( GRAVITYVIEW_DIR . 'includes/admin/entry-list.php' );
29
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
30
31
		/** @since 1.15 **/
32
		require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-support-port.php' );
33
34
		/** @since 1.6 */
35
		require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-duplicate-view.php' );
36
37
		/** @since 1.17 */
38
		require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-admin-no-conflict.php' );
39
	}
40
41
	/**
42
	 * @since 1.7.5
43
	 * @return void
44
	 */
45
	private function add_hooks() {
46
47
		// Filter Admin messages
48
		add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
49
		add_filter( 'bulk_post_updated_messages', array( $this, 'post_updated_messages' ) );
50
51
		add_filter( 'plugin_action_links_'. plugin_basename( GRAVITYVIEW_FILE ) , array( $this, 'plugin_action_links' ) );
52
53
		add_action( 'plugins_loaded', array( $this, 'backend_actions' ), 100 );
54
55
	}
56
57
	/**
58
	 * Get text for no views found.
59
	 *
60
	 * @since 1.18 Moved to GravityView_Admin
61
	 *
62
	 * @return string HTML message with no container tags.
63
	 */
64
	public static function no_views_text() {
65
		
66
		if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
67
			return __( 'No Views found in Trash', 'gravityview' );
68
		} elseif( ! empty( $_GET['s'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
69
			return __( 'No Views found.', 'gravityview' );
70
		}
71
72
		// Floaty the Astronaut says "oi"
73
		$image = self::get_floaty();
74
75
		if ( GVCommon::has_cap( 'edit_gravityviews' ) ) {
76
			$output = sprintf( esc_attr__( "%sYou don't have any active views. Let&rsquo;s go %screate one%s!%s\n\nIf you feel like you're lost in space and need help getting started, check out the %sGetting Started%s page.", 'gravityview' ), '<h3>', '<a href="' . admin_url( 'post-new.php?post_type=gravityview' ) . '">', '</a>', '</h3>', '<a href="' . admin_url( 'edit.php?post_type=gravityview&page=gv-getting-started' ) . '">', '</a>' );
77
		} else {
78
			$output = esc_attr__( 'There are no active Views', 'gravityview' );
79
		}
80
81
		return $image . wpautop( $output );
82
	}
83
84
	/**
85
	 * Display error HTML in Edit View when the form is in the trash or no longer exists in Gravity Forms
86
	 *
87
	 * @since 1.19
88
	 *
89
	 * @param int $form_id Gravity Forms
90
	 *
91
	 * @return void
92
	 */
93
	public static function connected_form_warning( $form_id = 0 ) {
94
        global $pagenow;
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...
95
96
		if ( ! is_int( $form_id ) || $pagenow === 'post-new.php' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
97
			return;
98
		}
99
100
		$form_info = GFFormsModel::get_form( $form_id, true );
101
102
		$error = '';
103
		if ( empty( $form_info ) ) {
104
			$error = esc_html__( 'The form connected to this View no longer exists.', 'gravityview' );
105
			$error .= ' ' . esc_html__( 'Select another form as the data source for this View.', 'gravityview' );
106
		} elseif ( $form_info->is_trash ) {
107
			$error = esc_html__( 'The connected form is in the trash.', 'gravityview' );
108
			$error .= ' ' . gravityview_get_link( admin_url( 'admin.php?page=gf_edit_forms&filter=trash' ), esc_html__( 'Restore the form from the trash', 'gravityview' ) );
109
			$error .= ' ' . esc_html__( 'or select another form.', 'gravityview' );
110
		}
111
112
		if( $error ) {
113
			?>
114
			<div class="wp-dialog notice-warning inline error wp-clearfix">
115
				<?php echo gravityview_get_floaty(); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'gravityview_get_floaty'
Loading history...
116
				<h3><?php echo $error; ?></h3>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$error'
Loading history...
117
			</div>
118
			<?php
119
		}
120
	}
121
122
	/**
123
	 * Function to launch admin objects
124
	 *
125
	 * @access public
126
	 * @return void
127
	 */
128
	public function backend_actions() {
129
130
		/** @define "GRAVITYVIEW_DIR" "../" */
131
		include_once( GRAVITYVIEW_DIR .'includes/admin/class.field.type.php' );
132
		include_once( GRAVITYVIEW_DIR .'includes/admin/class.render.settings.php' );
133
		include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-item.php' );
134
		include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-field.php' );
135
		include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-widget.php' );
136
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-views.php' );
137
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-welcome.php' );
138
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-add-shortcode.php' );
139
		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
140
141
		/**
142
		 * @action `gravityview_include_backend_actions` Triggered after all GravityView admin files are loaded
143
		 *
144
		 * Nice place to insert extensions' backend stuff
145
		 */
146
		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...
147
	}
148
149
	/**
150
	 * Modify plugin action links at plugins screen
151
	 *
152
	 * @since 1.15 Added check for `gravityview_view_settings` and `gravityview_support_port` capabilities
153
	 * @access public
154
	 * @static
155
	 * @param array $links Array of action links under GravityView on the plugin page
156
	 * @return array Action links with Settings and Support included, if the user has the appropriate caps
157
	 */
158
	public static function plugin_action_links( $links ) {
159
160
		$actions = array();
161
162
		if( GVCommon::has_cap( 'gravityview_view_settings' ) ) {
163
			$actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ), esc_html__( 'Settings', 'gravityview' ) );
164
		}
165
166
		if( GVCommon::has_cap( 'gravityview_support_port' ) ) {
167
			$actions[] = '<a href="http://docs.gravityview.co">' . esc_html__( 'Support', 'gravityview' ) . '</a>';
168
		}
169
170
		return array_merge( $actions, $links );
171
	}
172
173
	/**
174
	 * Get an image of our intrepid explorer friend
175
	 * @return string HTML image tag with floaty's cute mug on it
176
	 */
177
	public static function get_floaty() {
178
		return gravityview_get_floaty();
179
	}
180
181
	/**
182
	 * Filter Admin messages
183
	 *
184
	 * @param  array      $messages Existing messages
185
	 * @return array                Messages with GravityView views!
186
	 */
187
	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...
188
		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...
189
190
		$post_id = get_the_ID();
191
192
		// By default, there will only be one item being modified.
193
		// When in the `bulk_post_updated_messages` filter, there will be passed a number
194
		// of modified items that will override this array.
195
		$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...
196
197
		// If we're starting fresh, a new form was created.
198
		// We should let the user know this is the case.
199
		$start_fresh = get_post_meta( $post_id, '_gravityview_start_fresh', true );
200
201
		$new_form_text = '';
202
203
		if( !empty( $start_fresh ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
204
205
			// Get the form that was created
206
			$connected_form = gravityview_get_form_id( $post_id );
207
208
			if( !empty( $connected_form ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
209
				$form = gravityview_get_form( $connected_form );
210
				$form_name = esc_attr( $form['title'] );
211
				$image = self::get_floaty();
212
				$new_form_text .= '<h3>'.$image.sprintf( __( 'A new form was created for this View: "%s"', 'gravityview' ), $form_name ).'</h3>';
213
				$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...
214
215
					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.
216
					', '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...
217
				$new_form_text = wpautop( $new_form_text );
218
219
				delete_post_meta( $post_id, '_gravityview_start_fresh' );
220
			}
221
		}
222
223
		$messages['gravityview'] = array(
224
			0  => '', // Unused. Messages start at index 1.
225
			/* translators: %s and %s are HTML tags linking to the View on the website */
226
			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...
227
			/* translators: %s and %s are HTML tags linking to the View on the website */
228
			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...
229
			3  => __( 'View deleted.', 'gravityview' ),
230
			/* translators: %s and %s are HTML tags linking to the View on the website */
231
			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...
232
			/* translators: %s: date and time of the revision */
233
			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...
234
			/* translators: %s and %s are HTML tags linking to the View on the website */
235
			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...
236
			/* translators: %s and %s are HTML tags linking to the View on the website */
237
			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...
238
			8  => __( 'View submitted.', 'gravityview' ),
239
			9  => sprintf(
240
		        /* translators: Date and time the View is scheduled to be published */
241
				__( 'View scheduled for: %1$s.', 'gravityview' ),
242
				// translators: Publish box date format, see http://php.net/date
243
				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...
244
			) . $new_form_text,
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$new_form_text'
Loading history...
245
			/* translators: %s and %s are HTML tags linking to the View on the website */
246
			10  => sprintf(__( 'View draft updated. %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...
247
248
			/**
249
			 * These apply to `bulk_post_updated_messages`
250
			 * @file wp-admin/edit.php
251
			 */
252
			'updated'   => _n( '%s View updated.', '%s Views updated.', $bulk_counts['updated'], 'gravityview' ),
253
			'locked'    => _n( '%s View not updated, somebody is editing it.', '%s Views not updated, somebody is editing them.', $bulk_counts['locked'], 'gravityview' ),
254
			'deleted'   => _n( '%s View permanently deleted.', '%s Views permanently deleted.', $bulk_counts['deleted'], 'gravityview' ),
255
			'trashed'   => _n( '%s View moved to the Trash.', '%s Views moved to the Trash.', $bulk_counts['trashed'], 'gravityview' ),
256
			'untrashed' => _n( '%s View restored from the Trash.', '%s Views restored from the Trash.', $bulk_counts['untrashed'], 'gravityview' ),
257
		);
258
259
		return $messages;
260
	}
261
262
263
	/**
264
	 * Get admin notices
265
	 * @deprecated since 1.12
266
	 * @return array
267
	 */
268
	public static function get_notices() {
269
		return GravityView_Admin_Notices::get_notices();
270
	}
271
272
	/**
273
	 * Add a notice to be displayed in the admin.
274
	 * @deprecated since 1.12
275
	 * @param array $notice Array with `class` and `message` keys. The message is not escaped.
276
	 */
277
	public static function add_notice( $notice = array() ) {
278
		GravityView_Admin_Notices::add_notice( $notice );
279
	}
280
281
	/**
282
	 * Check if Gravity Forms plugin is active and show notice if not.
283
	 *
284
	 * @deprecated since 1.12
285
	 * @see GravityView_Compatibility::get_plugin_status()
286
	 * @return boolean True: checks have been passed; GV is fine to run; False: checks have failed, don't continue loading
287
	 */
288
	public static function check_gravityforms() {
289
		return GravityView_Compatibility::check_gravityforms();
290
	}
291
292
	/**
293
	 * Check if specified plugin is active, inactive or not installed
294
	 *
295
	 * @deprecated since 1.12
296
	 * @see GravityView_Compatibility::get_plugin_status()
297
298
	 * @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive
299
	 */
300
	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...
301
		return GravityView_Compatibility::get_plugin_status( $location );
302
	}
303
304
	/**
305
	 * Is the current admin page a GravityView-related page?
306
	 *
307
	 * @todo Convert to use WP_Screen
308
	 * @param string $hook
309
	 * @param null|string $page Optional. String return value of page to compare against.
310
	 *
311
	 * @return bool|string 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`)
312
	 */
313
	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...
314
		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...
315
316
		if( ! is_admin() ) { return false; }
317
318
		$is_page = false;
319
320
		$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...
321
322
		$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...
323
324
		$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...
325
326
		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...
327
			$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...
328
			$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...
329
		} else {
330
			$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...
331
		}
332
333
		if( $is_gv_screen || $is_gv_post_type || $is_gv_post_type || $is_gv_post_type_get || $is_gv_settings_get ) {
334
335
			// $_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...
336
			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...
337
				$is_page = 'single';
338
			} 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...
339
				$is_page = 'settings';
340
			} else {
341
				$is_page = 'views';
342
			}
343
		}
344
345
		/**
346
		 * @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page?
347
		 * @param[in,out] string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`)
348
		 * @param[in] string $hook The name of the page to check against. Is passed to the method.
349
		 */
350
		$is_page = apply_filters( 'gravityview_is_admin_page', $is_page, $hook );
351
352
		// If the current page is the same as the compared page
353
		if( !empty( $page ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
354
			return $is_page === $page;
355
		}
356
357
		return $is_page;
358
	}
359
360
}
361
362
new GravityView_Admin;
363
364
/**
365
 * Alias for GravityView_Admin::is_admin_page()
366
 *
367
 * @see GravityView_Admin::is_admin_page
368
 *
369
 * @param string $hook
370
 * @param null|string $page Optional. String return value of page to compare against.
371
 *
372
 * @return bool|string 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`)
373
 */
374
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...
375
	return GravityView_Admin::is_admin_page( $hook, $page );
376
}
377