'my-sidebar',
* 'name' => __( 'My Sidebar', 'my-theme-text-domain' ),
* 'description' => __( 'A description of the intended purpose or location', 'my-theme-text-domain' ),
* )
* );
*
* @since 1.0.0
*/
function bizznis_register_sidebar( $args ) {
$defaults = (array) apply_filters(
'bizznis_register_sidebar_defaults',
array(
'before_widget' => '',
'before_title' => '
\n",
),
$args
);
$args = wp_parse_args( $args, $defaults );
return register_sidebar( $args );
}
/**
* Alters the widget area params array for HTML5 compatibility.
*
* @since 1.0.0
*/
add_action( 'after_setup_theme', '_bizznis_builtin_sidebar_params' );
function _bizznis_builtin_sidebar_params() {
global $wp_registered_sidebars;
foreach ( $wp_registered_sidebars as $id => $params ) {
if ( ! isset( $params['_bizznis_builtin'] ) ) {
continue;
}
$wp_registered_sidebars[ $id ]['before_widget'] = '';
}
}
/**
* Conditionally display a sidebar, wrapped in a div by default.
*
* @since 1.0.0
*/
function bizznis_widget_area( $id, $args = array() ) {
if ( ! $id ) {
return false;
}
$args = wp_parse_args(
$args,
array(
'before' => '',
'default' => '',
'show_inactive' => 0,
'before_sidebar_hook' => 'bizznis_before_' . $id . '_widget_area',
'after_sidebar_hook' => 'bizznis_after_' . $id . '_widget_area',
)
);
if ( ! is_active_sidebar( $id ) && ! $args['show_inactive'] ) {
return false;
}
# Opening markup
echo $args['before'];
# Before hook
if ( $args['before_sidebar_hook'] ) {
do_action( $args['before_sidebar_hook'] );
}
if ( ! dynamic_sidebar( $id ) ) {
echo $args['default'];
}
# After hook
if( $args['after_sidebar_hook'] ) {
do_action( $args['after_sidebar_hook'] );
}
# Closing markup
echo $args['after'];
return true;
}
/**
* Temporary function to work around the default widgets that get added to
* Header Right when switching themes.
*
* The $defaults array contains a list of the IDs of the widgets that are added
* to the first sidebar in a new default install. If this exactly matches the
* widgets in Header Right after switching themes, then they are removed.
*
* This works around a perceived WP problem for new installs.
*
* If a user amends the list of widgets in the first sidebar before switching to
* a Bizznis child theme, then this function won't do anything.
*
* @since 1.0.0
*/
add_action( 'load-themes.php', 'bizznis_remove_default_widgets_added_by_wp' );
function bizznis_remove_default_widgets_added_by_wp() {
# Some tomfoolery for a faux activation hook
if ( ! isset( $_REQUEST['activated'] ) || 'true' !== $_REQUEST['activated'] ) {
return;
}
$widgets = get_option( 'sidebars_widgets' );
$defaults = array( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', );
if ( isset( $widgets['header-aside'] ) && $defaults === $widgets['header-aside'] ) {
$widgets['header-aside'] = array();
update_option( 'sidebars_widgets', $widgets );
}
}