You appear to be a bot. Output may be restricted
Description
Generate the export file, if requested, in JSON format.
After checking we're on the right page, and trying to export, loop through the list of requested options to export, grabbing the settings from the database, and building up a file name that represents that collection of settings. A .json file is then sent to the browser, named with "genesis" at the start and ending with the current date-time. The genesis_export action is fired after checking we can proceed, but before the array of export options are retrieved.
Usage
$null = Genesis_Admin_Import_Export::export();
Parameters
Returns
null Return early if not on the correct page, or we're not exporting settings.
Source
File name: genesis/lib/classes/class-genesis-admin-import-export.php
Lines:
public function export() { if ( ! genesis_is_menu_page( 'genesis-import-export' ) ) { return; } if ( empty( $_REQUEST['genesis-export'] ) ) { return; } check_admin_referer( 'genesis-export', 'genesis-export-nonce' ); $export_data = $_REQUEST['genesis-export']; /** * Fires before export happens, after admin referer has been checked. * * @since 1.4.0 * * @param string Value of `genesis-export` request variable, containing a list of which settings to export. */ do_action( 'genesis_export', $export_data ); $options = $this->get_export_options(); $settings = []; // Exported file name always starts with "genesis". $prefix = [ 'genesis' ]; // Loop through set(s) of options. foreach ( (array) $export_data as $export => $value ) { // Grab settings field name (key). $settings_field = $options[ $export ]['settings-field']; // Grab all of the settings from the database under that key. $settings[ $settings_field ] = get_option( $settings_field ); // Add name of option set to build up export file name. $prefix[] = $export; } if ( ! $settings ) { return; } // Complete the export file name by joining parts together. $prefix = implode( '-', $prefix ); $output = wp_json_encode( $settings ); // Prepare and send the export file to the browser. header( 'Content-Description: File Transfer' ); header( 'Cache-Control: public, must-revalidate' ); header( 'Pragma: hack' ); header( 'Content-Type: text/plain' ); header( 'Content-Disposition: attachment; filename="' . $prefix . '-' . gmdate( 'Ymd-His' ) . '.json"' ); header( 'Content-Length: ' . mb_strlen( $output ) ); echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit; }