PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.12.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.12.0
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Admin / Logtivity_Log_Index_Controller.php

Logtivity_Log_Index_Controller.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.12.0, at Admin/Logtivity_Log_Index_Controller.php

60 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Log_Index_Controller
4 {
5 public function __construct()
6 {
7 add_action("wp_ajax_nopriv_logtivity_log_index_filter", [$this, 'search']);
8 add_action("wp_ajax_logtivity_log_index_filter", [$this, 'search']);
9 }
10
11 public function search()
12 {
13 if ( !current_user_can( 'manage_options' ) ) {
14 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
15 }
16
17 $response = json_decode(
18 (new Logtivity_Api)->get('/logs', [
19 'page' => $this->getInput('page'),
20 'action' => $this->getInput('search_action'),
21 'context' => $this->getInput('search_context'),
22 'action_user' => $this->getInput('action_user'),
23 ])
24 );
25
26 if ($response->message) {
27 return $this->errorReponse($response->message);
28 }
29
30 return $this->successResponse($response);
31 }
32
33 private function successResponse($response)
34 {
35 return wp_send_json([
36 'view' => logtivity_view('_logs-loop', [
37 'logs' => $response->data,
38 'meta' => $response->meta,
39 'hasNextPage' => $response->links->next,
40 ])
41 ]);
42 }
43
44 private function errorReponse($message)
45 {
46 return wp_send_json([
47 'view' => logtivity_view('_logs-loop', [
48 'message' => $message,
49 'logs' => [],
50 ])
51 ]);
52 }
53
54 private function getInput($field)
55 {
56 return ( isset($_GET[$field]) && is_string($_GET[$field]) ? $_GET[$field] : null);
57 }
58 }
59
60 new Logtivity_Log_Index_Controller;