Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $import = $_GET['import'];
- if($import == '1'){
- require( './wp-load.php' );
- function wpv_admin_import_export_simplexml2array($element) {
- $element = is_string($element) ? trim($element) : $element;
- if (!empty($element) && is_object($element)) {
- $element = (array) $element;
- }
- // SRDJAN - slider settings that have 0 values are imported as empty string https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382765/comments
- if (!is_array($element) && strval($element) == '0') {
- $element = 0;
- } else if (empty($element)) {
- $element = '';
- } else if (is_array($element)) {
- foreach ($element as $k => $v) {
- $v = is_string($v) ? trim($v) : $v;
- if (!is_array($v) && strval($v) == '0') {
- $element[$k] = 0;
- } else if (empty($v)) {
- $element[$k] = '';
- continue;
- }
- $add = wpv_admin_import_export_simplexml2array($v);
- if (!is_array($add) && strval($add) == '0') {
- $element[$k] = 0;
- } else if (!empty($add)) {
- $element[$k] = $add;
- } else {
- $element[$k] = '';
- }
- }
- }
- if (!is_array($element) && strval($element) == '0') {
- $element = 0;
- } else if (empty($element)) {
- $element = '';
- }
- return $element;
- }
- function wpvdemo_import_wpml() {
- global $wpdb;
- if (defined('ICL_SITEPRESS_VERSION')) {
- $file = get_site_url() . '/wpml.xml';
- $file = @wp_remote_get($file);
- if (is_wp_error($file)) {
- return $file;
- }
- $xml = simplexml_load_string($file['body']);
- // We can use the Views function to convert to an array
- $data = wpv_admin_import_export_simplexml2array($xml);
- // Fix array indexes
- $data['translation-management']['__custom_fields_readonly_config_prev'] = $data['translation-management']['__custom_fields_readonly_config_prev']['item'];
- $data['translation-management']['custom_fields_readonly_config'] = $data['translation-management']['custom_fields_readonly_config']['item'];
- // Set the active langauges.
- global $wpdb;
- foreach($data['wpv_active_languages'] as $code => $active) {
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}icl_languages SET active=%d WHERE code='%s'", $active, $code ));
- }
- unset($data['wpv_active_languages']);
- update_option('icl_sitepress_settings', $data);
- return TRUE;
- }
- return FALSE;
- }
- $wpvdemo_import_wpml = wpvdemo_import_wpml($settings->download_url, $settings);
- if($wpvdemo_import_wpml == TRUE && !is_wp_error($wpvdemo_import_wpml)){
- echo "Your wpml settings have been successfully imported!";
- }else {
- echo "Something went wrong. Either WPML is not installed or the wpml.xml could not be found or be opened!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement