PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/ContextResolver.php +111 -8 1.42.0.9 View file →
@@ -6,10 +6,11 @@
6 6 */
7 7
8 8 declare( strict_types=1 );
9 9
10 +namespace Packetery\Module;
10 11
11 -namespace Packetery\Module;
12 +use Packetery\Nette\Http\Request;
12 13
13 14 /**
14 15 * Class ContextResolver.
15 16 *
@@ -17,16 +18,38 @@
17 18 */
18 19 class ContextResolver {
19 20
20 21 /**
22 + * Request.
23 + *
24 + * @var Request
25 + */
26 + private $request;
27 +
28 + /**
29 + * ContextResolver constructor.
30 + *
31 + * @param Request $request Packetery request.
32 + */
33 + public function __construct( Request $request ) {
34 + $this->request = $request;
35 + }
36 +
37 + /**
21 38 * Tells if requesting user is at order grid page.
22 39 *
23 40 * @return bool
24 41 */
25 42 public function isOrderGridPage(): bool {
26 - global $pagenow, $typenow;
43 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
44 + global $pagenow, $typenow, $plugin_page;
27 45
28 - return 'edit.php' === $pagenow && 'shop_order' === $typenow;
46 + if ( ModuleHelper::isHposEnabled() ) {
47 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
48 + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && in_array( $this->request->getQuery( 'action' ), [ 'edit', 'new' ], true ) === false;
49 + }
50 +
51 + return $pagenow === 'edit.php' && $typenow === 'shop_order';
29 52 }
30 53
31 54 /**
32 55 * Tells if requesting user is at order detail page.
@@ -33,29 +56,109 @@
33 56 *
34 57 * @return bool
35 58 */
36 59 public function isOrderDetailPage(): bool {
60 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
61 + global $pagenow, $typenow, $plugin_page;
62 +
63 + if ( ModuleHelper::isHposEnabled() ) {
64 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
65 + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && $this->request->getQuery( 'action' ) === 'edit';
66 + }
67 +
68 + return $pagenow === 'post.php' && $typenow === 'shop_order';
69 + }
70 +
71 + /**
72 + * Tells if requesting user is at product detail page.
73 + *
74 + * @return bool
75 + */
76 + private function isProductDetailPage(): bool {
37 77 global $pagenow, $typenow;
38 78
39 - return 'post.php' === $pagenow && 'shop_order' === $typenow;
79 + return $pagenow === 'post.php' && $typenow === 'product';
40 80 }
41 81
42 82 /**
43 - * Tells if requesting user is at product detail page.
83 + * Tells if requesting user is at product create page.
44 84 *
45 85 * @return bool
46 86 */
47 - public function isProductDetailPage(): bool {
87 + private function isProductCreatePage(): bool {
48 88 global $pagenow, $typenow;
49 89
50 - return 'post.php' === $pagenow && 'product' === $typenow;
90 + return $pagenow === 'post-new.php' && $typenow === 'product';
51 91 }
52 92
53 93 /**
94 + * Tells if requesting user is at product page.
95 + *
96 + * @return bool
97 + */
98 + public function isProductPage(): bool {
99 + return $this->isProductCreatePage() || $this->isProductDetailPage();
100 + }
101 +
102 + /**
54 103 * Tells if requesting user is at page using packetery confirm.
55 104 *
56 105 * @return bool
57 106 */
58 - public function isPacketeryConfirmPage(): bool {
107 + public function isConfirmModalPage(): bool {
59 108 return $this->isOrderDetailPage() || $this->isOrderGridPage();
109 + }
110 +
111 + /**
112 + * Tells if requesting user is at product category grid page.
113 + *
114 + * @return bool
115 + */
116 + public function isProductCategoryGridPage(): bool {
117 + global $pagenow;
118 +
119 + return $pagenow === 'edit-tags.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME;
120 + }
121 +
122 + /**
123 + * Tells if requesting user is at product category grid page.
124 + *
125 + * @return bool
126 + */
127 + public function isProductCategoryDetailPage(): bool {
128 + global $pagenow;
129 +
130 + return $pagenow === 'term.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME;
131 + }
132 +
133 + /**
134 + * Tells if user is at page detail.
135 + *
136 + * @return bool
137 + */
138 + public function isPageDetail(): bool {
139 + global $pagenow, $typenow;
140 +
141 + return $pagenow === 'post.php' && $typenow === 'page';
142 + }
143 +
144 + private function isShippingZoneDetailPage(): bool {
145 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
146 + global $pagenow, $plugin_page;
147 +
148 + return (
149 + $pagenow === 'admin.php' &&
150 + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
151 + $plugin_page === 'wc-settings' &&
152 + $this->request->getQuery( 'tab' ) === 'shipping' &&
153 + $this->request->getQuery( 'zone_id' ) > 0
154 + );
155 + }
156 +
157 + public function getShippingZoneId(): ?int {
158 + if ( $this->isShippingZoneDetailPage() ) {
159 + return (int) $this->request->getQuery( 'zone_id' );
160 + }
161 +
162 + return null;
60 163 }
61 164 }