File tree Expand file tree Collapse file tree 4 files changed +31
-6
lines changed
Expand file tree Collapse file tree 4 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1414 <severity >0</severity >
1515 </rule >
1616
17+ <file >config/</file >
1718 <file >src/</file >
19+ <file >wc-sync-core.php</file >
1820</ruleset >
Original file line number Diff line number Diff line change 66 * @subpackage Dependency Injection
77 */
88
9- namespace XWP \DI ;
10-
119use Automattic \Jetpack \Constants ;
1210
1311/**
1412 * Determines execution context.
1513 *
1614 * @since 1.0.0
1715 */
18- final class Hook_Context {
16+ final class XWP_Context {
1917 /**
2018 * Frontend context.
2119 */
@@ -120,6 +118,17 @@ public static function admin(): bool {
120118 return \is_admin () && ! self ::ajax ();
121119 }
122120
121+ /**
122+ * Check if the request is an admin request for a specific page.
123+ *
124+ * @param string $page The page to check.
125+ * @param string|null $type The post type to check.
126+ * @return bool
127+ */
128+ public static function admin_page ( string $ page , ?string $ type = null ): bool {
129+ return self ::admin () && ( $ GLOBALS ['pagenow ' ] ?? '' ) === $ page && ( ! $ type || ( $ GLOBALS ['typenow ' ] ?? '' ) === $ type );
130+ }
131+
123132 /**
124133 * Check if the request is an AJAX request.
125134 *
@@ -129,6 +138,16 @@ public static function ajax(): bool {
129138 return Constants::is_true ( 'DOING_AJAX ' );
130139 }
131140
141+ /**
142+ * Check if the request is an AJAX request for a specific action.
143+ *
144+ * @param string $action The action to check.
145+ * @return bool
146+ */
147+ public static function ajax_action ( string $ action ): bool {
148+ return self ::ajax () && \xwp_fetch_req_var ( 'action ' , '' ) === $ action ;
149+ }
150+
132151 /**
133152 * Check if the request is a cron request.
134153 *
Original file line number Diff line number Diff line change @@ -284,6 +284,10 @@ public function is_lazy(): bool {
284284 }
285285
286286 public function is_hookable (): bool {
287- return null === $ this ->hookable && $ this ->check_context () || $ this ->hookable ;
287+ if ( ! $ this ->check_context () ) {
288+ return false ;
289+ }
290+
291+ return $ this ->hookable ?? true ;
288292 }
289293}
Original file line number Diff line number Diff line change 1212use DI \Container ;
1313use ReflectionClass ;
1414use ReflectionMethod ;
15- use XWP \DI \Hook_Context ;
1615use XWP \DI \Interfaces \Can_Hook ;
16+ use XWP_Context ;
1717
1818/**
1919 * Base hook from which the action and filter decorators inherit.
@@ -111,7 +111,7 @@ public function can_load(): bool {
111111 * @return bool
112112 */
113113 public function check_context (): bool {
114- return Hook_Context ::validate ( $ this ->context );
114+ return XWP_Context ::validate ( $ this ->context );
115115 }
116116
117117 /**
You can’t perform that action at this time.
0 commit comments