@@ -27,30 +27,35 @@ public function registerRoutes()
2727
2828 public function addRoute (RouteRegister $ route )
2929 {
30- if (
31- !isset ($ _REQUEST ['action ' ])
32- || strpos ($ _REQUEST ['action ' ], $ this ->_router ->getAjaxPrefix ()) === false
33- || !\in_array (strtoupper ($ _SERVER ['REQUEST_METHOD ' ]), $ route ->getMethods ())
30+
31+ $ requestMethod = isset ($ _SERVER ['REQUEST_METHOD ' ]) ? sanitize_text_field ($ _SERVER ['REQUEST_METHOD ' ]) : '' ;
32+ $ action = isset ($ _REQUEST ['action ' ]) ? sanitize_text_field ($ _REQUEST ['action ' ]) : '' ;
33+
34+ if (strpos ($ action , $ this ->_router ->getAjaxPrefix ()) === false
35+ || !\in_array (strtoupper ($ requestMethod ), $ route ->getMethods ())
3436 ) {
3537 return ;
3638 }
3739
38- $ requestPath = str_replace ($ this ->_router ->getAjaxPrefix (), '' , $ _REQUEST [ ' action ' ] );
40+ $ requestPath = str_replace ($ this ->_router ->getAjaxPrefix (), '' , $ action );
3941 if (!$ this ->isRouteMatched ($ route , $ requestPath )) {
4042 return ;
4143 }
4244
43- Hooks::addAction ('wp_ajax_ ' . $ _REQUEST [ ' action ' ] , [$ route , 'handleRequest ' ]);
45+ Hooks::addAction ('wp_ajax_ ' . $ action , [$ route , 'handleRequest ' ]);
4446 if ($ route ->isNoAuth ()) {
45- Hooks::addAction ('wp_ajax_nopriv_ ' . $ _REQUEST [ ' action ' ] , [$ route , 'handleRequest ' ]);
47+ Hooks::addAction ('wp_ajax_nopriv_ ' . $ action , [$ route , 'handleRequest ' ]);
4648 }
4749
4850 $ this ->_router ->addRegisteredRoute ($ this ->currentRouteName (), $ route );
4951 }
5052
5153 public function currentRouteName ()
5254 {
53- return $ _SERVER ['REQUEST_METHOD ' ] . $ _REQUEST ['action ' ];
55+ $ requestMethod = isset ($ _SERVER ['REQUEST_METHOD ' ]) ? sanitize_text_field ($ _SERVER ['REQUEST_METHOD ' ]) : '' ;
56+ $ action = isset ($ _REQUEST ['action ' ]) ? sanitize_text_field ($ _REQUEST ['action ' ]) : '' ;
57+
58+ return $ requestMethod . $ action ;
5459 }
5560
5661 /**
0 commit comments