Created
October 8, 2018 10:05
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Fusion Slider Upgrade Script | |
* Plugin URI: https://theme-fusion.com | |
* Description: Runs Fusion Slider upgrade script for Avada 5.6.2 → 5.7 update. Upgrade script will be run automatically on plugin update, after which plugin should be disabled. | |
* Version: 1.0 | |
* Author: ThemeFusion | |
* Author URI: https://theme-fusion.com | |
*/ | |
if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { | |
add_action( 'init', 'fusion_migrate_fusion_slider_options', 99 ); | |
} | |
/** | |
* Migrate Fusion Slider options to term meta table. | |
*/ | |
function fusion_migrate_fusion_slider_options() { | |
global $sitepress; | |
if ( ! taxonomy_exists( 'slide-page' ) ) { | |
register_taxonomy( 'slide-page', null ); | |
} | |
$args = array( | |
'taxonomy' => 'slide-page', | |
'hide_empty' => false, | |
'number' => 0, | |
'fields' => 'id=>name', | |
); | |
// Polylang: query fetch terms for all languages. | |
if ( function_exists( 'pll_default_language' ) ) { | |
$args['lang'] = ''; | |
} | |
if ( $sitepress ) { | |
// WPML: remove filters so terms for all languages are fetched. | |
remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) ); | |
remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ) ); | |
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) ); | |
$sliders = get_terms( $args ); | |
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 ); | |
add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 ); | |
add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 ); | |
} else { | |
$sliders = get_terms( $args ); | |
} | |
foreach ( $sliders as $term_id => $term_name ) { | |
$slider_options = get_option( 'taxonomy_' . $term_id ); | |
if ( $slider_options ) { | |
update_term_meta( $term_id, 'fusion_slider_options', $slider_options ); | |
} | |
// Delete wp_options' entry as don't need it any more. | |
delete_option( 'taxonomy_' . $term_id ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment