Completed
Push — develop ( 7592b8...3eb7c5 )
by Zack
14:44
created

future/includes/class-gv-request-frontend.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 14 and the first side effect is on line 6.

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
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The default Request class.
11
 *
12
 * Finds out what Views are being requested.
13
 */
14
class Frontend_Request extends Request {
15
	/**
16
	 * Bootstrap.
17
	 *
18
	 * @return void
19
	 */
20
	public function __construct() {
21
		add_action( 'wp', array( $this, 'parse' ), 12 );
22
		parent::__construct();
23
	}
24
25
	/**
26
	 * Parse the current WordPress context around the $post global.
27
	 *
28
	 * Called by the `wp` hook.
29
	 *
30
	 * @param \WP $wp The WordPress environment class. Unused.
31
	 *
32
	 * @internal
33
	 * @return void
34
	 */
35
	public function parse( $wp = null ) {
36
		/** Nothing to do in an administrative context. */
37
		if ( $this->is_admin() ) {
38
			return;
39
		}
40
41
		/** The post might either be a gravityview, or contain gravityview shortcodes. */
42
		global $post;
43
44
		if ( ! $post instanceof \WP_Post ) {
45
			$this->views = new View_Collection();
46
		} else {
47
			$this->views = View_Collection::from_post( $post );
48
		}
49
	}
50
51
	/**
52
	 * Check if WordPress is_admin(), and make sure not DOING_AJAX.
53
	 *
54
	 * @todo load-(scripts|styles).php return true for \is_admin()!
55
	 *
56
	 * @api
57
	 * @since future
58
	 *
59
	 * @return bool Pure is_admin or not?
60
	 */
61 1
	public function is_admin() {
62 1
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
63 1
		return is_admin() && ! $doing_ajax;
64
	}
65
}
66