$mods ? $mods : array(), 'options' => array() ); // Build filename $site_url = site_url( '', 'http' ); $site_url = trim( $site_url, '/\\' ); // remove trailing slash $filename = str_replace( 'http://', '', $site_url ); // remove http:// $filename = str_replace( array( '/', '\\' ), '-', $filename ); // replace slashes with - $filename .= '-oceanwp-export'; // append $filename = apply_filters( 'ocean_export_filename', $filename ); foreach ( $mods as $key => $value ) { // Don't save widget data. if ( 'widget_' === substr( strtolower( $key ), 0, 7 ) ) { continue; } // Don't save sidebar data. if ( 'sidebars_' === substr( strtolower( $key ), 0, 9 ) ) { continue; } $data['options'][ $key ] = $value; } if ( function_exists( 'wp_get_custom_css_post' ) ) { $data['wp_css'] = wp_get_custom_css(); } // Set the download headers. header( 'Content-disposition: attachment; filename=' . $filename . '.dat' ); header( 'Content-Type: application/octet-stream; charset=' . get_option( 'blog_charset' ) ); // Serialize the export data. echo serialize( $data ); // Start the download. die(); } } /** * Upload import file * * @since 1.0.5 */ public static function upload_import_file() { // Check nonce for security since form was posted if ( ! empty( $_POST ) && ! empty( $_FILES['oceanwp_import_file'] ) && check_admin_referer( 'oceanwp_import', 'oceanwp_import_nonce' ) ) { // check_admin_referer prints fail page and dies // Check and move file to uploads dir, get file data // Will show die with WP errors if necessary (file too large, quota exceeded, etc.) $template = get_template(); $overrides = array( 'test_form' => false, 'test_type' => false, 'mimes' => array( 'dat' => 'text/plain' ) ); $file = wp_handle_upload( $_FILES['oceanwp_import_file'], $overrides ); if ( isset( $file['error'] ) ) { wp_die( $file['error'], '', array( 'back_link' => true ) ); } // Process import file self::process_import_file( $file['file'] ); } } /** * Process import file * * @since 1.0.5 */ public static function process_import_file( $file ) { // File exists? if ( ! file_exists( $file ) ) { wp_die( esc_html__( 'Import file could not be found. Please try again.', 'ocean-extra' ), '', array( 'back_link' => true ) ); } // Get file contents and decode $raw = file_get_contents( $file ); $data = @unserialize( $raw ); // Delete import file unlink( $file ); // If wp_css is set then import it. if ( function_exists( 'wp_update_custom_css_post' ) && isset( $data['wp_css'] ) && '' !== $data['wp_css'] ) { wp_update_custom_css_post( $data['wp_css'] ); } // Import data self::import_data( $data['mods'] ); } /** * Sanitization callback * * @since 1.0.5 */ public static function import_data( $file ) { $msg = null; $type = null; // Import the file if ( ! empty( $file ) ) { if ( '0' == json_last_error() ) { // Loop through mods and add them foreach ( $file as $mod => $value ) { set_theme_mod( $mod, $value ); } // Success message $msg = esc_attr__( 'Settings imported successfully.', 'ocean-extra' ); $type = 'updated'; } // Display invalid json data error else { $msg = esc_attr__( 'Invalid Import Data.', 'ocean-extra' ); $type = 'error'; } } // No json data entered else { $error_msg = esc_attr__( 'No import data found.', 'ocean-extra' ); $error_type = 'error'; } // Display notice add_settings_error( 'oceanwp-import-notices', esc_attr( 'settings_updated' ), $msg, $type ); // Return file return $file; } /** * Settings page output * * @since 1.0.5 */ public static function create_admin_page() { // Theme branding if ( function_exists( 'oceanwp_theme_branding' ) ) { $brand = oceanwp_theme_branding(); } else { $brand = 'OceanWP'; } ?>

.dat file generated by the export button.', 'ocean-extra' ), array( 'b' => array() ) ); ?>

.dat file for all settings.', 'ocean-extra' ), array( 'b' => array() ) ); ?>