PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.6
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.6
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / elementor / wp-one-package / src / Admin / Controllers / Logs.php

Logs.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.6, 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