<?php
/*
Plugin Name: Revert Polylang 1.2 to 1.1.6
*/
/*
* This plugin removes Polylang 1.2 data, keeping Polylang 1.1.6 data.
* Read carefully the procedure to follow
*
* Procedure:
*
* Make a database backup if you did not make one before ugrading to 1.2
* create a file revert.php and paste all this file (using a text editor such as notepad)
* upload revert.php in wp-content/plugins
* De-activate Polylang 1.2.x (DO NOT DELETE IT USING THE RED LINK 'delete' in Plugins table as every data would be removed)
* activate the plugins 'Revert Polylang 1.2 to 1.1.6'
* de-activate it
* Delete the polylang directory in wp-content/plugins
* download the file http://downloads.wordpress.org/plugin/polylang.1.1.6.zip
* extract the content and upload the polylang directory in wp-content/plugins
* activate Polylang 1.1.6
*/
add_action('init', 'pll_revert_to_old_db');
function pll_revert_to_old_db() {
if (defined('POLYLANG_VERSION'))
return;
global $wpdb;
// delete the strings translations 1.2+
register_post_type('polylang_mo', array('rewrite' => false, 'query_var' => false));
$ids = get_posts(array(
'post_type' => 'polylang_mo',
'numberposts' => -1,
'nopaging' => true,
'fields' => 'ids',
));
foreach ($ids as $id)
wp_delete_post($id, true);
// need to register the taxonomies
foreach (array('language', 'term_language', 'post_translations', 'term_translations') as $taxonomy)
register_taxonomy($taxonomy, null , array('label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false));
// delete all what is related to languages and translations
foreach (get_terms(array('term_language', 'post_translations', 'term_translations'), array('hide_empty'=>false)) as $term) {
$term_ids[] = (int) $term->term_id;
$tt_ids[] = (int) $term->term_taxonomy_id;
}
if (!empty($term_ids)) {
$term_ids = array_unique($term_ids);
$wpdb->query("DELETE FROM $wpdb->terms WHERE term_id IN (" . implode(',', $term_ids) . ")");
$wpdb->query("DELETE FROM $wpdb->term_taxonomy WHERE term_id IN (" . implode(',', $term_ids) . ")");
}
if (!empty($tt_ids)) {
$tt_ids = array_unique($tt_ids);
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode(',', $tt_ids) . ")");
}
$languages = get_terms('language', array('hide_empty' => 0));
foreach($languages as $lang) {
$description = maybe_unserialize($lang->description);
if (is_array($description))
wp_update_term((int) $lang->term_id, 'language', array('description' => $description['locale']));
}
$options = get_option('polylang');
$options['version'] = '1.1.6';
update_option('polylang', $options);
}