array(),
'mods' => array(),
'options' => array()
);
foreach ( $modules as $name => $value ) {
if ( 'activated' === get_option( $value ) ) {
$data['modules'][$name] = $value;
}
}
foreach ( $theme_mods as $theme_mod ) {
if ( 'generate_copyright' == $theme_mod ) {
if ( in_array( 'copyright', $_POST['module_group'] ) ) {
$data['mods'][$theme_mod] = get_theme_mod( $theme_mod );
}
} else {
if ( in_array( 'generate_settings', $_POST['module_group'] ) ) {
$data['mods'][$theme_mod] = get_theme_mod( $theme_mod );
}
}
}
foreach ( $settings as $setting ) {
if ( in_array( $setting, $_POST['module_group'] ) ) {
$data['options'][$setting] = get_option( $setting );
}
}
$data = apply_filters( 'generate_export_data', $data );
nocache_headers();
header( 'Content-Type: application/json; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=generate-settings-export-' . date( 'm-d-Y' ) . '.json' );
header( "Expires: 0" );
echo json_encode( $data );
exit;
}
/**
* Import our exported file.
*
* @since 1.7
*/
public static function import() {
if ( empty( $_POST['generate_action'] ) || 'import_settings' != $_POST['generate_action'] ) {
return;
}
if ( ! wp_verify_nonce( $_POST['generate_import_nonce'], 'generate_import_nonce' ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$filename = $_FILES['import_file']['name'];
$extension = end( explode( '.', $_FILES['import_file']['name'] ) );
if ( $extension != 'json' ) {
wp_die( __( 'Please upload a valid .json file', 'gp-premium' ) );
}
$import_file = $_FILES['import_file']['tmp_name'];
if ( empty( $import_file ) ) {
wp_die( __( 'Please upload a file to import', 'gp-premium' ) );
}
// Retrieve the settings from the file and convert the json object to an array.
$settings = json_decode( file_get_contents( $import_file ), true );
foreach ( ( array ) $settings['modules'] as $key => $val ) {
if ( in_array( $val, self::get_modules() ) ) {
update_option( $val, 'activated' );
}
}
foreach ( ( array ) $settings['mods'] as $key => $val ) {
if ( in_array( $key, self::get_theme_mods() ) ) {
set_theme_mod( $key, $val );
}
}
foreach ( ( array ) $settings['options'] as $key => $val ) {
if ( in_array( $key, self::get_settings() ) ) {
update_option( $key, $val );
}
}
// Delete existing dynamic CSS cache
delete_option( 'generate_dynamic_css_output' );
delete_option( 'generate_dynamic_css_cached_version' );
wp_safe_redirect( admin_url( 'admin.php?page=generate-options&status=imported' ) );
exit;
}
/**
* List out our available modules.
*
* @since 1.7
*/
public static function get_modules() {
return array(
'Backgrounds' => 'generate_package_backgrounds',
'Blog' => 'generate_package_blog',
'Colors' => 'generate_package_colors',
'Copyright' => 'generate_package_copyright',
'Elements' => 'generate_package_elements',
'Disable Elements' => 'generate_package_disable_elements',
'Hooks' => 'generate_package_hooks',
'Menu Plus' => 'generate_package_menu_plus',
'Page Header' => 'generate_package_page_header',
'Secondary Nav' => 'generate_package_secondary_nav',
'Sections' => 'generate_package_sections',
'Spacing' => 'generate_package_spacing',
'Typography' => 'generate_package_typography',
'WooCommerce' => 'generate_package_woocommerce',
);
}
/**
* List our our set theme mods.
*
* @since 1.7
*/
public static function get_theme_mods() {
return array(
'font_body_variants',
'font_body_category',
'font_site_title_variants',
'font_site_title_category',
'font_site_tagline_variants',
'font_site_tagline_category',
'font_navigation_variants',
'font_navigation_category',
'font_secondary_navigation_variants',
'font_secondary_navigation_category',
'font_buttons_variants',
'font_buttons_category',
'font_heading_1_variants',
'font_heading_1_category',
'font_heading_2_variants',
'font_heading_2_category',
'font_heading_3_variants',
'font_heading_3_category',
'font_heading_4_variants',
'font_heading_4_category',
'font_heading_5_variants',
'font_heading_5_category',
'font_heading_6_variants',
'font_heading_6_category',
'font_widget_title_variants',
'font_widget_title_category',
'font_footer_variants',
'font_footer_category',
'generate_copyright',
);
}
/**
* List out our available settings.
*
* @since 1.7
*/
public static function get_settings() {
return array(
'generate_settings',
'generate_background_settings',
'generate_blog_settings',
'generate_hooks',
'generate_page_header_settings',
'generate_secondary_nav_settings',
'generate_spacing_settings',
'generate_menu_plus_settings',
'generate_woocommerce_settings',
);
}
}
GeneratePress_Import_Export::get_instance();