array( 'type' => 'string', 'enum' => array( 'json', 'apache', 'nginx' ), 'default' => 'json', 'description' => __( 'Output format. json returns structured rows; apache and nginx return server configuration text.', 'acrossai-abilities-manager' ), ), 'limit' => array( 'type' => 'integer', 'default' => 500, 'minimum' => 1, 'maximum' => 5000, 'description' => __( 'Maximum active redirections to include.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'format' => array( 'type' => 'string' ), 'content' => array( 'type' => 'string' ), 'redirections' => array( 'type' => 'array' ), 'rule_count' => array( 'type' => 'integer' ), 'warnings' => array( 'type' => 'array' ), 'format_parity' => array( 'type' => 'string' ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $format = isset( $input['format'] ) ? sanitize_key( (string) $input['format'] ) : 'json'; $limit = isset( $input['limit'] ) ? max( 1, min( 5000, (int) $input['limit'] ) ) : 500; if ( 'json' === $format ) { $listing = Redirections_Repository::listing( 'active', $limit, 1, '', 'id', 'DESC' ); if ( is_wp_error( $listing ) ) { return $listing; } return array( 'format' => 'json', 'content' => '', 'redirections' => $listing['redirections'], 'rule_count' => $listing['count'], 'warnings' => array(), 'format_parity' => 'native', 'message' => sprintf( /* translators: %d: number of redirections exported */ _n( 'Exported %d active redirection as JSON.', 'Exported %d active redirections as JSON.', $listing['count'], 'acrossai-abilities-manager' ), $listing['count'] ), ); } $result = Redirections_Repository::export( $format, $limit ); if ( is_wp_error( $result ) ) { return $result; } $result['redirections'] = array(); $result['message'] = array() === $result['warnings'] ? sprintf( /* translators: 1: number of redirections, 2: format name */ _n( 'Exported %1$d active redirection as %2$s configuration.', 'Exported %1$d active redirections as %2$s configuration.', $result['rule_count'], 'acrossai-abilities-manager' ), $result['rule_count'], $format ) : sprintf( /* translators: 1: number of redirections, 2: format name, 3: number of warnings */ __( 'Exported %1$d active redirections as %2$s configuration with %3$d warnings — review them before applying.', 'acrossai-abilities-manager' ), $result['rule_count'], $format, count( $result['warnings'] ) ); return $result; } }