PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/news/library/functions/sidebars.php

https://bitbucket.org/lgorence/quickpress
PHP | 120 lines | 60 code | 15 blank | 45 comment | 2 complexity | 55d4bc9659793dcfc38b8f261ff02a59 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Sets up the default framework sidebars if the theme supports them. By default, the framework registers
  4. * seven sidebars. Themes may choose to use one or more of these sidebars. A theme must register support
  5. * for 'hybrid-core-sidebars' to use them and register each sidebar ID within an array for the second
  6. * parameter of add_theme_support().
  7. *
  8. * @package HybridCore
  9. * @subpackage Functions
  10. * @author Justin Tadlock <justin@justintadlock.com>
  11. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  12. * @link http://themehybrid.com/hybrid-core
  13. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  14. */
  15. /* Register widget areas. */
  16. add_action( 'widgets_init', 'hybrid_register_sidebars' );
  17. /**
  18. * Registers the default framework dynamic sidebars based on the sidebars the theme has added support
  19. * for using add_theme_support().
  20. *
  21. * @since 0.7.0
  22. * @access private
  23. * @uses register_sidebar() Registers a sidebar with WordPress.
  24. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  25. * @return void
  26. */
  27. function hybrid_register_sidebars() {
  28. /* Get the theme-supported sidebars. */
  29. $supported_sidebars = get_theme_support( 'hybrid-core-sidebars' );
  30. /* If the theme doesn't add support for any sidebars, return. */
  31. if ( !is_array( $supported_sidebars[0] ) )
  32. return;
  33. /* Get the available core framework sidebars. */
  34. $core_sidebars = hybrid_get_sidebars();
  35. /* Loop through the supported sidebars. */
  36. foreach ( $supported_sidebars[0] as $sidebar ) {
  37. /* Make sure the given sidebar is one of the core sidebars. */
  38. if ( isset( $core_sidebars[$sidebar] ) ) {
  39. /* Set up some default sidebar arguments. */
  40. $defaults = array(
  41. 'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-wrap widget-inside">',
  42. 'after_widget' => '</div></div>',
  43. 'before_title' => '<h3 class="widget-title">',
  44. 'after_title' => '</h3>'
  45. );
  46. /* Allow developers to filter the default sidebar arguments. */
  47. $defaults = apply_filters( hybrid_get_prefix() . '_sidebar_defaults', $defaults, $sidebar );
  48. /* Parse the sidebar arguments and defaults. */
  49. $args = wp_parse_args( $core_sidebars[$sidebar], $defaults );
  50. /* If no 'id' was given, use the $sidebar variable and sanitize it. */
  51. $args['id'] = ( isset( $args['id'] ) ? sanitize_key( $args['id'] ) : sanitize_key( $sidebar ) );
  52. /* Allow developers to filter the sidebar arguments. */
  53. $args = apply_filters( hybrid_get_prefix() . '_sidebar_args', $args, $sidebar );
  54. /* Register the sidebar. */
  55. register_sidebar( $args );
  56. }
  57. }
  58. }
  59. /**
  60. * Returns an array of the core framework's available sidebars for use in themes. We'll just set the
  61. * ID (array keys), name, and description of each sidebar. The other sidebar arguments will be set when the
  62. * sidebar is registered.
  63. *
  64. * @since 1.2.0
  65. * @access private
  66. * @return array $sidebars All the available framework sidebars.
  67. */
  68. function hybrid_get_sidebars() {
  69. /* Set up an array of sidebars. */
  70. $sidebars = array(
  71. 'primary' => array(
  72. 'name' => _x( 'Primary', 'sidebar', 'hybrid-core' ),
  73. 'description' => __( 'The main (primary) widget area, most often used as a sidebar.', 'hybrid-core' )
  74. ),
  75. 'secondary' => array(
  76. 'name' => _x( 'Secondary', 'sidebar', 'hybrid-core' ),
  77. 'description' => __( 'The second most important widget area, most often used as a secondary sidebar.', 'hybrid-core' ),
  78. ),
  79. 'subsidiary' => array(
  80. 'name' => _x( 'Subsidiary', 'sidebar', 'hybrid-core' ),
  81. 'description' => __( 'A widget area loaded in the footer of the site.', 'hybrid-core' ),
  82. ),
  83. 'header' => array(
  84. 'name' => _x( 'Header', 'sidebar', 'hybrid-core' ),
  85. 'description' => __( "Displayed within the site's header area.", 'hybrid-core' ),
  86. ),
  87. 'before-content' => array(
  88. 'name' => _x( 'Before Content', 'sidebar', 'hybrid-core' ),
  89. 'description' => __( "Loaded before the page's main content area.", 'hybrid-core' ),
  90. ),
  91. 'after-content' => array(
  92. 'name' => _x( 'After Content', 'sidebar', 'hybrid-core' ),
  93. 'description' => __( "Loaded after the page's main content area.", 'hybrid-core' ),
  94. ),
  95. 'after-singular' => array(
  96. 'name' => _x( 'After Singular', 'sidebar', 'hybrid-core' ),
  97. 'description' => __( 'Loaded on singular post (page, attachment, etc.) views before the comments area.', 'hybrid-core' ),
  98. )
  99. );
  100. /* Return the sidebars. */
  101. return $sidebars;
  102. }
  103. ?>