/** * Additional Widgets Classes * * @param $params * * @return mixed */ function croft_widget_classes($params) { /* Global a counter array */ global $croft_widget_num; /* Get the id for the current sidebar we're processing */ $this_id = $params[0]['id']; /* Get registered widgets */ $arr_registered_widgets = wp_get_sidebars_widgets(); /* If the counter array doesn't exist, create it */ if (!$croft_widget_num) { $croft_widget_num = array(); } /* if current sidebar has no widget, return. */ if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { return $params; } /* See if the counter array has an entry for this sidebar */ if (isset($croft_widget_num[$this_id])) { $croft_widget_num[$this_id]++; } else { $croft_widget_num[$this_id] = 1; } /* Add a widget number class for additional styling options */ $class = 'class="widget widget-' . $croft_widget_num[$this_id] . ' '; /* in first widget, add 'widget-first' class */ if ($croft_widget_num[$this_id] == 1) { $class .= 'widget-first '; } elseif ($croft_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { $class .= 'widget-last '; } /* str replace before_widget param with new class */ $params[0]['before_widget'] = str_replace('class="widget ', $class, $params[0]['before_widget']); return $params; }
/** * Add additional classes onto widgets * * @link http://wordpress.org/support/topic/how-to-first-and-last-css-classes-for-sidebar-widgets */ function kadence_widget_first_last_classes($params) { global $my_widget_num; $this_id = $params[0]['id']; $arr_registered_widgets = wp_get_sidebars_widgets(); if (!$my_widget_num) { $my_widget_num = array(); } if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { return $params; } if (isset($my_widget_num[$this_id])) { $my_widget_num[$this_id]++; } else { $my_widget_num[$this_id] = 1; } $class = 'class="widget-' . $my_widget_num[$this_id] . ' '; if ($my_widget_num[$this_id] == 1) { $class .= 'widget-first '; } elseif ($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { $class .= 'widget-last '; } $params[0]['before_widget'] = preg_replace('/class=\\"/', "{$class}", $params[0]['before_widget'], 1); return $params; }
/** * Register meta boxes * @return void */ function mango_register_meta_boxes($meta_boxes) { /** * prefix of meta keys (optional) * Use underscore (_) at the beginning to make keys hidden * Alt.: You also can make prefix empty to disable it */ // Better has an underscore as last sign $prefix = 'mango_'; $mango_sidebar_nosidebar = array(); $mango_sidebar = array(); $mango_sidebar_nosidebar[''] = "No Sidebar"; global $post; $post_id = isset($_GET['post']) && $_GET['post'] ? $_GET['post'] : ''; $post_id = isset($_REQUEST['post']) && $_REQUEST['post'] ? $_REQUEST['post'] : ''; //if(isset($_GET['post'])||isset($_POST['post_ID'])): // $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; //endif; $template_file = get_post_meta($post_id, '_wp_page_template', TRUE); $categories = get_terms('portfolio-category', 'orderby=count&hide_empty=0'); $mango_portfolio_categories['all'] = __('All Categories', 'mango'); if ($categories && !is_wp_error($categories)) { foreach ($categories as $category) { $mango_portfolio_categories[$category->name] = $category->name; } } foreach ($mango_portfolio_categories as $key => $value) { if ($key == 'uncategorized') { continue; } $mango_portfolio_default[] = $key; } $wp_registered_sidebars = wp_get_sidebars_widgets(); foreach ($wp_registered_sidebars as $sidebar => $sidebar_info) { if ($sidebar == 'wp_inactive_widgets') { continue; } $mango_sidebar[$sidebar] = ucwords(str_replace(array('_', '-'), ' ', $sidebar)); $mango_sidebar_nosidebar[$sidebar] = ucwords(str_replace(array('_', '-'), ' ', $sidebar)); } // Page require_once mango_functions . '/metaboxes/meta-page.php'; // Portfolio require_once mango_functions . '/metaboxes/meta-portfolio.php'; // Post require_once mango_functions . '/metaboxes/meta-post.php'; // Client require_once mango_functions . '/metaboxes/meta-clients.php'; // testimonials require_once mango_functions . '/metaboxes/meta-testimonial.php'; // Faqs require_once mango_functions . '/metaboxes/meta-faqs.php'; // Product require_once mango_functions . '/metaboxes/meta-product.php'; //general require_once mango_functions . '/metaboxes/meta-general.php'; //meta popup require_once mango_functions . '/metaboxes/meta-popup.php'; return $meta_boxes; }
/** * HTML for export admin page */ public static function export_settings_page() { $sidebar_widgets = self::order_sidebar_widgets( wp_get_sidebars_widgets() ); ?> <div class="widget-data export-widget-settings"> <div class="wrap"> <h2>Widget Setting Export</h2> <div id="notifier" style="display: none;"></div> <form action="" method="post" id="widget-export-settings"> <input type="hidden" id="action" name="action" value="export_widget_settings" /> <?php wp_nonce_field('export_widget_settings', '_wpnonce'); ?> <p> <a class="button select-all">Select All Active Widgets</a> <a class="button unselect-all">Un-Select All Active Widgets</a> </p> <div class="title"> <h3>Sidebars</h3> <div class="clear"></div> </div> <div class="sidebars"> <?php foreach ( $sidebar_widgets as $sidebar_name => $widget_list ) : if ( empty( $widget_list ) ) continue; $sidebar_info = self::get_sidebar_info( $sidebar_name ); if( !empty($sidebar_info) ): ?> <div class="sidebar"> <h4><?php echo $sidebar_info['name']; ?></h4> <div class="widgets"> <?php foreach ( $widget_list as $widget ) : $widget_type = trim( substr( $widget, 0, strrpos( $widget, '-' ) ) ); $widget_type_index = trim( substr( $widget, strrpos( $widget, '-' ) + 1 ) ); $widget_options = get_option( 'widget_' . $widget_type ); $widget_title = isset( $widget_options[$widget_type_index]['title'] ) ? $widget_options[$widget_type_index]['title'] : $widget_type_index; ?> <div class="import-form-row"> <input class="<?php echo ($sidebar_name == 'wp_inactive_widgets') ? 'inactive' : 'active'; ?> widget-checkbox" type="checkbox" name="<?php echo esc_attr( $widget ); ?>" id="<?php echo esc_attr( 'meta_' . $widget ); ?>" /> <label for="<?php echo esc_attr( 'meta_' . $widget ); ?>"> <?php echo ucfirst( $widget_type ); if( !empty( $widget_title ) ) echo ' - ' . $widget_title; ?> </label> </div> <?php endforeach; ?> </div> <!-- end widgets --> </div> <!-- end sidebar --> <?php endif; endforeach; ?> </div> <!-- end sidebars --> <input class="button-bottom button-primary" type="submit" value="Export Widget Settings"/> </form> </div> <!-- end wrap --> </div> <!-- end export-widget-settings --> <?php }
/** * @param $sidebar_id string * @return int */ public function count_widgets($sidebar_id) { if (!isset($sidebar_id)) { return 0; } return count(wp_get_sidebars_widgets($sidebar_id)); }
/** * Display the footer widget if the footer widget are active. */ function calibrefx_do_footer_widgets() { global $wp_registered_sidebars; $footer_widgets = get_theme_support('calibrefx-footer-widgets'); $all_widgets = wp_get_sidebars_widgets(); //Check if footer widget theme support is activated or is there any widget inside if (!$footer_widgets or !isset($all_widgets['footer-widget'])) { return; } $count_footer_widgets = count($all_widgets['footer-widget']); if (0 == $count_footer_widgets) { return; } if (current_theme_supports('calibrefx-responsive-style')) { $span = 'col-lg-' . strval(floor(12 / $count_footer_widgets)) . ' col-md-' . strval(floor(12 / $count_footer_widgets)) . ' col-sm-12 col-xs-12'; } else { $span = 'col-xs-' . strval(floor(12 / $count_footer_widgets)); } $sidebar = $wp_registered_sidebars['footer-widget']; $footer_widget_column = apply_filters('calibrefx_footer_widget_column_span', $span); $sidebar['before_widget'] = '<div id="%1$s" class="widget ' . $footer_widget_column . ' %2$s">'; $sidebar['after_widget'] = '</div>'; unregister_sidebar('footer-widget'); register_sidebar($sidebar); if (is_active_sidebar('footer-widget')) { echo '<div id="footer-widget">'; calibrefx_put_wrapper('footer-widget', 'open'); $footer_widget_wrapper_class = apply_filters('footer_widget_wrapper_class', calibrefx_row_class()); echo '<div class="footer-widget-wrapper"><div class="' . $footer_widget_wrapper_class . '">'; dynamic_sidebar('footer-widget'); echo '</div></div><!--end .footer-widget-wrapper -->'; calibrefx_put_wrapper('footer-widget', 'close'); echo '</div><!--end #footer-widget-->'; } }
function setUp() { parent::setUp(); require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); add_theme_support( 'customize-selective-refresh-widgets' ); $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( $user_id ); $GLOBALS['wp_customize'] = new WP_Customize_Manager(); $this->manager = $GLOBALS['wp_customize']; unset( $GLOBALS['_wp_sidebars_widgets'] ); // clear out cache set by wp_get_sidebars_widgets() $sidebars_widgets = wp_get_sidebars_widgets(); $this->assertEqualSets( array( 'wp_inactive_widgets', 'sidebar-1' ), array_keys( wp_get_sidebars_widgets() ) ); $this->assertContains( 'search-2', $sidebars_widgets['sidebar-1'] ); $this->assertContains( 'categories-2', $sidebars_widgets['sidebar-1'] ); $this->assertArrayHasKey( 2, get_option( 'widget_search' ) ); $widget_categories = get_option( 'widget_categories' ); $this->assertArrayHasKey( 2, $widget_categories ); $this->assertEquals( '', $widget_categories[2]['title'] ); // @todo We should not be including a theme anyway remove_action( 'after_setup_theme', 'twentyfifteen_setup' ); remove_action( 'after_setup_theme', 'twentysixteen_setup' ); remove_action( 'customize_register', 'twentysixteen_customize_register', 11 ); $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars']; // Reset protected static var on class. WP_Customize_Setting::reset_aggregated_multidimensionals(); }
function category_posts_should_enqueue($id_base, $class) { global $wp_registered_widgets; $ret = false; $sidebars_widgets = wp_get_sidebars_widgets(); if (is_array($sidebars_widgets)) { foreach ($sidebars_widgets as $sidebar => $widgets) { if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) { continue; } if (is_array($widgets)) { foreach ($widgets as $widget) { $widget_base = _get_widget_id_base($widget); if ($widget_base == $id_base) { $widgetclass = new $class(); $allsettings = $widgetclass->get_settings(); $settings = $allsettings[str_replace($widget_base . '-', '', $widget)]; if (!isset($settings['disable_css'])) { // checks if css disable is not set $ret = true; } } } } } } return $ret; }
function vanilla_widget_template_markup($block = null) { global $wp_registered_sidebars, $wp_registered_widgets; $tpl_source = ""; $block = sanitize_title($block); foreach ((array) $wp_registered_sidebars as $key => $value) { if (sanitize_title($value['name']) == $block) { $block = $key; break; } } $sidebars_widgets = wp_get_sidebars_widgets(); if (empty($wp_registered_sidebars[$block]) || !array_key_exists($block, $sidebars_widgets) || !is_array($sidebars_widgets[$block]) || empty($sidebars_widgets[$block])) { return ""; } $sidebar = $wp_registered_sidebars[$block]; foreach ((array) $sidebars_widgets[$block] as $id) { $params = array_merge(array(array_merge($sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']))), (array) $wp_registered_widgets[$id]['params']); $params = apply_filters('dynamic_sidebar_params', $params); $callback = $wp_registered_widgets[$id]['callback']; $widget_name = str_replace("widget_", "", strtolower($callback)); $active_template = vanilla_get_template('widgets/' . str_replace("_", "-", $widget_name) . ".html"); if (!$active_template) { return ""; } //echo $widget_name . " " . $widget_filename; if (is_callable($callback)) { call_user_func_array($callback, $params); $tpl_source .= '<span metal:use-macro="' . $active_template . '/loader" />' . "\n" . '<span tal:condition="php:VANILLA_DEBUG" class="widget-debug">WIDGET: ' . $widget_name . '</span>' . "\n" . '<span metal:define-slot="' . $widget_name . '" />' . "\n"; } } return $tpl_source; }
function theme_FirstLastClasses($params) { global $my_widget_num; $this_id = $params[0]['id']; $arr_registered_widgets = wp_get_sidebars_widgets(); if (!$my_widget_num) { $my_widget_num = array(); } if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { return $params; } if (isset($my_widget_num[$this_id])) { $my_widget_num[$this_id]++; } else { $my_widget_num[$this_id] = 1; } $class = 'class="widget-' . $my_widget_num[$this_id] . ' '; if ($my_widget_num[$this_id] == 1) { $class .= 'widget-first '; } elseif ($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { $class .= 'widget-last '; } $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); return $params; }
function iterator($id_base, $class, $callback) { global $wp_registered_widgets; $sidebars_widgets = wp_get_sidebars_widgets(); if (is_array($sidebars_widgets)) { foreach ($sidebars_widgets as $sidebar => $widgets) { if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) { continue; } if (is_array($widgets)) { foreach ($widgets as $widget) { $widget_base = _get_widget_id_base($widget); if ($widget_base == $id_base) { $widgetclass = new $class(); $allsettings = $widgetclass->get_settings(); $settings = isset($allsettings[str_replace($widget_base . '-', '', $widget)]) ? $allsettings[str_replace($widget_base . '-', '', $widget)] : false; if (!$callback($settings)) { return; } } } } } } }
function widget($args) { global $wp_registered_widgets; extract($args); echo $before_widget; $widget_ids = wp_get_sidebars_widgets(); if (!empty($widget_ids['tabs-widget-area'])) { echo '<div class="tabs-section">'; $output = '<ul class="tabs-list">'; $i = 0; foreach ($widget_ids['tabs-widget-area'] as $widget) { $widget_object = $wp_registered_widgets[$widget]['callback'][0]; $widget_id = $wp_registered_widgets[$widget]['params'][0]['number']; $widget_data = get_option($widget_object->option_name); foreach ($widget_data as $id => $widget) { if ($id == $widget_id) { $i++; if ($i == 1) { $output .= '<li class="tabs-current">' . __($widget['title'], 'unspoken') . '</li>'; } else { $output .= '<li>' . __($widget['title'], 'unspoken') . '</li>'; } } } } echo $output .= '</ul>'; if (!dynamic_sidebar('tabs-widget-area')) { } echo '</div>'; } echo $after_widget; }
function __comicpress_widgets_init() { $available_widgets = array(); if (($dh = opendir(dirname(__FILE__) . '/widgets')) !== false) { while (($file = readdir($dh)) !== false) { if (strpos($file, '.inc') !== false) { $class_name = "ComicPress" . preg_replace('#\\..*$#', '', $file); require_once dirname(__FILE__) . '/widgets/' . $file; register_widget($class_name); $widget = new $class_name(true); if (method_exists($widget, 'init')) { $widget->init(); } $available_widgets[strtolower($class_name)] = $widget; } } closedir($dh); } foreach (wp_get_sidebars_widgets() as $type => $widgets) { if ($type != 'wp_inactive_widgets') { foreach ($widgets as $widget_id) { foreach ($available_widgets as $key => $widget) { if (method_exists($widget, 'is_active')) { if (strpos(strtolower($widget_id), $key) === 0) { $widget->is_active(); } } } } } } }
/** * Update subscribe widget instances to follow widget instances * * @since 1.1.9 */ public static function update_widgets() { $sidebars = wp_get_sidebars_widgets(); if (!is_array($sidebars)) { return; } $found_widgets = false; foreach ($sidebars as $sidebar => $widgets) { foreach ($widgets as $position => $widget_id) { if (strlen($widget_id) > 18 && substr_compare($widget_id, 'facebook-subscribe', 0, 18) === 0) { $sidebars[$sidebar][$position] = 'facebook-follow' . substr($widget_id, strrpos($widget_id, '-')); $found_widgets = true; } } } if ($found_widgets) { $existing_instances = get_option('widget_facebook-subscribe'); if (is_array($existing_instances)) { update_option('widget_facebook-follow', $existing_instances); } if ($existing_instances !== false) { delete_option('widget_facebook-subscribe'); } unset($existing_instances); wp_set_sidebars_widgets($sidebars); } }
function count_sidebar_widgets($sidebar_id, $echo = true) { $the_sidebars = wp_get_sidebars_widgets(); if (!isset($the_sidebars[$sidebar_id])) { return 0; } return count($the_sidebars[$sidebar_id]); }
/** * WP_REST_Widgets_Controller constructor. * * @param WP_Widget[] $widgets Widget objects. */ public function __construct($widgets) { $this->namespace = 'wp/v2'; $this->rest_base = 'widgets'; $this->widgets = $widgets; $this->sidebars = wp_get_sidebars_widgets(); // @todo Now given $this->widgets, inject schema information for Core widgets in lieu of them being in core now. See #35574. }
/** * * HighThemes Options Framework * twitter : http://twitter.com/theHighthemes * */ function ht_sidebars_page() { global $sidehook, $sidebar_options, $wpdb; if (isset($_POST['Submit'])) { // getting the list of custom sidebars $get_sidebar_options = ht_sidebar_generator::get_sidebars(); $sidebar_name = str_replace(array("\n", "\r", "\t"), '', $_POST['ht_sidebar_name']); $sidebar_id = sanitize_title($sidebar_name); if ($sidebar_id == '') { $options_sidebar = $get_sidebar_options; } else { if (isset($get_sidebar_options[$sidebar_id])) { header("Location: admin.php?page=sidebars&error=true{$hidden_anchor}"); die; } if (is_array($get_sidebar_options)) { $new_sidebar_gen[$sidebar_id] = $sidebar_name; $options_sidebar = array_merge($get_sidebar_options, (array) $new_sidebar_gen); } else { $options_sidebar[$sidebar_id] = $sidebar_name; } } update_option('ht_sidebar_generator', $options_sidebar); header("Location: admin.php?page=sidebars{$send}&saved=true{$hidden_anchor}"); die; } if (isset($_GET['sn'])) { $sidebar_id = $_GET['sn']; $get_sidebar_options = ht_sidebar_generator::get_sidebars(); if (array_key_exists($sidebar_id, $get_sidebar_options)) { unset($get_sidebar_options[$sidebar_id]); update_option('ht_sidebar_generator', $get_sidebar_options); // $get_widgets = wp_get_sidebars_widgets(); unset($get_widgets['array_version']); foreach ($get_widgets as $key => $value) { if ($key == 'ht_' . $sidebar_id) { unset($get_widgets['ht_' . $sidebar_id]); } } wp_set_sidebars_widgets($get_widgets); $sidebar_meta = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '{$sidebar_id}'", ARRAY_A); if ($sidebar_meta) { if (is_array($sidebar_meta)) { foreach ($sidebar_meta as $key => $value) { delete_post_meta($value['post_id'], '_selected_sidebar'); } } } else { header("Location: admin.php?page=sidebars"); } } } wp_enqueue_script('common'); wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); add_meta_box('ht_add_sidebars', 'Add New Sidebars', 'ht_add_sidebars', $sidehook, 'normal', 'high'); }
/** * widget_area_active() Checks to see if a widget area is active based on ID * * @since 0.4 */ function widget_area_active($index) { global $wp_registered_sidebars; $widgetarea = wp_get_sidebars_widgets(); if (isset($widgetarea[$index])) { return true; } return false; }
/** * Check for static widgets in widget-ready areas */ function is_sidebar_active($index) { global $wp_registered_sidebars; $widgetcolums = wp_get_sidebars_widgets(); if ($widgetcolums[$index]) { return true; } return false; }
function testHTML() { // replace this with some actual testing code $widgets = wp_get_sidebars_widgets(); $data = array(); $content = Timber::get_widgets('sidebar-1'); $content = trim($content); $this->assertEquals('<', substr($content, 0, 1)); }
function _esc_dynamic_sidebar_params($params) { /*if ( is_admin() ) return ;*/ global $wp_registered_widgets, $widget_number; $arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets $this_id = $params[0]['id']; // Get the id for the current sidebar we're processing $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[$widget_id]; $widget_num = $widget_obj['params'][0]['number']; $widget_opt = null; // Default callback if (isset($widget_obj['callback'][0]->option_name)) { $widget_opt = get_option($widget_obj['callback'][0]->option_name); } // Add classes if (isset($widget_opt[$widget_num]['classes']) && !empty($widget_opt[$widget_num]['classes'])) { // Add all classes $params[0]['before_widget'] = preg_replace('/class="/', "class=\"{$widget_opt[$widget_num]['classes']} ", $params[0]['before_widget'], 1); } // Add id if (isset($widget_opt[$widget_num]['ids']) && !empty($widget_opt[$widget_num]['ids'])) { $params[0]['before_widget'] = preg_replace('/id="[^"]*/', "id=\"{$widget_opt[$widget_num]['ids']}", $params[0]['before_widget'], 1); } // Add first, last, even, and odd classes if (!$widget_number) { $widget_number = array(); } if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { return $params; } if (isset($widget_number[$this_id])) { $widget_number[$this_id]++; } else { $widget_number[$this_id] = 1; } $class = 'class="'; /*show_id*/ $class .= esc_attr__('widget-', 'esc') . $widget_number[$this_id] . ' '; /*show_location*/ $widget_first = apply_filters('widget_css_classes_first', esc_attr__('widget-first', 'widget-css-classes')); $widget_last = apply_filters('widget_css_classes_last', esc_attr__('widget-last', 'widget-css-classes')); if ($widget_number[$this_id] == 1) { $class .= $widget_first . ' '; } if ($widget_number[$this_id] == count($arr_registered_widgets[$this_id])) { $class .= $widget_last . ' '; } /*show_evenodd*/ $widget_even = apply_filters('widget_css_classes_even', esc_attr__('widget-even', 'widget-css-classes')); $widget_odd = apply_filters('widget_css_classes_odd', esc_attr__('widget-odd', 'widget-css-classes')); $class .= $widget_number[$this_id] % 2 ? $widget_odd . ' ' : $widget_even . ' '; $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); return $params; }
function hsinsider_count_sidebar_widgets($sidebar_id) { $the_sidebars = wp_get_sidebars_widgets(); if (!isset($the_sidebars[$sidebar_id])) { return __('Invalid sidebar ID'); } else { return count($the_sidebars[$sidebar_id]); } }
function my_sub_menu_footer_function() { $the_sidebars = wp_get_sidebars_widgets(); echo "<pre>"; print_r($the_sidebars); echo "</pre>"; the_widget('calendar-2'); include_once "pages/footer-option.php"; }
function lsx_sidebar_footer_params($params) { $sidebar_id = $params[0]['id']; if ($sidebar_id == 'sidebar-footer') { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $params[0]['before_widget'] = str_replace('class="styler', 'class="col-sm-' . floor(12 / $sidebar_widgets), $params[0]['before_widget']); } return $params; }
/** * @todo Add Function documentation */ function zclean_sidebar_params($params) { $sidebar_id = $params[0]['id']; if ($sidebar_id == 'footer-top') { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $params[0]['before_widget'] = str_replace('class="', 'class="col-xs-12 col-sm-6 col-md-' . floor(12 / $sidebar_widgets) . ' ', $params[0]['before_widget']); } return $params; }
public static function displayPosition($key, array $params = []) { $key = sanitize_title($key); // Do nothing if sidebar is not active. if (!is_active_sidebar($key)) { return null; } // Set chrome for the filter we add. static::$chromeArgs = static::getChromeArgs(isset($params['chrome']) ? $params['chrome'] : null); // Add sidebar params filter to give more options. \add_filter('dynamic_sidebar_params', ['Gantry\\Wordpress\\Widgets', 'sidebarChromeFilter'], -1000); if (!empty($params['prepare_layout'])) { // Only pre-render Gantry widgets on prepare layout. global $wp_registered_sidebars, $wp_registered_widgets; $sidebar = $wp_registered_sidebars[$key]; $sidebars_widgets = wp_get_sidebars_widgets(); $widgets = !empty($sidebars_widgets[$key]) ? $sidebars_widgets[$key] : []; foreach ($widgets as $id) { // TODO: This should display an error if (empty($wp_registered_widgets[$id])) { continue; } // Make sure we have Gantry 5 compatible widget. if (empty($wp_registered_widgets[$id]['gantry5']) && $wp_registered_widgets[$id]['classname'] !== 'roksprocket_options' && $wp_registered_widgets[$id]['classname'] !== 'rokgallery_options') { continue; } $callback = $wp_registered_widgets[$id]['callback']; // Pre-render Gantry widget. if (is_callable($callback)) { $name = $wp_registered_widgets[$id]['name']; $args = array_merge([array_merge($sidebar, array('widget_id' => $id, 'widget_name' => $name))], (array) $wp_registered_widgets[$id]['params']); // Apply sidebar filter for rokbox and other plugins. $args = apply_filters('dynamic_sidebar_params', $args); // Grab the content of the plugin. ob_start(); call_user_func_array($callback, $args); $contents = ob_get_clean(); // As we already rendered content, we can later just display it. $wp_registered_widgets[$id]['callback'] = function () use($contents) { echo $contents; }; } } $html = '@@DEFERRED@@'; } else { // Display whole sidebar. ob_start(); \dynamic_sidebar($key); $html = ob_get_clean(); } // Remove sidebar params filter. \remove_filter('dynamic_sidebar_params', ['Gantry\\Wordpress\\Widgets', 'sidebarChromeFilter'], -1000); return $html; }
/** * Dynamically add column classes to footer widgets */ function flatbook_footer_widget_params($params) { $sidebar_id = $params[0]['id']; if ($sidebar_id == 'footer-widgets') { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $params[0]['before_widget'] = '<div class="col-sm-' . floor(12 / $sidebar_widgets) . '">' . $params[0]['before_widget']; $params[0]['after_widget'] = $params[0]['after_widget'] . '</div>'; } return $params; }
/** * Add widget count classes so they can be targeted based on their position. * * Adds a class to widgets containing it's position in the sidebar it belongs * to and adds a special class to the last widget. * * @since 1.0.0 * @deprecated 1.5.0 * * @param array $params Wiget registration args. * @return array */ function audiotheme_widget_count_class($params) { $class = ''; $sidebar_widgets = wp_get_sidebars_widgets(); $order = array_search($params[0]['widget_id'], $sidebar_widgets[$params[0]['id']]) + 1; if ($order === count($sidebar_widgets[$params[0]['id']])) { $class = ' widget-last'; } $params[0]['before_widget'] = preg_replace('/class="(.*?)"/i', 'class="$1 widget-' . $order . $class . '"', $params[0]['before_widget']); return $params; }
function cosmos_bottom_sidebar_class($params) { $sidebar_id = $params[0]['id']; if ($sidebar_id == 'sidebar-bottom') { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $class = 'class="span' . floor(12 / $sidebar_widgets) . ' '; $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); } return $params; }
function delicious_count_sidebar_widgets($sidebar_id, $echo = true) { $the_sidebars = wp_get_sidebars_widgets(); if (!isset($the_sidebars[$sidebar_id])) { return __('Invalid sidebar ID', 'delicious'); } if ($echo) { echo count($the_sidebars[$sidebar_id]); } else { return count($the_sidebars[$sidebar_id]); } }