Passed
Push — master ( 2d893f...5de32f )
by Atanas
02:41
created

AdminCondition::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Routing\Conditions;
11
12
use WPEmerge\Requests\RequestInterface;
13
14
/**
15
 * Check against the current ajax action.
16
 *
17
 * @codeCoverageIgnore
18
 */
19
class AdminCondition implements ConditionInterface {
20
	/**
21
	 * Menu slug.
22
	 *
23
	 * @var string
24
	 */
25
	protected $menu = '';
26
27
	/**
28
	 * Parent menu slug.
29
	 *
30
	 * @var string
31
	 */
32
	protected $parent_menu = '';
33
34
	/**
35
	 * Constructor
36
	 *
37
	 * @codeCoverageIgnore
38
	 * @param string $menu
39
	 * @param string $parent_menu
40
	 */
41
	public function __construct( $menu, $parent_menu = '' ) {
42
		$this->menu = $menu;
43
		$this->parent_menu = $parent_menu;
44
	}
45
46
	/**
47
	 * Check if the admin page requirement matches.
48
	 *
49
	 * @return boolean
50
	 */
51
	protected function isAdminPage() {
52
		return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX );
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57
	 */
58
	public function isSatisfied( RequestInterface $request ) {
59
		if ( ! $this->isAdminPage() ) {
60
			return false;
61
		}
62
63
		$screen = get_current_screen();
64
65
		if ( ! $screen ) {
66
			return false;
67
		}
68
69
		return $screen->id === get_plugin_page_hookname( $this->menu, $this->parent_menu );
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	public function getArguments( RequestInterface $request ) {
76
		return ['hook' => get_plugin_page_hookname( $this->menu, $this->parent_menu )];
77
	}
78
}
79