()


false, 'mimes' => array( 'txt' => 'text/plain' ) ) ); if ( isset( $import_file['error'] ) ) wp_die( $import_file['error'] ); /* Get filesystem credentials to read the file */ global $wp_filesystem; $url = wp_nonce_url( 'customize.php?blograzzi-import=1', 'blograzzi-import' ); if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, array( 'import' ) ) ) ) return true; if ( ! WP_Filesystem( $creds ) ) { request_filesystem_credentials( $url, $method, true, false, $form_fields ); return true; } $data = $wp_filesystem->get_contents( $import_file['file'] ); wp_delete_file( $import_file['file'] ); /* Check that the file has data */ if ( $data === false ) wp_die( __( 'Could not read uploaded file. Please check the file and try again.', 'blograzzi' ) ); /* Check that the file data is Blograzzi settings */ $settings = json_decode( $data, true ); if ( ! $settings ) wp_die( __( 'Uploaded file does not contain any setting to import. Please check and try again.', 'blograzzi' ) ); if ( ! isset( $settings['db_version'] ) ) wp_die( __( 'The uploaded file does not contain valid Blograzzi options. Please check and try again.', 'blograzzi' ) ); /* Update the settings if everything checks out */ $settings = array_merge( $blograzzi_settings, $settings ); update_option( 'blograzzi_settings', $settings ); } add_action( 'admin_init', 'blograzzi_import_file' );