widgets_enabled() ) :
* echo '
';
* $fm->render_widgets(); // echoes each active column
* echo '
';
* endif;
* ------------------------------------------------------------------
*
* @package BongotoWooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Bongoto_WooCommerce_Footer_Manager' ) ) :
class Bongoto_WooCommerce_Footer_Manager {
const MAX_COLUMNS = 6;
const MIN_COLUMNS = 1;
/** @var self|null */
private static $instance = null;
/**
* Singleton accessor.
*
* @return self
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action( 'widgets_init', array( $this, 'register_sidebars' ) );
}
/**
* Register footer sidebars once (1..MAX_COLUMNS).
* We always register all; visibility is controlled at render time.
*/
public function register_sidebars() {
for ( $i = 1; $i <= self::MAX_COLUMNS; $i++ ) {
register_sidebar(
array(
/* translators: %d: column number */
'name' => sprintf( __( 'Footer Column %d', 'bongoto-woocommerce' ), $i ),
'id' => 'footer-' . $i,
'description' => __( 'Add widgets here to appear in the footer.', 'bongoto-woocommerce' ),
'before_widget' => '',
'before_title' => '',
)
);
}
}
/**
* Are footer widgets enabled?
*
* @return bool
*/
public function widgets_enabled() {
return (bool) get_theme_mod( 'bongoto_woocommerce_footer_widgets_enabled', true );
}
/**
* Are we showing the subscribe bar?
*
* @return bool
*/
public function subscribe_enabled() {
return (bool) get_theme_mod( 'bongoto_woocommerce_footer_show_subscribe', true );
}
/**
* How many columns should be shown (clamped 1..MAX_COLUMNS)?
*
* @return int
*/
public function columns() {
$cols = absint( get_theme_mod( 'bongoto_woocommerce_footer_columns', 4 ) );
$cols = max( self::MIN_COLUMNS, min( self::MAX_COLUMNS, $cols ) );
return $cols;
}
/**
* CSS class for grid wrapper (simple responsive layout).
* You can replace with utility classes from your CSS framework if desired.
*
* @return string
*/
public function grid_class() {
$cols = $this->columns();
// A minimal CSS grid; theme CSS should style .bt-footer-grid accordingly.
// Example style (in assets/css/main.css):
// .bt-footer-grid { display:grid; gap:1rem; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); }
// You can further specialize based on $cols if needed.
return 'bt-footer-grid cols-' . $cols;
}
/**
* Render N columns worth of widget areas.
* Shows placeholders in Customizer preview when a column is empty.
*/
public function render_widgets() {
$cols = $this->columns();
// Collect only active widget areas.
$active_sidebars = array();
for ( $i = 1; $i <= $cols; $i++ ) {
if ( is_active_sidebar( 'footer-' . $i ) || is_customize_preview() ) {
$active_sidebars[] = $i;
}
}
// If none active, bail out (for cleaner layout).
if ( empty( $active_sidebars ) ) {
if ( is_customize_preview() ) {
echo '' . esc_html__( 'Add footer widgets in the Widgets panel.', 'bongoto-woocommerce' ) . '
';
}
return;
}
// Render only active ones.
foreach ( $active_sidebars as $i ) {
echo '';
}
}
}
/**
* Convenience function.
*
* @return Bongoto_WooCommerce_Footer_Manager
*/
function bongoto_woocommerce_footer_manager() {
return Bongoto_WooCommerce_Footer_Manager::instance();
}
endif;