@@ -24,6 +24,7 @@ class RequestRouter {
2424 protected UrlBuilder $ url_builder ;
2525 protected Renderer $ renderer ;
2626 protected LabelGenerator $ label_generator ;
27+ protected Request $ request ;
2728
2829 /** @var callable|null */
2930 protected $ layout_callback = null ;
@@ -38,7 +39,8 @@ public function __construct(
3839 FieldTypeRegistry $ registry ,
3940 UrlBuilder $ url_builder ,
4041 ?Renderer $ renderer = null ,
41- ?LabelGenerator $ label_generator = null
42+ ?LabelGenerator $ label_generator = null ,
43+ ?Request $ request = null
4244 ) {
4345 $ this ->config = $ config ;
4446 $ this ->dataset = $ dataset ;
@@ -47,6 +49,7 @@ public function __construct(
4749 $ this ->url_builder = $ url_builder ;
4850 $ this ->renderer = $ renderer ?? new HtmlRenderer ();
4951 $ this ->label_generator = $ label_generator ?? new LabelGenerator ();
52+ $ this ->request = $ request ?? new Request ();
5053
5154 $ this ->resolve_labels ();
5255 }
@@ -120,8 +123,8 @@ protected function check_capability() {
120123 public function route (): void {
121124 $ this ->check_capability ();
122125
123- $ action = $ this ->url_builder ->get_current_action ();
124- $ id = $ this ->url_builder ->get_current_id ();
126+ $ action = $ this ->request ->get_current_action ();
127+ $ id = $ this ->request ->get_current_id ();
125128
126129 // Handle singular mode differently.
127130 if ( $ this ->config ->is_singular () ) {
@@ -526,15 +529,6 @@ protected function render_list_table( array $entities ): string {
526529 return $ html ;
527530 }
528531
529- /**
530- * Check if this is a POST request.
531- *
532- * @return bool True if POST request.
533- */
534- protected function is_post_request (): bool {
535- return isset ( $ _SERVER ['REQUEST_METHOD ' ] ) && $ _SERVER ['REQUEST_METHOD ' ] === 'POST ' ;
536- }
537-
538532 /**
539533 * Verify nonce for an action.
540534 *
@@ -544,8 +538,7 @@ protected function is_post_request(): bool {
544538 */
545539 protected function verify_nonce ( string $ action , ?int $ id = null ): bool {
546540 $ nonce_action = $ this ->url_builder ->get_nonce_action ( $ action , $ id );
547- // phpcs:ignore WordPress.Security.NonceVerification.Missing
548- $ nonce = $ _POST ['_wpnonce ' ] ?? $ _GET ['_wpnonce ' ] ?? '' ;
541+ $ nonce = $ this ->request ->get_nonce ();
549542 return wp_verify_nonce ( $ nonce , $ nonce_action ) !== false ;
550543 }
551544
0 commit comments