function sds_customize_preview_init()
{
    global $sds_theme_options;
    $sds_theme_options = SDS_Theme_Options::get_sds_theme_options();
    /**
     * Remove Logo backwards compatibility check
     *
     * If 'remove-logo' is set in the options array, we need to remove it here
     * to ensure the Theme Customizer will save the logo information correctly.
     * This is due to the Theme Options sanitize function running on save of Theme
     * Customizer, which checks for 'remove-logo' and nulls the logo_attachment_id
     * value if it's set. We're now unset()ing 'remove-logo' if it is set in Theme
     * Options, however previous versions were not doing so. This check is necessary
     * for backwards compatibility.
     */
    if (isset($sds_theme_options['remove-logo'])) {
        unset($sds_theme_options['remove-logo']);
        update_option(SDS_Theme_Options::get_option_name(), $sds_theme_options);
    }
}
Exemple #2
0
 /**
  * This function updates legacy Conductor Widgets to ensure legacy widget displays/sizes are
  * switched to the new custom (flexbox) display. This function ensures the current version of
  * Conductor is at least 1.3.0.
  *
  * It also updates the order of the output elements to ensure that the author byline output
  * element is at the bottom.
  */
 public function update_conductor_widgets($after_switch_theme = false)
 {
     global $sds_theme_options;
     // Bail if we don't have options stored in the database
     if (!SDS_Theme_Options::has_options()) {
         return;
     }
     // Grab SDS Theme Options
     $sds_theme_options = SDS_Theme_Options::get_sds_theme_options();
     // If Conductor Widget exists and we haven't already updated legacy widget sizes
     if (function_exists('Conduct_Widget') && (!isset($sds_theme_options['baton_conductor_widgets_updated']) || !$sds_theme_options['baton_conductor_widgets_updated'] || $after_switch_theme)) {
         // Grab the Conductor Widget instance
         $conductor_widget = Conduct_Widget();
         // Grab all Conductor Widget instances
         $all_instances = $conductor_widget->get_settings();
         // If Conductor is greater than 1.2.9 or Conductor Widget instance has the "displays" property, we can check to see if the custom display exists
         if ($this->conductor_has_flexbox_display($conductor_widget)) {
             // Loop through instances (passing by reference)
             foreach ($all_instances as $number => &$instance) {
                 // Only if this instance isn't empty
                 if (!empty($instance)) {
                     // Legacy display
                     if (in_array($instance['widget_size'], array('small', 'medium', 'large'))) {
                         // Switch based on widget size
                         switch ($instance['widget_size']) {
                             case 'small':
                                 // Flexbox Columns (4 columns)
                                 $instance['flexbox']['columns'] = 4;
                                 $instance['flexbox_columns'] = 4;
                                 break;
                                 // Medium
                             // Medium
                             case 'medium':
                                 // Flexbox Columns (2 columns)
                                 $instance['flexbox']['columns'] = 2;
                                 $instance['flexbox_columns'] = 2;
                                 break;
                                 // Large
                             // Large
                             case 'large':
                                 // Flexbox Columns (1 column)
                                 $instance['flexbox']['columns'] = 1;
                                 $instance['flexbox_columns'] = 1;
                                 break;
                         }
                         // Widget Size (display)
                         $instance['widget_size'] = 'flexbox';
                         // Custom (Flexbox)
                     }
                 }
             }
             // Set the update flag
             $sds_theme_options['baton_conductor_widgets_updated'] = true;
             update_option(SDS_Theme_Options::get_option_name(), $sds_theme_options);
         }
         // Only on after_switch_theme
         if ($after_switch_theme) {
             /*
              * Conductor Output Elements
              */
             $author_byline = array();
             // Remove the reference to the $instance
             unset($instance);
             // Conductor output elements, Loop through instances (passing by reference)
             foreach ($all_instances as $number => &$instance) {
                 // Only if this instance isn't empty
                 if (!empty($instance) && isset($instance['output'])) {
                     // Loop through output elements
                     foreach ($instance['output'] as $priority => $output) {
                         // Author Byline (store reference to priority and configuration)
                         if ($output['id'] === 'author_byline') {
                             $author_byline = $output;
                             // Remove author byline
                             unset($instance['output'][$priority]);
                         }
                     }
                     /*
                      * Author Byline (move to bottom of default output elements)
                      */
                     $output_elements = array();
                     $default_priority_gap = 10;
                     $count = 0;
                     // Loop through the passed in widget settings
                     foreach ($instance['output'] as $output) {
                         // Increase count
                         $count++;
                         // Add this element to the output elements
                         $output_elements[$default_priority_gap * $count] = $output;
                     }
                     // Author Byline (increase count before multiplying)
                     $output_elements[$default_priority_gap * ++$count] = $author_byline;
                     // Set the default output
                     $instance['output'] = $output_elements;
                 }
             }
         }
         // Update the database
         $conductor_widget->save_settings($all_instances);
     }
 }