Advertisement
sarahn

import_wpml_settings.php

Apr 1st, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <?php
  2. $import = $_GET['import'];
  3.  
  4. if($import == '1'){
  5. require( './wp-load.php' );
  6.  
  7. function wpv_admin_import_export_simplexml2array($element) {
  8. $element = is_string($element) ? trim($element) : $element;
  9. if (!empty($element) && is_object($element)) {
  10. $element = (array) $element;
  11. }
  12. // SRDJAN - slider settings that have 0 values are imported as empty string https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382765/comments
  13. if (!is_array($element) && strval($element) == '0') {
  14. $element = 0;
  15. } else if (empty($element)) {
  16. $element = '';
  17. } else if (is_array($element)) {
  18. foreach ($element as $k => $v) {
  19. $v = is_string($v) ? trim($v) : $v;
  20. if (!is_array($v) && strval($v) == '0') {
  21. $element[$k] = 0;
  22. } else if (empty($v)) {
  23. $element[$k] = '';
  24. continue;
  25. }
  26. $add = wpv_admin_import_export_simplexml2array($v);
  27. if (!is_array($add) && strval($add) == '0') {
  28. $element[$k] = 0;
  29. } else if (!empty($add)) {
  30. $element[$k] = $add;
  31. } else {
  32. $element[$k] = '';
  33. }
  34. }
  35. }
  36.  
  37. if (!is_array($element) && strval($element) == '0') {
  38. $element = 0;
  39. } else if (empty($element)) {
  40. $element = '';
  41. }
  42.  
  43. return $element;
  44. }
  45.  
  46. function wpvdemo_import_wpml() {
  47. global $wpdb;
  48.  
  49. if (defined('ICL_SITEPRESS_VERSION')) {
  50.  
  51. $file = get_site_url() . '/wpml.xml';
  52.  
  53. $file = @wp_remote_get($file);
  54.  
  55. if (is_wp_error($file)) {
  56. return $file;
  57. }
  58.  
  59. $xml = simplexml_load_string($file['body']);
  60.  
  61. // We can use the Views function to convert to an array
  62. $data = wpv_admin_import_export_simplexml2array($xml);
  63.  
  64. // Fix array indexes
  65. $data['translation-management']['__custom_fields_readonly_config_prev'] = $data['translation-management']['__custom_fields_readonly_config_prev']['item'];
  66. $data['translation-management']['custom_fields_readonly_config'] = $data['translation-management']['custom_fields_readonly_config']['item'];
  67.  
  68. // Set the active langauges.
  69. global $wpdb;
  70. foreach($data['wpv_active_languages'] as $code => $active) {
  71. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}icl_languages SET active=%d WHERE code='%s'", $active, $code ));
  72. }
  73.  
  74. unset($data['wpv_active_languages']);
  75.  
  76. update_option('icl_sitepress_settings', $data);
  77.  
  78. return TRUE;
  79. }
  80. return FALSE;
  81. }
  82.  
  83. $wpvdemo_import_wpml = wpvdemo_import_wpml($settings->download_url, $settings);
  84. if($wpvdemo_import_wpml == TRUE && !is_wp_error($wpvdemo_import_wpml)){
  85. echo "Your wpml settings have been successfully imported!";
  86. }else {
  87. echo "Something went wrong. Either WPML is not installed or the wpml.xml could not be found or be opened!";
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement