Server IP : 104.21.14.48 / Your IP : 3.147.77.159 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/chroot/var/www/wp-content/plugins/defender-security/framework/helper/ |
Upload File : |
<?php /** * Helper to enqueue ajax route, also generate the nonce's. * * @package Calotes\Helper */ namespace Calotes\Helper; /** * Helper to enqueue ajax route, also generate the nonce's. */ class Route { /** * Array to store registered routes. * * @var array */ protected static $routes = array(); /** * Array to store nonce's for registered routes. * * @var array */ protected static $nonces = array(); /** * Registers a new route for handling AJAX requests. * * @param mixed $name The name of the route. * @param mixed $category The category of the route. * @param mixed $route The route to be registered. * @param mixed $callback The callback function to handle the request. * @param bool $nopriv Whether the route should be accessible without authentication. */ public static function register_route( $name, $category, $route, $callback, $nopriv = false ) { $namespace = self::get_namespace( $category ); $route = $namespace . '/' . $route; add_action( 'wp_ajax_' . $route, $callback ); if ( true === $nopriv ) { add_action( 'wp_ajax_nopriv_' . $route, $callback ); } if ( ! isset( self::$routes[ $category ] ) ) { self::$routes[ $category ] = array(); self::$nonces[ $category ] = array(); } self::$routes[ $category ][ $name ] = $route; self::$nonces[ $category ][ $name ] = wp_create_nonce( $name . $category ); } /** * Retrieves the exported routes and nonce's for the specified categories. * * @param mixed $categories The categories for which to export routes and nonce's. * * @return array The exported routes and nonce's. */ public static function export_routes( $categories ) { $routes = self::$routes[ $categories ] ?? array(); $nonces = self::$nonces[ $categories ] ?? array(); return array( $routes, $nonces ); } /** * Retrieves the namespace for a given module. * * @param mixed $module The module for which to retrieve the namespace. * * @return string The namespace for the specified module. */ public static function get_namespace( $module ) { return 'wp-defender/v1/' . $module; } }