sidebars.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * Theme sidebars.
  4. *
  5. * @package Pen
  6. */
  7. if ( ! function_exists( 'pen_sidebars_register' ) ) {
  8. /**
  9. * Register widget areas.
  10. *
  11. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  12. */
  13. function pen_sidebars_register() {
  14. /* phpcs:disable */
  15. $sidebars = array(
  16. 'left' => array(
  17. 'name' => __( 'Left Sidebar', 'pen' ),
  18. 'description' => '',
  19. ),
  20. 'right' => array(
  21. 'name' => __( 'Right Sidebar', 'pen' ),
  22. 'description' => '',
  23. ),
  24. 'header-primary' => array(
  25. 'name' => __( 'Header - Primary', 'pen' ),
  26. 'description' => __( '(Stays in the middle of the header)', 'pen' ),
  27. ),
  28. 'header-secondary' => array(
  29. 'name' => __( 'Header - Secondary', 'pen' ),
  30. 'description' => __( '(Stays at the right of the header)', 'pen' ),
  31. ),
  32. 'search-top' => array(
  33. 'name' => __( 'Search - Top', 'pen' ),
  34. 'description' => __( 'Located above the bigger search box.', 'pen' ),
  35. ),
  36. 'search-left' => array(
  37. 'name' => __( 'Search - Left', 'pen' ),
  38. 'description' => __( 'Located left side of the bigger search box.', 'pen' ),
  39. ),
  40. 'search-right' => array(
  41. 'name' => __( 'Search - Right', 'pen' ),
  42. 'description' => __( 'Located right side of the bigger search box.', 'pen' ),
  43. ),
  44. 'search-bottom' => array(
  45. 'name' => __( 'Search - Bottom', 'pen' ),
  46. 'description' => __( 'Located beneath the bigger search box.', 'pen' ),
  47. ),
  48. 'top' => array(
  49. 'name' => __( 'Top', 'pen' ),
  50. 'description' => __( 'Located above the content area below the header and the navigation menu.', 'pen' ),
  51. ),
  52. 'bottom' => array(
  53. 'name' => __( 'Bottom', 'pen' ),
  54. 'description' => __( 'Located beneath the content area.', 'pen' ),
  55. ),
  56. 'content-top' => array(
  57. 'name' => __( 'Content - Top', 'pen' ),
  58. 'description' => __( 'Located above the content.', 'pen' ),
  59. ),
  60. 'content-bottom' => array(
  61. 'name' => __( 'Content - Bottom', 'pen' ),
  62. 'description' => __( 'Located beneath the content.', 'pen' ),
  63. ),
  64. 'footer-top' => array(
  65. 'name' => __( 'Footer - Top', 'pen' ),
  66. 'description' => '',
  67. ),
  68. 'footer-left' => array(
  69. 'name' => __( 'Footer - Left', 'pen' ),
  70. 'description' => '',
  71. ),
  72. 'footer-right' => array(
  73. 'name' => __( 'Footer - Right', 'pen' ),
  74. 'description' => '',
  75. ),
  76. 'footer-bottom' => array(
  77. 'name' => __( 'Footer - Bottom', 'pen' ),
  78. 'description' => '',
  79. ),
  80. );
  81. /* phpcs:enable */
  82. foreach ( $sidebars as $id => $sidebar ) {
  83. register_sidebar(
  84. array(
  85. 'name' => esc_html( $sidebar['name'] ),
  86. 'id' => 'sidebar-' . esc_attr( $id ),
  87. 'description' => esc_html( $sidebar['description'] ),
  88. 'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
  89. 'after_widget' => '</aside>',
  90. 'before_title' => '<h3 class="widget-title"><span><span>',
  91. 'after_title' => '</span></span></h3>',
  92. )
  93. );
  94. }
  95. }
  96. add_action( 'widgets_init', 'pen_sidebars_register' );
  97. }
  98. if ( ! function_exists( 'pen_sidebar_get' ) ) {
  99. /**
  100. * Sidebars.
  101. *
  102. * @param string $sidebar The sidebar ID.
  103. *
  104. * @since Pen 1.0.0
  105. * @return void
  106. */
  107. function pen_sidebar_get( $sidebar ) {
  108. if ( ! is_registered_sidebar( $sidebar ) ) {
  109. return;
  110. }
  111. if ( pen_sidebar_check( $sidebar ) && is_active_sidebar( $sidebar ) ) {
  112. $classes = trim(
  113. implode(
  114. ' ',
  115. array_filter(
  116. array(
  117. 'sidebar',
  118. 'clearfix',
  119. 'widget-area',
  120. )
  121. )
  122. )
  123. );
  124. if ( 'sidebar-bottom' === $sidebar ) {
  125. if ( pen_option_get( 'color_bottom_background_transparent' ) ) {
  126. $classes .= ' pen_is_transparent';
  127. } else {
  128. $classes .= ' pen_not_transparent';
  129. }
  130. }
  131. ?>
  132. <div id="<?php echo esc_attr( str_ireplace( array( 'sidebar-', '-' ), array( 'pen_', '_' ), $sidebar ) ); ?>" class="<?php echo esc_attr( $classes ); ?>" role="complementary">
  133. <?php
  134. if ( in_array( $sidebar, array( 'sidebar-top', 'sidebar-bottom' ), true ) ) {
  135. ?>
  136. <div class="pen_container">
  137. <?php
  138. }
  139. dynamic_sidebar( $sidebar );
  140. if ( in_array( $sidebar, array( 'sidebar-top', 'sidebar-bottom' ), true ) ) {
  141. ?>
  142. </div>
  143. <?php
  144. }
  145. pen_html_jump_menu( $sidebar );
  146. ?>
  147. </div>
  148. <?php
  149. }
  150. }
  151. }
  152. if ( ! function_exists( 'pen_sidebar_check' ) ) {
  153. /**
  154. * Checks sidebars visibility.
  155. *
  156. * @param string $sidebar The unique sidebar ID.
  157. *
  158. * @since Pen 1.0.0
  159. */
  160. function pen_sidebar_check( $sidebar ) {
  161. if ( ! is_registered_sidebar( $sidebar ) ) {
  162. return;
  163. }
  164. $sidebar = str_ireplace( '-', '_', $sidebar );
  165. $visible = true;
  166. if ( is_home() || is_front_page() ) {
  167. $visible = pen_option_get( 'front_' . $sidebar . '_display' ) ? false : true;
  168. }
  169. if ( is_singular() ) {
  170. $visible = get_post_meta( get_the_ID(), 'pen_' . $sidebar . '_display', true ) ? false : true;
  171. }
  172. return $visible;
  173. }
  174. }