PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / vendor-prefixed / stellarwp / admin-notices / src / ValueObjects / ScreenCondition.php

ScreenCondition.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/vendor-prefixed/stellarwp/admin-notices/src/ValueObjects/ScreenCondition.php

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Vendors\StellarWP\AdminNotices\ValueObjects;
4
5 use InvalidArgumentException;
6
7 class ScreenCondition
8 {
9 /**
10 * @var string|array a string compared against the url, a regex for the url, or an array of conditions used against WP_Screen
11 *
12 * @see https://developer.wordpress.org/reference/classes/wp_screen/
13 */
14 private $condition;
15
16 /**
17 * @var bool
18 */
19 private $isRegex = true;
20
21 public function __construct($condition)
22 {
23 $this->validateCondition($condition);
24
25 $this->condition = $condition;
26
27 // check if condition is a string with a regex using ~ as the delimiter
28 $this->isRegex = is_string($condition) && preg_match('/^~.+~[a-z]*$/', $condition) === 1;
29 }
30
31 public function getCondition()
32 {
33 return $this->condition;
34 }
35
36 public function isRegex(): bool
37 {
38 return $this->isRegex;
39 }
40
41 private function validateCondition($condition)
42 {
43 // check if condition is a string or an array
44 if (!(is_string($condition) || is_array($condition))) {
45 throw new InvalidArgumentException('Screen condition must be a string or an array');
46 }
47
48 // check if array is an associative array with WP_Screen properties
49 static $wpScreenProperties = null;
50
51 if ($wpScreenProperties === null) {
52 $wpScreenProperties = get_class_vars('WP_Screen');
53 }
54
55 if (is_array($condition) && array_diff_key($condition, $wpScreenProperties)) {
56 throw new InvalidArgumentException(
57 'Screen condition must be an associative array with WP_Screen properties'
58 );
59 }
60 }
61 }
62