PluginProbe
Adminimize / 1.11.8
Adminimize v1.11.8
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
adminimize / inc-setup / export.php

export.php in Adminimize 1.11.8, at inc-setup/export.php

126 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 add_action( 'admin_init', '_mw_adminimize_export_role_json' );
18
19 /**
20 * Process a settings export that generates a .json file of the shop settings.
21 */
22 function _mw_adminimize_export_json() {
23
24 if ( ! is_admin() ) {
25 return;
26 }
27
28 if ( ! current_user_can( 'manage_options' ) ) {
29 return;
30 }
31
32 // If is AJAX Call.
33 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
34 return;
35 }
36
37 if ( empty( $_POST[ '_mw_adminimize_export' ] ) || 'true' !== $_POST[ '_mw_adminimize_export' ] ) {
38 return;
39 }
40
41 require_once ABSPATH . 'wp-includes/pluggable.php';
42 if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) {
43 return;
44 }
45
46 $settings = _mw_adminimize_get_option_value();
47 $filepath = 'mw_adminimize-settings-export-' . date( 'm-d-Y' ) . '.json';
48
49 ignore_user_abort( TRUE );
50
51 nocache_headers();
52 header( 'Cache-Control: public' );
53 header( 'Content-Type: application/json; charset=utf-8' );
54 header( 'Content-Transfer-Encoding: binary' );
55 header( 'Content-Disposition: attachment; filename=' . $filepath );
56 //header( 'Content-Length: ' . filesize( $filepath ) );
57 header( 'Expires: 0' );
58
59 echo wp_json_encode( $settings );
60 exit();
61 }
62
63 /**
64 * Process a settings export for one or many roles that generates a .json file of the shop settings.
65 *
66 * @return array
67 */
68 function _mw_adminimize_export_role_json() {
69
70 if ( ! is_admin() ) {
71 return;
72 }
73
74 if ( ! current_user_can( 'manage_options' ) ) {
75 return;
76 }
77
78 // If is AJAX Call.
79 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
80 return;
81 }
82
83 if ( empty( $_POST[ '_mw_adminimize_export_role' ] )
84 || 'true' !== $_POST[ '_mw_adminimize_export_role' ]
85 || empty( $_POST['select_adminimize_roles']) ) {
86 return;
87 }
88
89 require_once ABSPATH . 'wp-includes/pluggable.php';
90 if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_export_role_nonce' ], 'mw_adminimize_export_role_nonce' ) ) {
91 return;
92 }
93
94 $keys = [];
95 $adminimize_roles = $_POST['select_adminimize_roles'];
96 $adminimize_option = _mw_adminimize_get_option_value();
97 foreach( $adminimize_roles as $adminimize_role ){
98
99 $adminimize_role_keys = array_filter(
100 $adminimize_option, function( $option_key ) use ( $adminimize_role ){
101 return stripos( $option_key, '_' . $adminimize_role ) !== false;
102 }, ARRAY_FILTER_USE_KEY
103 );
104 if ( empty( $keys ) ){
105 $keys = $adminimize_role_keys;
106 } else {
107 $keys = array_merge( $keys, $adminimize_role_keys );
108 }
109 }
110
111 $filepath = 'mw_adminimize-settings-role-export-' . date( 'm-d-Y' ) . '.json';
112
113 ignore_user_abort( TRUE );
114
115 nocache_headers();
116 header( 'Cache-Control: public' );
117 header( 'Content-Type: application/json; charset=utf-8' );
118 header( 'Content-Transfer-Encoding: binary' );
119 header( 'Content-Disposition: attachment; filename=' . $filepath );
120 header( 'Expires: 0' );
121
122 echo wp_json_encode( $keys );
123 exit();
124 }
125
126