Please remember that this is still an experimental feature.', 'mantra'); ?>

( )

0) ) ) { $form_fields = array('import'); $method = ''; $url = wp_nonce_url('themes.php?page=mantra-page', 'mantra-import'); // Get file writing credentials if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $form_fields) ) ) { return true; } if ( ! WP_Filesystem($creds) ) { // our credentials were no good, ask the user for them again request_filesystem_credentials($url, $method, true, false, $form_fields); return true; } // Write the file if credentials are good $upload_dir = wp_upload_dir(); $filename = trailingslashit($upload_dir['path']).'mantra_options.txt'; // by this point, the $wp_filesystem global should be working, so let's use it to create a file global $wp_filesystem; if ( ! $wp_filesystem->move($_FILES['import']['tmp_name'], $filename, true) ) { echo 'Error saving file!'; return; } $file = $_FILES['import']; if ($file['type'] == 'text/plain') { $data = $wp_filesystem->get_contents($filename); // try to read the file if ($data !== FALSE){ $settings = json_decode($data, true); // try to read the settings array if (isset($settings['mantra_db'])){ ?>

'. __('Great! The options have been imported!', 'mantra').'
'; echo ''.__('Go back to the Mantra options page and check them out!', 'mantra').'

'; } else { // else: try to read the settings array echo '

'.__('Oops, there\'s a small problem.', 'mantra').'
'; echo __('The uploaded file does not contain valid Mantra options. Make sure the file is exported from the Mantra Options page.', 'mantra').'

'; mantra_import_form(); } } else { // else: try to read the file echo '

'.__('Oops, there\'s a small problem.', 'mantra').'
'; echo __('The uploaded file could not be read.', 'mantra').'

'; mantra_import_form(); } } else { // else: make sure the file uploaded was a plain text file echo '

'.__('Oops, there\'s a small problem.', 'mantra').'
'; echo __('The uploaded file is not supported. Make sure the file was exported from the Mantra page and that it is a text file.', 'mantra').'

'; mantra_import_form(); } // Delete the file after we're done $wp_filesystem->delete($filename); } else { // else: make sure there is an import file uploaded echo '

'.__( 'Oops! The file is empty or there was no file. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'mantra' ).'

'; mantra_import_form(); } echo ' '; } else { wp_die(__('ERROR: You are not authorised to perform that operation', 'mantra')); } } // Closes the mantra_import_file() function definition // Truncate function for use in the Admin RSS feed function mantra_truncate_words($string,$words=20, $ellipsis=' ...') { $new = preg_replace('/((\w+\W+\'*){'.($words-1).'}(\w+))(.*)/', '${1}', $string); return $new.$ellipsis; } ?>