Closed jpu4 closed 4 months ago
It "seems" to be resolved from core/loaders/mvc_admin_loader.
I defined a private array called "ajaxRoutes"
then refactored "add_admin_ajax_routes()" and "add_public_ajax_routes()"
public function add_admin_ajax_routes(): void {
$routes = MvcRouter::get_admin_ajax_routes();
if (!empty($routes)) {
foreach ($routes as $route) {
$route['is_admin_ajax'] = true;
$method = 'admin_ajax_' . $route['wp_action'];
$this->ajaxRoutes[$method] = function () use ($route) {
MvcDispatcher::dispatch(array(
'controller' => $route['controller'],
'action' => $route['action']
));
die();
};
add_action('wp_ajax_' . $route['wp_action'], function () use ($method) {
$this->execute_ajax_route($method);
});
}
}
}
public function execute_ajax_route(string $method): void {
if (isset($this->ajaxRoutes[$method])) {
call_user_func($this->ajaxRoutes[$method]);
}
}
public function add_public_ajax_routes(): void {
$routes = MvcRouter::get_public_ajax_routes();
if (!empty($routes)) {
foreach ($routes as $route) {
$route['is_admin_ajax'] = false;
$method = 'public_ajax_' . $route['wp_action'];
$this->ajaxRoutes[$method] = function () use ($route) {
// $this->dispatcher->{$method} = function () use ($route) {
MvcDispatcher::dispatch(array(
'controller' => $route['controller'],
'action' => $route['action']
));
die();
};
// add_action('wp_ajax_nopriv_' . $route['wp_action'], array($this->dispatcher, $method));
add_action('wp_ajax_nopriv_' . $route['wp_action'], function () use ($method) {
$this->execute_ajax_route($method);
});
}
}
}
Feel free to submit a pull request. I've been running this on php 8.x for clients for some time but perhaps the warning levels are set lower....
I'm not sure the project is still active but I just thought I'd take a chance and ask if there's a plan to support php 8.1+. I've made a number of php 8 updates but what's consistent is the warning about dynamic properties.