'my-sidebar',
* 'name' => __( 'My Sidebar', 'my-theme-text-domain' ),
* 'description' => __( 'A description of the intended purpose or location', 'my-theme-text-domain' ),
* )
* );
* ~~~
*
* @since 1.1.0
*
* @uses bizznis_markup() Contextual markup.
*
* @param string|array $args Name, ID, description and other widget area arguments.
*
* @return string The sidebar ID that was added.
*/
function bizznis_register_widget_area( $args ) {
$defaults = array(
'before_widget' => '',
'before_title' => '
\n",
);
/**
* A filter on the default parameters used by `bizznis_register_widget_area()`. For backward compatibility.
*
* @since 1.0.1
*/
$defaults = apply_filters( 'bizznis_register_sidebar_defaults', $defaults, $args );
/**
* A filter on the default parameters used by `bizznis_register_widget_area()`.
*
* @since 1.1.0
*/
$defaults = apply_filters( 'bizznis_register_widget_area_defaults', $defaults, $args );
$args = wp_parse_args( $args, $defaults );
return register_sidebar( $args );
}
/**
* An alias for `bizznis_register_widget_area()`.
*
* @since 1.0.0
*
* @uses bizznis_register_widget_area()
*
* @param string|array $args Name, ID, description and other widget area arguments.
*
* @return string The sidebar ID that was added.
*/
function bizznis_register_sidebar( $args ) {
return bizznis_register_widget_area( $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;
}
$defaults = apply_filters( 'bizznis_widget_area_defaults', array(
'before' => '',
'default' => '',
'show_inactive' => 0,
'before_sidebar_hook' => 'bizznis_before_' . $id . '_widget_area',
'after_sidebar_hook' => 'bizznis_after_' . $id . '_widget_area',
), $id, $args );
$args = wp_parse_args( $args, $defaults );
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 );
}
}
/**
* Widget heading filter, default H4 in Widgets and sidebars modified to an H3 if bizznis_a11y( 'headings' ) support
*
* For using a semantic heading structure, improves accessibility
*
* @since 1.2.0
* @param array $args Arguments
* @return array $args
*/
add_filter( 'bizznis_register_sidebar_defaults', 'bizznis_a11y_register_sidebar_defaults' );
function bizznis_a11y_register_sidebar_defaults( $args ) {
if ( bizznis_a11y( 'headings' ) ) {
$args['before_title'] = '\n";
}
return $args;
}
/**
* Adds an H2 title to widget areas.
*
* For using a semantic heading structure, improves accessibility
*
* @since 1.2.0
* @uses bizznis_a11y( 'headings' ) to check for semantic heading support
* @global $wp_registered_sidebars
* @return string $heading Widget area heading or null
*/
function bizznis_sidebar_title( $id ) {
if ( bizznis_a11y( 'headings' ) && $id ) {
global $wp_registered_sidebars;
if ( array_key_exists( $id, $wp_registered_sidebars ) ) {
$name = $wp_registered_sidebars[$id]['name'];
} else {
$name = $id;
}
$heading = '';
return apply_filters( 'bizznis_sidebar_title_output', $heading, $id );
}
}