previous_theme_versions = get_option( 'avada_previous_version', array() ); // Previous version only really needed, because through the upgrade loop, the database_theme_version will be altered. $this->previous_theme_version = $this->get_previous_theme_version(); $this->database_theme_version = get_option( 'avada_version', false ); $this->database_theme_version = Avada_Helper::normalize_version( $this->database_theme_version ); $this->current_theme_version = Avada::get_theme_version(); $this->current_theme_version = Avada_Helper::normalize_version( $this->current_theme_version ); // Check through all options names that were available for Theme Options in databse. $theme_options = get_option( Avada::get_option_name(), get_option( 'avada_theme_options', get_option( 'Avada_options', false ) ) ); // If no old version is in database or there are no saved options, // this is a new install, nothing to do, but to copy version to db. if ( false === $this->database_theme_version || ! $theme_options ) { $this->fresh_installation(); return; // If on front-end and user intervention necessary, do not continue. } elseif ( ! is_admin() && version_compare( $this->database_theme_version, '5.0.1', '<' ) ) { return; } // Each version is defined as an array( 'Version', 'Force-Instantiation' ). $versions = array( '385' => array( '3.8.5', false ), '387' => array( '3.8.7', false ), '390' => array( '3.9.0', false ), '392' => array( '3.9.2', false ), '400' => array( '4.0.0', true ), '402' => array( '4.0.2', false ), '403' => array( '4.0.3', false ), '500' => array( '5.0.0', true ), '503' => array( '5.0.3', false ), '510' => array( '5.1.0', false ), '516' => array( '5.1.6', false ), '520' => array( '5.2.0', false ), '521' => array( '5.2.1', false ), '530' => array( '5.3.0', false ), '540' => array( '5.4.0', false ), '541' => array( '5.4.1', false ), '542' => array( '5.4.2', false ), '550' => array( '5.5.0', false ), '551' => array( '5.5.1', false ), '552' => array( '5.5.2', false ), ); $upgraded = false; foreach ( $versions as $key => $version ) { $classname = 'Avada_Upgrade_' . $key; if ( $this->database_theme_version && version_compare( $this->database_theme_version, $version[0], '<' ) ) { $upgraded = true; // Instantiate the class if migration is needed. if ( class_exists( $classname ) ) { new $classname(); } } elseif ( true === $version[1] ) { // Instantiate the class if force-instantiation is set to true. if ( class_exists( $classname ) ) { new $classname( true ); } } } if ( true === $upgraded ) { // Reset all Fusion caches. if ( ! class_exists( 'Fusion_Cache' ) ) { include_once Avada::$template_dir_path . '/includes/lib/inc/class-fusion-cache.php'; } $fusion_cache = new Fusion_Cache(); $fusion_cache->reset_all_caches(); } /** * Don't do anything when in the Customizer. */ global $wp_customize; if ( $wp_customize ) { return; } add_action( 'init', array( $this, 'update_installation' ) ); } /** * Make sure there's only 1 instance of this class running. * * @static * @access public * @return object */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new Avada_Upgrade(); } return self::$instance; } /** * Get the previous theme version from database. * * @access public * @return string The previous theme version. */ public function get_previous_theme_version() { if ( is_array( $this->previous_theme_versions ) && ! empty( $this->previous_theme_versions ) ) { $this->previous_theme_version = end( $this->previous_theme_versions ); reset( $this->previous_theme_versions ); } else { $this->previous_theme_version = $this->previous_theme_versions; } // Make sure the theme version has 3 digits. return Avada_Helper::normalize_version( $this->previous_theme_version ); } /** * Actions to run on a fresh installation. */ public function fresh_installation() { update_option( 'avada_version', $this->current_theme_version ); $this->clear_update_theme_transient(); } /** * Clear update_themes transient after update. Fix for #5048. */ public function clear_update_theme_transient() { delete_site_transient( 'update_themes' ); } /** * Actions to run on an update installation. * * @param bool $skip400 Skips the migration to 4.0 if set to true. */ public function update_installation( $skip400 = false ) { global $current_user; $this->current_user = $current_user; $this->debug(); if ( version_compare( $this->current_theme_version, $this->database_theme_version, '>' ) ) { // Delete the update notice dismiss flag, so that the flag is reset. if ( ! $skip400 ) { delete_user_meta( $this->current_user->ID, 'avada_pre_385_notice' ); delete_user_meta( $this->current_user->ID, 'avada_update_notice' ); // Delete the TGMPA update notice dismiss flag, so that the flag is reset. delete_user_meta( $this->current_user->ID, 'tgmpa_dismissed_notice_tgmpa' ); } $this->update_version(); } // Hook the dismiss notice functionality. if ( ! $skip400 ) { add_action( 'admin_init', array( $this, 'notices_action' ) ); } // Show upgrade notices. if ( version_compare( $this->current_theme_version, '5.1.0', '<=' ) ) { add_action( 'admin_notices', array( $this, 'upgrade_notice' ) ); } } /** * Update the avada version in the database and reset flags. */ public function update_version() { if ( version_compare( $this->current_theme_version, $this->database_theme_version, '>' ) ) { // Update the stored theme versions. update_option( 'avada_version', $this->current_theme_version ); $this->clear_update_theme_transient(); if ( $this->previous_theme_versions ) { if ( is_array( $this->previous_theme_versions ) ) { $versions_array = $this->previous_theme_versions; $versions_array[] = $this->database_theme_version; } else { $versions_array = array( $this->previous_theme_versions, ); } } else { $versions_array = array( $this->database_theme_version, ); } update_option( 'avada_previous_version', $versions_array ); } } /** * Notices that will show to users that upgrade */ public function upgrade_notice() { /* Check that the user hasn't already clicked to ignore the message */ if ( $this->previous_theme_version && current_user_can( 'edit_theme_options' ) && ! get_user_meta( $this->current_user->ID, 'avada_update_notice', true ) ) { echo '
The following important changes were made to Avada 3.8.5:
The following important changes were made to Avada 3.8.6:
The following important changes were made to Avada 3.8.7:
The following important changes were made to Avada 3.9:
Please view the important update information for Avada 5.1:
You can view all update information here: Important Update Information