array( Logs::class, 'live' ), '/stats' => array( Reports::class, 'stats' ), '/log/visitors' => array( Logs::class, 'visitors' ), '/log/actions' => array( Logs::class, 'actions' ), '/filter-values' => array( Logs::class, 'filter_values' ), '/page-queries' => array( Reports::class, 'page_queries' ), '/session/(?P\\d+)' => array( Logs::class, 'session' ), ); foreach ( $routes as $route => $callback ) { register_rest_route( 'footloom/v1', $route, array( 'methods' => 'GET', 'callback' => $callback, 'permission_callback' => array( self::class, 'can_view' ), ) ); } } public static function can_view() { return current_user_can( 'manage_options' ); } // Converts the from/to params (local Y-m-d dates) into a UTC range. public static function date_range( \WP_REST_Request $request ) { $offset = Plugin::tz_offset(); $today = gmdate( 'Y-m-d', time() + $offset ); $from = preg_match( '/^\d{4}-\d{2}-\d{2}$/', (string) $request['from'] ) ? $request['from'] : $today; $to = preg_match( '/^\d{4}-\d{2}-\d{2}$/', (string) $request['to'] ) ? $request['to'] : $today; if ( $from > $to ) { list( $from, $to ) = array( $to, $from ); } return array( $from, $to, gmdate( 'Y-m-d H:i:s', strtotime( "$from 00:00:00 UTC" ) - $offset ), gmdate( 'Y-m-d H:i:s', strtotime( "$to 00:00:00 UTC" ) + DAY_IN_SECONDS - $offset ), ); } }