/wordpress/wp-content/theme/hybrid/library/functions/widgets.php
PHP | 228 lines | 79 code | 25 blank | 124 comment | 7 complexity | 07ba8133c8740cd7428965817549d6ce MD5 | raw file
Possible License(s): GPL-2.0
- <?php
- /**
- * Functions for dealing with widgets and widget areas within the theme. WP widgets must be
- * unregistered. Hybrid widgets must be registered in their place. All widget areas are loaded
- * and registered with WP.
- *
- * @package Hybrid
- * @subpackage Functions
- */
-
- /**
- * Register widget areas
- * @since 0.7
- */
- add_action( 'init', 'hybrid_register_sidebars' );
-
- /**
- * Unregister WP widgets
- * @since 0.3.2
- */
- add_action( 'widgets_init', 'hybrid_unregister_widgets' );
-
- /**
- * Register Hybrid Widgets
- * @since 0.6
- */
- add_action( 'widgets_init', 'hybrid_register_widgets' );
-
- /**
- * Disables widget areas
- * @since 0.5
- */
- add_filter( 'sidebars_widgets', 'remove_sidebars' );
-
- /**
- * Registers each widget area for the theme. This includes all of the asides
- * and the utility widget areas throughout the theme.
- *
- * We're retaining the 'sidebar' terminology until such time that the
- * WordPress community decides on a better term.
- *
- * @since 0.7
- * @uses register_sidebar() Registers a widget area.
- */
- function hybrid_register_sidebars() {
- $domain = hybrid_get_textdomain();
-
- /* Register aside widget areas. */
- register_sidebar( array( 'name' => __( 'Primary', $domain ), 'id' => 'primary', 'description' => __( 'The main (primary) widget area, most often used as a sidebar.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- register_sidebar( array( 'name' => __( 'Secondary', $domain ), 'id' => 'secondary', 'description' => __( 'The second most important widget area, most often used as a secondary sidebar', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- register_sidebar( array( 'name' => __( 'Subsidiary', $domain ), 'id' => 'subsidiary', 'description' => __( 'A widget area loaded in the footer of the site.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
-
- /* Register utility widget areas. */
- register_sidebar( array( 'name' => __( 'Utility: Before Content', $domain ), 'id' => 'utility-before-content', 'description' => __( 'Loaded before the page\'s main content area.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- register_sidebar( array( 'name' => __( 'Utility: After Content', $domain ), 'id' => 'utility-after-content', 'description' => __( 'Loaded after the page\'s main content area.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- register_sidebar( array( 'name' => __( 'Utility: After Singular', $domain ), 'id' => 'utility-after-singular', 'description' => __( 'Loaded on singular post (page, attachment, etc.) views before the comments area.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
-
- /* Register template widget areas. */
- register_sidebar( array( 'name' => __( 'Widgets Template', $domain ), 'id' => 'utility-widgets-template', 'description' => __( 'Used as the content of the Widgets page template.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- register_sidebar( array( 'name' => __( '404 Template', $domain ), 'id' => 'utility-404', 'description' => __( 'Replaces the default 404 error page content.', $domain ), 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
- }
-
- /**
- * Register Hybrid's extra widgets. Each widget is meant to replace or extend the
- * current default WordPress widgets.
- *
- * @since 0.6
- * @uses register_widget() Registers individual widgets.
- * @link http://codex.wordpress.org/WordPress_Widgets_Api
- */
- function hybrid_register_widgets() {
-
- /* Load each widget file. */
- require_once( THEME_CLASSES . '/widget-archives.php' );
- require_once( THEME_CLASSES . '/widget-authors.php' );
- require_once( THEME_CLASSES . '/widget-bookmarks.php' );
- require_once( THEME_CLASSES . '/widget-calendar.php' );
- require_once( THEME_CLASSES . '/widget-categories.php' );
- require_once( THEME_CLASSES . '/widget-pages.php' );
- require_once( THEME_CLASSES . '/widget-search.php' );
- require_once( THEME_CLASSES . '/widget-tags.php' );
-
- /* Register each widget. */
- register_widget( 'Hybrid_Widget_Archives' );
- register_widget( 'Hybrid_Widget_Authors' );
- register_widget( 'Hybrid_Widget_Bookmarks' );
- register_widget( 'Hybrid_Widget_Calendar' );
- register_widget( 'Hybrid_Widget_Categories' );
- register_widget( 'Hybrid_Widget_Pages' );
- register_widget( 'Hybrid_Widget_Search' );
- register_widget( 'Hybrid_Widget_Tags' );
- }
-
- /**
- * Unregister default WordPress widgets we don't need. The theme adds its own
- * versions of these widgets.
- *
- * @since 0.3.2
- * @uses unregister_widget() Removes individual widgets.
- * @link http://codex.wordpress.org/WordPress_Widgets_Api
- */
- function hybrid_unregister_widgets() {
- unregister_widget( 'WP_Widget_Pages' );
- unregister_widget( 'WP_Widget_Calendar' );
- unregister_widget( 'WP_Widget_Archives' );
- unregister_widget( 'WP_Widget_Links' );
- unregister_widget( 'WP_Widget_Categories' );
- unregister_widget( 'WP_Widget_Recent_Posts' );
- unregister_widget( 'WP_Widget_Search' );
- unregister_widget( 'WP_Widget_Tag_Cloud' );
- }
-
- /**
- * Loads the Primary widget area. Users can overwrite 'aside-primary.php'.
- *
- * @since 0.2.2
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_primary() {
- locate_template( array( 'sidebar-primary.php' ), true );
- }
-
- /**
- * Loads the Secondary widget area. Users can overwrite 'aside-secondary.php'.
- *
- * @since 0.2.2
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_secondary() {
- locate_template( array( 'sidebar-secondary.php' ), true );
- }
-
- /**
- * Loads the Subsidiary widget area. Users can overwrite 'aside-subsidiary.php'.
- *
- * @since 0.3.1
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_subsidiary() {
- locate_template( array( 'sidebar-subsidiary.php' ), true );
- }
-
- /**
- * Loads the Utility: Before Content widget area. Users can overwrite
- * 'utility-before-content.php' in child themes.
- *
- * @since 0.4
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_utility_before_content() {
- locate_template( array( 'sidebar-before-content.php' ), true );
- }
-
- /**
- * Loads the Utility: After Content widget area. Users can overwrite
- * 'utility-after-content.php' in child themes.
- *
- * @since 0.4
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_utility_after_content() {
- locate_template( array( 'sidebar-after-content.php' ), true );
- }
-
- /**
- * Loads the Utility: After Singular widget area. Users can overwrite
- * 'utility-after-singular.php' in child themes.
- *
- * @since 0.7
- * @uses locate_template() Checks for template in child and parent theme.
- */
- function hybrid_get_utility_after_singular() {
- locate_template( array( 'sidebar-after-singular.php' ), true );
- }
-
- /**
- * Check for widgets in widget-ready areas. Allows user to completely collapse
- * widget-ready areas by not adding widgets to particular widget areas. Checks widget
- * areas by name and/or ID.
- *
- * @deprecated 0.6.1
- * Realizing that WordPress 2.8 introduced is_active_sidebar(), we're still using this
- * function because the WP function doesn't perform correctly. See ticket #10136.
- * @link http://core.trac.wordpress.org/ticket/10136
- *
- * Major props to Chaos Kaizer and Ian Stewart.
- * @link http://wordpress.org/support/topic/190184#post-808787
- * @link http://blog.kaizeku.com
- * @link http://themeshaper.com/collapsing-wordpress-widget-ready-areas-sidebars
- *
- * @since 0.2
- * @param string|int $index name|ID of widget area.
- * @return bool
- */
- function is_sidebar_active( $index = 1 ) {
- $sidebars_widgets = wp_get_sidebars_widgets();
-
- $index = ( is_int( $index ) ) ? "sidebar-$index" : sanitize_title( $index );
-
- if ( isset( $sidebars_widgets[$index] ) && !empty( $sidebars_widgets[$index] ) )
- return true;
-
- return false;
- }
-
- /**
- * Removes all widget areas on the No Widgets page template. We're only going to run
- * it on the No Widgets template. Users that need additional templates without widgets
- * should create a simliar function in their child theme.
- *
- * We're retaining the 'sidebar' terminology until such time that the
- * WordPress community decides on a better term.
- *
- * @since 0.5
- * @uses sidebars_widgets Filter to remove all widget areas
- */
- function remove_sidebars( $sidebars_widgets ) {
- global $wp_query;
-
- if ( is_singular() ) {
- $template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true );
- if ( 'no-widgets.php' == $template || "{$wp_query->post->post_type}-no-widgets.php" == $template )
- $sidebars_widgets = array( false );
- }
- return $sidebars_widgets;
- }
-
- ?>