2019-01-28 23:02:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-11-14 17:16:31 +00:00
|
|
|
* Rest in peace
|
2019-01-28 23:02:25 +00:00
|
|
|
*
|
|
|
|
* @package understrap
|
|
|
|
*/
|
|
|
|
|
2019-06-20 08:57:12 +00:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
2019-01-28 23:02:25 +00:00
|
|
|
|
|
|
|
if ( ! function_exists( 'understrap_slbd_count_widgets' ) ) {
|
2019-07-04 14:53:03 +00:00
|
|
|
/**
|
|
|
|
* Count number of widgets in a sidebar
|
|
|
|
* Used to add classes to widget areas so widgets can be displayed one, two, three or four per row
|
|
|
|
*
|
|
|
|
* @param int $sidebar_id The ID of the sidebar.
|
|
|
|
* @deprecated 0.8.9
|
|
|
|
*/
|
2019-01-28 23:02:25 +00:00
|
|
|
function understrap_slbd_count_widgets( $sidebar_id ) {
|
|
|
|
// If loading from front page, consult $_wp_sidebars_widgets rather than options
|
|
|
|
// to see if wp_convert_widget_settings() has made manipulations in memory.
|
|
|
|
global $_wp_sidebars_widgets;
|
|
|
|
if ( empty( $_wp_sidebars_widgets ) ) :
|
2020-04-19 10:08:39 +00:00
|
|
|
$_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
2019-01-28 23:02:25 +00:00
|
|
|
endif;
|
|
|
|
$sidebars_widgets_count = $_wp_sidebars_widgets;
|
|
|
|
if ( isset( $sidebars_widgets_count[ $sidebar_id ] ) ) :
|
2020-04-19 10:08:39 +00:00
|
|
|
$widget_count = count( $sidebars_widgets_count[ $sidebar_id ] );
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes = 'widget-count-' . count( $sidebars_widgets_count[ $sidebar_id ] );
|
2020-04-19 10:08:39 +00:00
|
|
|
if ( 0 == $widget_count % 4 || $widget_count > 6 ) : // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
|
|
|
// Four widgets per row if there are exactly four or more than six.
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes .= ' col-md-3';
|
2020-04-19 10:08:39 +00:00
|
|
|
elseif ( 6 == $widget_count ) : // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
|
|
|
// If two widgets are published.
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes .= ' col-md-2';
|
|
|
|
elseif ( $widget_count >= 3 ) :
|
2020-04-19 10:08:39 +00:00
|
|
|
// Three widgets per row if there's three or more widgets.
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes .= ' col-md-4';
|
2020-04-19 10:08:39 +00:00
|
|
|
elseif ( 2 == $widget_count ) : // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
|
|
|
// If two widgets are published.
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes .= ' col-md-6';
|
2020-04-19 10:08:39 +00:00
|
|
|
elseif ( 1 == $widget_count ) : // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
|
|
|
// If just on widget is active.
|
2019-01-28 23:02:25 +00:00
|
|
|
$widget_classes .= ' col-md-12';
|
2019-06-20 08:57:12 +00:00
|
|
|
endif;
|
2019-01-28 23:02:25 +00:00
|
|
|
return $widget_classes;
|
|
|
|
endif;
|
|
|
|
}
|
2019-06-20 08:57:12 +00:00
|
|
|
}
|