PluginProbe
Elementor Website Builder – more than just a page builder / trunk
Elementor Website Builder – more than just a page builder vtrunk
4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 All 456 releases
elementor / vendor / elementor / wp-one-package / src / Admin / Controllers / Logs.php

Logs.php in Elementor Website Builder – more than just a page builder trunk, at vendor/elementor/wp-one-package/src/Admin/Controllers/Logs.php

83 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorOne\Admin\Controllers;
4
5 use ElementorOne\Admin\Config;
6 use ElementorOne\LogStore;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Internal logs REST API (elementor-one host only).
14 */
15 class Logs extends \WP_REST_Controller {
16
17 /**
18 * Constructor
19 */
20 public function __construct() {
21 $this->namespace = Config::APP_REST_NAMESPACE;
22 $this->rest_base = 'logs';
23
24 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
25 }
26
27 /**
28 * @return void
29 */
30 public function register_routes() {
31 register_rest_route(
32 $this->namespace,
33 '/' . $this->rest_base,
34 [
35 [
36 'methods' => \WP_REST_Server::READABLE,
37 'callback' => [ $this, 'get_logs' ],
38 'permission_callback' => [ $this, 'permissions_check' ],
39 ],
40 [
41 'methods' => \WP_REST_Server::DELETABLE,
42 'callback' => [ $this, 'clear_logs' ],
43 'permission_callback' => [ $this, 'permissions_check' ],
44 ],
45 ]
46 );
47 }
48
49 /**
50 * @param \WP_REST_Request $request
51 * @return \WP_REST_Response|\WP_Error
52 */
53 public function get_logs( \WP_REST_Request $request ) {
54 return new \WP_REST_Response(
55 [
56 'entries' => LogStore::instance()->all_newest_first(),
57 ]
58 );
59 }
60
61 /**
62 * @param \WP_REST_Request $request
63 * @return \WP_REST_Response|\WP_Error
64 */
65 public function clear_logs( \WP_REST_Request $request ) {
66 LogStore::instance()->clear();
67
68 return new \WP_REST_Response(
69 [
70 'success' => true,
71 ]
72 );
73 }
74
75 /**
76 * @param \WP_REST_Request $request
77 * @return bool
78 */
79 public function permissions_check( \WP_REST_Request $request ) {
80 return current_user_can( 'manage_options' );
81 }
82 }
83