Esempio n. 1
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);
     }
 }
Esempio n. 2
0
function sds_after_switch_theme()
{
    global $sds_theme_options;
    // Bail if we don't have options stored in the database
    if (!SDS_Theme_Options::has_options()) {
        return;
    }
    $sds_theme_option_defaults = SDS_Theme_Options::get_sds_theme_option_defaults();
    // Defaults
    // Color Scheme (reset if necessary)
    if (!empty($sds_theme_options['color_scheme']) && function_exists('sds_color_schemes')) {
        $color_scheme = $sds_theme_options['color_scheme'];
        $color_schemes = sds_color_schemes();
        if (!isset($color_schemes[$color_scheme])) {
            $sds_theme_options['color_scheme'] = $sds_theme_option_defaults['color_scheme'];
        }
    }
    // Web Font (reset if necessary)
    if (!empty($sds_theme_options['web_font']) && function_exists('sds_web_fonts')) {
        $web_font = $sds_theme_options['web_font'];
        $web_fonts = sds_web_fonts();
        if (!isset($web_fonts[$web_font])) {
            $sds_theme_options['web_font'] = $sds_theme_option_defaults['web_font'];
        }
    }
    // Content Layouts (reset if necessary)
    if (function_exists('sds_content_layouts')) {
        $content_layouts = $sds_theme_options['content_layouts'];
        $sds_content_layouts = sds_content_layouts();
        foreach ($content_layouts as $content_layout_id => $content_layout) {
            if ($content_layout && !isset($sds_content_layouts[$content_layout])) {
                $sds_theme_options['content_layouts'][$content_layout_id] = $sds_theme_option_defaults['content_layouts'][$content_layout_id];
            }
        }
    }
    // Update the option with new values
    update_option(SDS_Theme_Options::get_option_name(), $sds_theme_options);
}