Want more features on Pastebin? Sign Up, it's FREE!
Guest

Revert DB from Polylang 1.2 to 1.1.6

By: Chouby on Nov 11th, 2013  |  syntax: PHP  |  size: 2.80 KB  |  views: 221  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: Revert Polylang 1.2 to 1.1.6
  4. */
  5.  
  6. /*
  7.  * This plugin removes Polylang 1.2 data, keeping Polylang 1.1.6 data.
  8.  * Read carefully the procedure to follow
  9.  *
  10.  * Procedure:
  11.  *
  12.  * Make a database backup if you did not make one before ugrading to 1.2
  13.  * create a file revert.php and paste all this file (using a text editor such as notepad)
  14.  * upload revert.php in wp-content/plugins
  15.  * De-activate Polylang 1.2.x (DO NOT DELETE IT USING THE RED LINK 'delete' in Plugins table as every data would be removed)
  16.  * activate the plugins 'Revert Polylang 1.2 to 1.1.6'
  17.  * de-activate it
  18.  * Delete the polylang directory in wp-content/plugins
  19.  * download the file http://downloads.wordpress.org/plugin/polylang.1.1.6.zip
  20.  * extract the content and upload the polylang directory in wp-content/plugins
  21.  * activate Polylang 1.1.6
  22.  */
  23.  
  24. add_action('init', 'pll_revert_to_old_db');
  25.  
  26. function pll_revert_to_old_db() {
  27.         if (defined('POLYLANG_VERSION'))
  28.                 return;
  29.  
  30.         global $wpdb;
  31.  
  32.         // delete the strings translations 1.2+
  33.         register_post_type('polylang_mo', array('rewrite' => false, 'query_var' => false));
  34.         $ids = get_posts(array(
  35.                 'post_type'   => 'polylang_mo',
  36.                 'numberposts' => -1,
  37.                 'nopaging'    => true,
  38.                 'fields'      => 'ids',
  39.         ));
  40.         foreach ($ids as $id)
  41.                 wp_delete_post($id, true);
  42.  
  43.         // need to register the taxonomies
  44.         foreach (array('language', 'term_language', 'post_translations', 'term_translations') as $taxonomy)
  45.                 register_taxonomy($taxonomy, null , array('label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false));
  46.  
  47.         // delete all what is related to languages and translations
  48.         foreach (get_terms(array('term_language', 'post_translations', 'term_translations'), array('hide_empty'=>false)) as $term) {
  49.                 $term_ids[] = (int) $term->term_id;
  50.                 $tt_ids[] = (int) $term->term_taxonomy_id;
  51.         }
  52.  
  53.         if (!empty($term_ids)) {
  54.                 $term_ids = array_unique($term_ids);
  55.                 $wpdb->query("DELETE FROM $wpdb->terms WHERE term_id IN (" . implode(',', $term_ids) . ")");
  56.                 $wpdb->query("DELETE FROM $wpdb->term_taxonomy WHERE term_id IN (" . implode(',', $term_ids) . ")");
  57.         }
  58.  
  59.         if (!empty($tt_ids)) {
  60.                 $tt_ids = array_unique($tt_ids);
  61.                 $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode(',', $tt_ids) . ")");
  62.         }
  63.  
  64.         $languages = get_terms('language', array('hide_empty' => 0));
  65.  
  66.         foreach($languages as $lang) {
  67.                 $description = maybe_unserialize($lang->description);
  68.                 if (is_array($description))
  69.                         wp_update_term((int) $lang->term_id, 'language', array('description' => $description['locale']));
  70.         }
  71.  
  72.         $options = get_option('polylang');
  73.         $options['version'] = '1.1.6';
  74.         update_option('polylang', $options);
  75. }
clone this paste RAW Paste Data