Exemplo n.º 1
0
 public function __construct()
 {
     Avada::$is_updating = true;
     /* Raise the memory limit and max_execution_time time */
     @ini_set('memory_limit', '256M');
     @set_time_limit(0);
     $this->available_languages = Avada_Multilingual::get_available_languages();
     $this->active_language = Avada_Multilingual::get_active_language();
     $this->default_language = Avada_Multilingual::get_default_language();
     // If English is used then make this first in array order.  Also set starting language so that it is migrated first
     if (in_array('en', $this->available_languages)) {
         $en_array = array('en');
         $en_key = array_search('en', $this->available_languages);
         $available_languages_no_en = $this->available_languages;
         unset($available_languages_no_en[$en_key]);
         $this->available_languages = array_merge($en_array, $available_languages_no_en);
         $this->starting_language = 'en';
     } else {
         // If not English then make default language first in array order.  Also set it to be starting language for migration.
         $default_array = array($this->default_language);
         $default_key = array_search($this->default_language, $this->available_languages);
         $available_languages_no_default = $this->available_languages;
         unset($available_languages_no_default[$default_key]);
         $this->available_languages = array_merge($default_array, $available_languages_no_default);
         $this->starting_language = $this->default_language;
     }
     if ($_GET && isset($_GET['avada_update'])) {
         // Only continue if the URL is ?avada_update=1
         if ('1' != $_GET['avada_update']) {
             return;
         }
         // Only continue if we're updating to version 4.0.0
         if (!isset($_GET['ver']) || $this->version != $_GET['ver']) {
             return;
         }
         // Get the current step
         if (!isset($_GET['step'])) {
             $this->step = 0;
         } else {
             $this->step = intval($_GET['step']);
         }
         if (isset($_GET['proceed']) && '0' == $_GET['proceed']) {
             $this->proceed = false;
         }
         if (isset($_GET['lang']) && !in_array($_GET['lang'], array('', 'en', 'all', null))) {
             Avada_Multilingual::set_active_language($_GET['lang']);
         }
         $this->options = get_option(Avada::get_option_name(), array());
         $this->fields = Avada_Options::get_option_fields();
         add_action('admin_init', array($this, 'migrate_page'));
     }
 }
 public function __construct()
 {
     // Only run on the dashboard
     if (!is_admin()) {
         return;
     }
     // Set the version
     $this->version = '400';
     // Set the language
     if ($_GET && isset($_GET['lang'])) {
         $this->lang = $_GET['lang'];
     }
     if (!empty($this->lang) && !Avada::$lang_applied) {
         Avada_Multilingual::set_active_language($this->lang);
     }
     $default_old_options = get_option('Avada_options', array());
     // for multilingual sites, set the language for the options
     if (!in_array($this->lang, array('', 'en', 'all', null))) {
         $old_options = get_option('Avada_options_' . Avada_Multilingual::get_active_language(), array());
     } else {
         $old_options = $default_old_options;
     }
     $new_options = get_option(Avada::get_option_name(), array());
     // If clean install, set builder and encoding active
     if (empty($old_options) && empty($new_options)) {
         update_option('avada_disable_builder', 1);
         update_option('avada_disable_encoding', 1);
     }
     // No need to proceed if there's no data at all to migrate
     if (empty($default_old_options)) {
         return;
     }
     // Add migration steps for previous versions of Avada
     parent::update_installation(true);
     parent::migrate();
     // No need to proceed if the old options are empty
     if (empty($old_options) && !Avada_Multilingual::get_available_languages()) {
         return;
     }
     // Redirect to the migration script if needed
     $trigger_migration = false;
     if (!$_GET || !isset($_GET['avada_update']) || '1' != $_GET['avada_update']) {
         if (!empty($old_options)) {
             if (empty($new_options)) {
                 $trigger_migration = true;
             } else {
                 // Get a record of already run migrations
                 // and determine if we should continue or not
                 $migration_run = get_option('avada_migrations', array());
                 if (isset($migration_run[$this->version])) {
                     if (is_array($migration_run[$this->version])) {
                         if (isset($migration_run[$this->version]['finished']) && true !== $migration_run[$this->version]['finished']) {
                             $trigger_migration = true;
                         }
                         if (isset($migration_run[$this->version]['started']) && true !== $migration_run[$this->version]['started']) {
                             $trigger_migration = true;
                         }
                     } else {
                         $trigger_migration = true;
                     }
                 } else {
                     $trigger_migration = true;
                 }
             }
         }
     }
     if ($trigger_migration) {
         wp_redirect(trailingslashit(admin_url()) . 'index.php?avada_update=1&ver=400&step=0&new=1');
         exit;
     }
     // Define the migration steps
     $this->steps = array(array('callback' => '__return_true', 'description' => esc_html__('Preparing to run Upgrade', 'Avada')), array('callback' => array($this, 'migrate_sliders'), 'description' => esc_html__('Slider controls', 'Avada')), array('callback' => array($this, 'migrate_checkboxes'), 'description' => esc_html__('Checkbox & Switch controls', 'Avada')), array('callback' => array($this, 'dimension'), 'description' => esc_html__('Dimension controls', 'Avada')), array('callback' => array($this, 'social'), 'description' => esc_html__('Social Networks', 'Avada')), array('callback' => array($this, 'color_alpha'), 'description' => esc_html__('HEX to RGBA colors conversion', 'Avada')), array('callback' => array($this, 'color_hex'), 'description' => esc_html__('HEX colors', 'Avada')), array('callback' => array($this, 'media_files'), 'description' => esc_html__('Media Files', 'Avada')), array('callback' => array($this, 'spacing_1'), 'description' => esc_html__('Spacing Options', 'Avada')), array('callback' => array($this, 'custom_fonts'), 'description' => esc_html__('Custom Fonts', 'Avada')), array('callback' => array($this, 'typography_1'), 'description' => sprintf(esc_html__('Typography Options (step %s of %s)', 'Avada'), '1', '2')), array('callback' => array($this, 'typography_2'), 'description' => sprintf(esc_html__('Typography Options (step %s of %s)', 'Avada'), '2', '2')), array('callback' => array($this, 'other_options'), 'description' => esc_html__('Other Options', 'Avada')));
     // Run the parent class constructor
     parent::__construct();
     // Copy the old options to the new options for new migrations
     if ($_GET && isset($_GET['new']) && 1 == $_GET['new']) {
         $migration_run = get_option('avada_migrations', array());
         $migration_run[$this->version]['started'] = true;
         $migration_run[$this->version]['finished'] = false;
         if (!isset($migration_run['copied'])) {
             $migration_run['copied'] = false;
         }
         // Copy default options
         $old_options = get_option('Avada_options', array());
         $original_option_name = Avada::get_original_option_name();
         if (false == $migration_run['copied']) {
             update_option($original_option_name, $old_options);
         }
         // Check multilingual installations
         if (Avada_Multilingual::get_available_languages() && false == $migration_run['copied']) {
             // Loop languages
             foreach (Avada_Multilingual::get_available_languages() as $language) {
                 // Process secondary languages.
                 // 'en' & 'all' have already been handled before we check for multilingual.
                 if (!in_array($language, array('', 'en', 'all', null))) {
                     // Get the old language options
                     $old_language_options = get_option('Avada_options_' . $language, array());
                     // If the old language options are empty, use the standard options instead.
                     if (empty($old_language_options)) {
                         $old_language_options = $old_options;
                     }
                     // Update the new language options with the old ones
                     update_option($original_option_name . '_' . $language, $old_language_options);
                 }
             }
             $migration_run['copied'] = true;
         }
         update_option('avada_migrations', $migration_run);
     }
 }