/** * Handle sidebars config after theme change * * @access private * @since 3.3 */ function _wp_sidebars_changed() { global $sidebars_widgets; if (!is_array($sidebars_widgets)) { $sidebars_widgets = wp_get_sidebars_widgets(); } retrieve_widgets(true); }
/** * Execute changes made in WordPress 3.3. * * @since 3.3.0 */ function upgrade_330() { global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; if ($wp_current_db_version < 19061 && is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) { $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')"); } if ($wp_current_db_version >= 11548) { return; } $sidebars_widgets = get_option('sidebars_widgets', array()); $_sidebars_widgets = array(); if (isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets)) { $sidebars_widgets['array_version'] = 3; } elseif (!isset($sidebars_widgets['array_version'])) { $sidebars_widgets['array_version'] = 1; } switch ($sidebars_widgets['array_version']) { case 1: foreach ((array) $sidebars_widgets as $index => $sidebar) { if (is_array($sidebar)) { foreach ((array) $sidebar as $i => $name) { $id = strtolower($name); if (isset($wp_registered_widgets[$id])) { $_sidebars_widgets[$index][$i] = $id; continue; } $id = sanitize_title($name); if (isset($wp_registered_widgets[$id])) { $_sidebars_widgets[$index][$i] = $id; continue; } $found = false; foreach ($wp_registered_widgets as $widget_id => $widget) { if (strtolower($widget['name']) == strtolower($name)) { $_sidebars_widgets[$index][$i] = $widget['id']; $found = true; break; } elseif (sanitize_title($widget['name']) == sanitize_title($name)) { $_sidebars_widgets[$index][$i] = $widget['id']; $found = true; break; } } if ($found) { continue; } unset($_sidebars_widgets[$index][$i]); } } } $_sidebars_widgets['array_version'] = 2; $sidebars_widgets = $_sidebars_widgets; unset($_sidebars_widgets); case 2: $sidebars_widgets = retrieve_widgets(); $sidebars_widgets['array_version'] = 3; update_option('sidebars_widgets', $sidebars_widgets); } }
foreach ($sidebars_widgets as $sidebar_id => $widgets) { if ('wp_inactive_widgets' == $sidebar_id) { continue; } if (!isset($wp_registered_sidebars[$sidebar_id])) { if (!empty($widgets)) { // register the inactive_widgets area as sidebar register_sidebar(array('name' => __('Inactive Sidebar (not used)'), 'id' => $sidebar_id, 'class' => 'inactive-sidebar orphan-sidebar', 'description' => __('This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '')); } else { unset($sidebars_widgets[$sidebar_id]); } } } // register the inactive_widgets area as sidebar register_sidebar(array('name' => __('Inactive Widgets'), 'id' => 'wp_inactive_widgets', 'class' => 'inactive-sidebar', 'description' => __('Drag widgets here to remove them from the sidebar but keep their settings.'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '')); retrieve_widgets(); // We're saving a widget without js if (isset($_POST['savewidget']) || isset($_POST['removewidget'])) { $widget_id = $_POST['widget-id']; check_admin_referer("save-delete-widget-{$widget_id}"); $number = isset($_POST['multi_number']) ? (int) $_POST['multi_number'] : ''; if ($number) { foreach ($_POST as $key => $val) { if (is_array($val) && preg_match('/__i__|%i%/', key($val))) { $_POST[$key] = array($number => array_shift($val)); break; } } } $sidebar_id = $_POST['sidebar']; $position = isset($_POST[$sidebar_id . '_position']) ? (int) $_POST[$sidebar_id . '_position'] - 1 : 0;
/** * Override sidebars_widgets for theme switch. * * When switching a theme via the Customizer, supply any previously-configured * sidebars_widgets from the target theme as the initial sidebars_widgets * setting. Also store the old theme's existing settings so that they can * be passed along for storing in the sidebars_widgets theme_mod when the * theme gets switched. * * @since 3.9.0 * @access public * * @global array $sidebars_widgets * @global array $_wp_sidebars_widgets */ public function override_sidebars_widgets_for_theme_switch() { global $sidebars_widgets; if ($this->manager->doing_ajax() || $this->manager->is_theme_active()) { return; } $this->old_sidebars_widgets = wp_get_sidebars_widgets(); add_filter('customize_value_old_sidebars_widgets_data', array($this, 'filter_customize_value_old_sidebars_widgets_data')); // retrieve_widgets() looks at the global $sidebars_widgets $sidebars_widgets = $this->old_sidebars_widgets; $sidebars_widgets = retrieve_widgets('customize'); add_filter('option_sidebars_widgets', array($this, 'filter_option_sidebars_widgets_for_theme_switch'), 1); // reset global cache var used by wp_get_sidebars_widgets() unset($GLOBALS['_wp_sidebars_widgets']); }
function copy_theme_mods($from, $to) { // we can copy settings from parent to child even if neither is currently active // so we need cases for active parent, active child or neither // get active theme $active_theme = get_stylesheet(); $this->debug('from: ' . $from . ' to: ' . $to . ' active: ' . $active_theme, __FUNCTION__); // create temp array from parent settings $child_mods = get_option('theme_mods_' . $from); if ($active_theme == $from) { $this->debug('from is active, using active widgets', __FUNCTION__); // if parent theme is active, get widgets from active sidebars_widgets array $child_widgets = retrieve_widgets(); } else { $this->debug('from not active, using theme mods widgets', __FUNCTION__); // otherwise get widgets from parent theme mods $child_widgets = empty($child_mods['sidebars_widgets']['data']) ? array('wp_inactive_widgets' => array()) : $child_mods['sidebars_widgets']['data']; } if ($active_theme == $to) { $this->debug('to active, setting active widgets', __FUNCTION__); // if child theme is active, remove widgets from temp array unset($child_mods['sidebars_widgets']); // copy widgets to active sidebars_widgets array wp_set_sidebars_widgets($child_widgets); } else { $this->debug('child not active, saving widgets in theme mods', __FUNCTION__); // otherwise copy widgets to temp array with time stamp $child_mods['sidebars_widgets']['data'] = $child_widgets; $child_mods['sidebars_widgets']['time'] = time(); } $this->debug('saving child theme mods:' . LF . print_r($child_mods, TRUE), __FUNCTION__); // copy temp array to child mods update_option('theme_mods_' . $to, $child_mods); }
function bizzthemes_layout() { global $wpdb, $wp_version, $wp_registered_widget_updates, $wp_registered_sidebars, $wp_registered_widgets, $bizz_package, $sidebars_widgets; // Permissions Check if (!current_user_can('edit_theme_options')) { wp_die(__('Cheatin’ uh?', 'bizzthemes')); } // WordPress Administration Widgets API load_template(ABSPATH . 'wp-admin/includes/widgets.php'); // These are the widgets grouped by sidebar /* $sidebars_widgets = wp_get_sidebars_widgets(); if ( empty( $sidebars_widgets ) ) $sidebars_widgets = wp_get_widget_defaults(); */ // Show inactive widgets $user = get_current_user_id(); $screenopt = get_user_meta($user, 'templates_screen_options', true); // Mobile if (wp_is_mobile()) { wp_enqueue_script('jquery-touch-punch'); } // Do sidebar action do_action('sidebar_admin_setup'); // options header bizzthemes_options_header($options_title = __('Template Builder', 'bizzthemes'), $toggle = false); if (isset($messages)) { foreach ($messages as $message) { echo $message . "\n"; } } // register the inactive_widgets area as sidebar register_sidebar(array('name' => __('Inactive Widgets', 'bizzthemes'), 'id' => 'wp_inactive_widgets', 'class' => 'inactive-sidebar', 'description' => __('Drag widgets here to remove them from the sidebar but keep their settings.', 'bizzthemes'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', 'grid' => '')); if (function_exists('retrieve_widgets')) { retrieve_widgets(); } do_action('widgets_admin_page'); ?> <div class="manage-templates manage-menus<?php if (!isset($_REQUEST['tab'])) { echo ' disabled'; } ?> "> <div class="label-templates"><?php _e('Select a template to edit:', 'bizzthemes'); ?> </div> <div class="select-templates"> <a href="#" class="dropdown-toggle menu-select"> <span dir="ltr"><?php echo bizz_tabs_active(); ?> </span> <span class="templates-toggle"></span> </a> <div class="dropdown-menu menu-tabs"> <?php bizz_tabs_list(); ?> </div> </div> <a href="#" class="bizzhelp templates-help" onclick="return template_help_toggle();">?</a> </div> <div id="widget-frame" class="clearfix"> <div class="widget-liquid-left<?php if (!isset($_REQUEST['tab'])) { echo ' liquid-left-disabled'; } ?> "> <div id="widgets-left"> <div id="available-widgets" class="widgets-holder-wrap"> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php _e('Available Widgets', 'bizzthemes'); ?> <span id="removing-widget"><?php _e('Deactivate', 'bizzthemes'); ?> <span></span></span></h3> </div> <div class="widget-holder"> <p class="description"> <?php _e('Drag widgets from here to a template on the right to activate them. Drag widgets back here to deactivate them and delete their settings.', 'bizzthemes'); ?> </p> <div id="widget-list"> <?php wp_list_widgets(); ?> </div> <br class='clear' /> </div> </div> <?php if (isset($screenopt['inactive_widgets'])) { foreach ($wp_registered_sidebars as $sidebar => $registered_sidebar) { if (false !== strpos($registered_sidebar['class'], 'inactive-sidebar') || 'orphaned_widgets' == substr($sidebar, 0, 16)) { $wrap_class = 'widgets-holder-wrap closed'; if (!empty($registered_sidebar['class'])) { $wrap_class .= ' sidebar-' . $registered_sidebar['class']; } ?> <div id="inactive-widgets" class="<?php echo esc_attr($wrap_class); ?> "> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php echo esc_html($registered_sidebar['name']); ?> <span class="spinner"></span> </h3> </div> <div class="widget-holder inactive"> <?php wp_list_widget_controls($sidebar); ?> <br class="clear" /> </div> </div> <?php } } } ?> </div> </div> <div class="widget-liquid-right<?php if (!isset($_REQUEST['tab'])) { echo ' liquid-right-disabled'; } ?> "> <div id="widgets-right"> <div id="post-body-content" class="meta-box-sortables"> <div class="metabox-holder sortme<?php if (!isset($_REQUEST['tab'])) { echo ' sortme-disabled'; } ?> "> <?php // conditions and items (administration tabs) isset($_REQUEST['condition']) ? $bizz_condition = $_REQUEST['condition'] : ($bizz_condition = 'is_index'); isset($_REQUEST['id']) ? $bizz_item = $_REQUEST['id'] : ($bizz_item = 'all'); isset($_REQUEST['tab']) ? $bizz_tab = $_REQUEST['tab'] : ($bizz_tab = 'is_index'); isset($_REQUEST['subtab']) ? $bizz_subtab = $_REQUEST['subtab'] : ($bizz_subtab = 'all'); isset($_REQUEST['subtabsub']) ? $bizz_subtabsub = $_REQUEST['subtabsub'] : ($bizz_subtabsub = 'all'); // define condition logic $condition_logic['bizz_tab'] = $bizz_tab; $condition_logic['bizz_subtab'] = $bizz_subtab; $condition_logic['bizz_subtabsub'] = $bizz_subtabsub; $condition_logic['bizz_condition'] = $bizz_condition; $condition_logic['bizz_item'] = $bizz_item; // bake condition and item echo "\t<input type=\"hidden\" class=\"cond_item\" name=\"empty\" value=\"empty\" />\n"; echo "\t<input type=\"hidden\" class=\"cond_item\" name=\"condition\" value=\"{$bizz_condition}\" />\n"; echo "\t<input type=\"hidden\" class=\"cond_item\" name=\"item\" value=\"{$bizz_item}\" />\n"; echo "\t<input type=\"hidden\" class=\"cond_item\" name=\"empty\" value=\"empty\" />\n"; echo "\t<input type=\"hidden\" class=\"empty_parent\" name=\"empty\" value=\"empty\" />\n"; echo "\t<input type=\"hidden\" class=\"is_parent\" name=\"parent\" value=\"true\" />\n"; echo "\t<input type=\"hidden\" class=\"not_parent\" name=\"parent\" value=\"false\" />\n"; echo "\t<input type=\"hidden\" class=\"cond_item\" name=\"empty\" value=\"empty\" />\n"; echo "\t<input type=\"hidden\" class=\"empty_parent\" name=\"empty\" value=\"empty\" />\n"; echo "\t<input type=\"hidden\" class=\"is_enabled\" name=\"show\" value=\"true\" />\n"; echo "\t<input type=\"hidden\" class=\"not_enabled\" name=\"show\" value=\"false\" />\n"; $widget_logic = bizz_frame_widget_logic($condition_logic); #widget logic // print_r($widget_logic); // print_r('<br/><br/>'); $grid_logic = bizz_frame_grid_logic($condition_logic); #grid logic // print_r($grid_logic); // print_r('<br/><br/>'); $main_area_exists = array_key_exists("main_area", $grid_logic) ? true : false; #main area exists? // loop through registred grids $i = 0; foreach ($grid_logic as $container => $registered_container) { $closed = ' closed'; if ($main_area_exists && $registered_container['id'] == 'main_area' && $registered_container['show'] == 'true') { $next = $i; } elseif ($main_area_exists && $registered_container['id'] == 'main_area' && $registered_container['show'] == 'false') { $next = $i + 1; } elseif (!$main_area_exists) { $next = 0; } // close if (isset($next) && $next == $i) { $closed = ''; } // show if ($registered_container['show'] == 'true') { $box = ' enabled-box'; $taction = __('Disable', 'bizzthemes'); $show = 'true'; # show grid } elseif (!isset($_REQUEST['tab'])) { $box = ' enabled-box'; $taction = __('Disable', 'bizzthemes'); $show = 'true'; # show grid } else { $box = ' disabled-box closed'; $taction = __('Enable', 'bizzthemes'); $show = 'false'; # hide grid } // hide enable/disable for first builder page if (!isset($_REQUEST['tab'])) { $taction = ''; } ?> <div class="postbox container-area<?php echo $box . $closed; ?> "> <div class="sidebar-name-arrow container-arrow" title="<?php _e('Click to toggle', 'bizzthemes'); ?> "><br /></div> <h3 class="container-name"> <span class="label"><?php echo esc_html($registered_container['name']); ?> </span> <span class="current"><?php _e('disabled', 'bizzthemes'); ?> </span> <span class="spinner"></span> <span class="title-action"><a href="#"><?php echo $taction; ?> </a></span> </h3> <div class="widget-holder"> <div class="row-fluid"> <?php bizz_grid_tree($registered_container['grids']); ?> </div><!-- END .row-fluid --> </div><!-- END .widget-holder --> <input type="hidden" class="accepted" name="<?php echo $registered_container['id']; ?> [id]" value="<?php echo $registered_container['id']; ?> " /> <input type="hidden" class="accepted" name="<?php echo $registered_container['id']; ?> [name]" value="<?php echo $registered_container['name']; ?> " /> <input type="hidden" class="accepted" name="<?php echo $registered_container['id']; ?> [show]" value="<?php echo $show; ?> " /> <input type="hidden" class="accepted" name="<?php echo $registered_container['id']; ?> [condition]" value="<?php isset($_REQUEST['condition']) ? esc_attr_e($_REQUEST['condition']) : esc_attr_e('is_index'); ?> " /> <input type="hidden" class="accepted" name="<?php echo $registered_container['id']; ?> [item]" value="<?php isset($_REQUEST['id']) ? esc_attr_e($_REQUEST['id']) : esc_attr_e('all'); ?> " /> </div><!-- END .container-area --> <?php $i++; } ?> </div><!-- /.metabox-holder --> </div><!-- /#post-body-content --> </div> </div> </div> <form action="" method="post"><?php wp_nonce_field('save-sidebar-widgets', '_wpnonce_widgets', false); ?> </form> <div class="clear"><!----></div> <?php if (isset($_REQUEST['tab'])) { ?> <div id="bcollapse-menu" class="hide-if-no-js clearfix"><div id="bcollapse-button"><div></div></div><span><?php esc_html_e('Collapse menu', 'bizzthemes'); ?> </span></div> <?php } ?> <br /> <?php // options footer bizzthemes_options_footer(); do_action('sidebar_admin_page'); }
function get_theme_mods($theme) { // get active theme $active_theme = get_stylesheet(); // create temp array from parent settings $mods = get_option('theme_mods_' . $theme); if ($active_theme == $theme) { $this->debug('from is active, using active widgets', __FUNCTION__, __CLASS__); // if parent theme is active, get widgets from active sidebars_widgets array $mods['sidebars_widgets']['data'] = retrieve_widgets(); } else { $this->debug('from not active, using theme mods widgets', __FUNCTION__, __CLASS__); // otherwise get widgets from parent theme mods $mods['sidebars_widgets']['data'] = empty($mods['sidebars_widgets']['data']) ? array('wp_inactive_widgets' => array()) : $mods['sidebars_widgets']['data']; } return $mods; }