PluginProbe
Redirection / 4.2.1
Redirection v4.2.1
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / api / api-log.php

api-log.php in Redirection 4.2.1, at api/api-log.php

54 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 class Redirection_Api_Log extends Redirection_Api_Filter_Route {
4 public function __construct( $namespace ) {
5 $filters = array( 'url', 'ip', 'url-exact' );
6 $orders = array( 'url', 'ip' );
7
8 register_rest_route( $namespace, '/log', array(
9 'args' => $this->get_filter_args( $filters, $orders ),
10 $this->get_route( WP_REST_Server::READABLE, 'route_log' ),
11 $this->get_route( WP_REST_Server::EDITABLE, 'route_delete_all' ),
12 ) );
13
14 $this->register_bulk( $namespace, '/bulk/log/(?P<bulk>delete)', $filters, $filters, 'route_bulk' );
15 }
16
17 public function route_log( WP_REST_Request $request ) {
18 return $this->get_logs( $request->get_params() );
19 }
20
21 public function route_bulk( WP_REST_Request $request ) {
22 $items = explode( ',', $request['items'] );
23
24 if ( is_array( $items ) ) {
25 $items = array_map( 'intval', $items );
26 array_map( array( 'RE_Log', 'delete' ), $items );
27 return $this->route_log( $request );
28 }
29
30 return $this->add_error_details( new WP_Error( 'redirect', 'Invalid array of items' ), __LINE__ );
31 }
32
33 public function route_delete_all( WP_REST_Request $request ) {
34 $params = $request->get_params();
35 $filter = false;
36 $filter_by = false;
37
38 if ( isset( $params['filter'] ) ) {
39 $filter = $params['filter'];
40 }
41
42 if ( isset( $params['filterBy'] ) && in_array( $params['filterBy'], array( 'url', 'ip', 'url-exact' ), true ) ) {
43 $filter_by = $params['filterBy'];
44 }
45
46 RE_Log::delete_all( $filter_by, $filter );
47 return $this->route_log( $request );
48 }
49
50 private function get_logs( array $params ) {
51 return RE_Filter_Log::get( 'redirection_logs', 'RE_Log', $params );
52 }
53 }
54