# redirection/4.3.2/api/api-export.php

Redirection, version 4.3.2. 42 lines.

- Page: https://pluginprobe.com/plugins/redirection/4.3.2/code/api/api-export.php
- Raw: https://pluginprobe.com/plugins/redirection/4.3.2/raw/api/api-export.php
- Modified: 2019-06-02T05:33:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/redirection/4.3.2/code/api/api-export.php#L10-L20`.

```php
<?php

/**
 * @api {get} /redirection/v1/export/:module/:format Export redirects for a module in a format
 * @apiDescription Export redirects for a module in a format
 * @apiGroup Export
 *
 * @apiParam {String} module The module to export - 1, 2, 3, or 'all'
 * @apiParam {String} format The format of the export. Either 'csv', 'apache', 'nginx', or 'json'
 *
 * @apiSuccess {Array} ip Array of export data
 * @apiSuccess {Integer} total Number of items exported
 *
 * @apiUse 400Error
 */
class Redirection_Api_Export extends Redirection_Api_Route {
	public function __construct( $namespace ) {
		register_rest_route( $namespace, '/export/(?P<module>1|2|3|all)/(?P<format>csv|apache|nginx|json)', array(
			$this->get_route( WP_REST_Server::READABLE, 'route_export' ),
		) );
	}

	public function route_export( WP_REST_Request $request ) {
		$module = $request['module'];
		$format = 'json';

		if ( in_array( $request['format'], array( 'csv', 'apache', 'nginx', 'json' ) ) ) {
			$format = $request['format'];
		}

		$export = Red_FileIO::export( $module, $format );
		if ( $export === false ) {
			return $this->add_error_details( new WP_Error( 'redirect', 'Invalid module' ), __LINE__ );
		}

		return array(
			'data' => $export['data'],
			'total' => $export['total'],
		);
	}
}

```
