PluginProbe
Redirection / 4.0
Redirection v4.0
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-export.php

api-export.php in Redirection 4.0, at api/api-export.php

29 lines 802 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Redirection_Api_Export extends Redirection_Api_Route {
4 public function __construct( $namespace ) {
5 register_rest_route( $namespace, '/export/(?P<module>1|2|3|all)/(?P<format>csv|apache|nginx|json)', array(
6 $this->get_route( WP_REST_Server::READABLE, 'route_export' ),
7 ) );
8 }
9
10 public function route_export( WP_REST_Request $request ) {
11 $module = $request['module'];
12 $format = 'json';
13
14 if ( in_array( $request['format'], array( 'csv', 'apache', 'nginx', 'json' ) ) ) {
15 $format = $request['format'];
16 }
17
18 $export = Red_FileIO::export( $module, $format );
19 if ( $export === false ) {
20 return $this->add_error_details( new WP_Error( 'redirect', 'Invalid module' ), __LINE__ );
21 }
22
23 return array(
24 'data' => $export['data'],
25 'total' => $export['total'],
26 );
27 }
28 }
29