| 1 |
<?php |
| 2 |
/** |
| 3 |
* Export settings as json file. |
| 4 |
* |
| 5 |
* @package Adminimize |
| 6 |
* @subpackage export |
| 7 |
* @author Frank Bültge |
| 8 |
* @version 2017-04-13 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! function_exists( 'add_action' ) ) { |
| 12 |
echo "Hi there! I'm just a part of plugin, not much I can do when called directly."; |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
add_action( 'admin_init', '_mw_adminimize_export_json' ); |
| 17 |
/** |
| 18 |
* Process a settings export that generates a .json file of the shop settings. |
| 19 |
*/ |
| 20 |
function _mw_adminimize_export_json() { |
| 21 |
|
| 22 |
if ( ! is_admin() ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
// If is AJAX Call. |
| 31 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
if ( empty( $_POST[ '_mw_adminimize_export' ] ) || 'true' !== $_POST[ '_mw_adminimize_export' ] ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
require_once ABSPATH . 'wp-includes/pluggable.php'; |
| 40 |
if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
$settings = _mw_adminimize_get_option_value(); |
| 45 |
$filepath = 'mw_adminimize-settings-export-' . date( 'm-d-Y' ) . '.json'; |
| 46 |
|
| 47 |
ignore_user_abort( TRUE ); |
| 48 |
|
| 49 |
nocache_headers(); |
| 50 |
header( 'Cache-Control: public' ); |
| 51 |
header( 'Content-Type: application/json; charset=utf-8' ); |
| 52 |
header( 'Content-Transfer-Encoding: binary' ); |
| 53 |
header( 'Content-Disposition: attachment; filename=' . $filepath ); |
| 54 |
//header( 'Content-Length: ' . filesize( $filepath ) ); |
| 55 |
header( 'Expires: 0' ); |
| 56 |
|
| 57 |
echo wp_json_encode( $settings ); |
| 58 |
exit(); |
| 59 |
} |
| 60 |
|