sidebar.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor sidebar widget.
  8. *
  9. * Elementor widget that insert any sidebar into the page.
  10. *
  11. * @since 1.0.0
  12. */
  13. class Widget_Sidebar extends Widget_Base {
  14. /**
  15. * Get widget name.
  16. *
  17. * Retrieve sidebar widget name.
  18. *
  19. * @since 1.0.0
  20. * @access public
  21. *
  22. * @return string Widget name.
  23. */
  24. public function get_name() {
  25. return 'sidebar';
  26. }
  27. /**
  28. * Get widget title.
  29. *
  30. * Retrieve sidebar widget title.
  31. *
  32. * @since 1.0.0
  33. * @access public
  34. *
  35. * @return string Widget title.
  36. */
  37. public function get_title() {
  38. return __( 'Sidebar', 'elementor' );
  39. }
  40. /**
  41. * Get widget icon.
  42. *
  43. * Retrieve sidebar widget icon.
  44. *
  45. * @since 1.0.0
  46. * @access public
  47. *
  48. * @return string Widget icon.
  49. */
  50. public function get_icon() {
  51. return 'eicon-sidebar';
  52. }
  53. /**
  54. * Get widget keywords.
  55. *
  56. * Retrieve the list of keywords the widget belongs to.
  57. *
  58. * @since 2.1.0
  59. * @access public
  60. *
  61. * @return array Widget keywords.
  62. */
  63. public function get_keywords() {
  64. return [ 'sidebar', 'widget' ];
  65. }
  66. /**
  67. * Register sidebar widget controls.
  68. *
  69. * Adds different input fields to allow the user to change and customize the widget settings.
  70. *
  71. * @since 1.0.0
  72. * @access protected
  73. */
  74. protected function _register_controls() {
  75. global $wp_registered_sidebars;
  76. $options = [];
  77. if ( ! $wp_registered_sidebars ) {
  78. $options[''] = __( 'No sidebars were found', 'elementor' );
  79. } else {
  80. $options[''] = __( 'Choose Sidebar', 'elementor' );
  81. foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
  82. $options[ $sidebar_id ] = $sidebar['name'];
  83. }
  84. }
  85. $default_key = array_keys( $options );
  86. $default_key = array_shift( $default_key );
  87. $this->start_controls_section(
  88. 'section_sidebar',
  89. [
  90. 'label' => __( 'Sidebar', 'elementor' ),
  91. ]
  92. );
  93. $this->add_control( 'sidebar', [
  94. 'label' => __( 'Choose Sidebar', 'elementor' ),
  95. 'type' => Controls_Manager::SELECT,
  96. 'default' => $default_key,
  97. 'options' => $options,
  98. ] );
  99. $this->end_controls_section();
  100. }
  101. /**
  102. * Render sidebar widget output on the frontend.
  103. *
  104. * Written in PHP and used to generate the final HTML.
  105. *
  106. * @since 1.0.0
  107. * @access protected
  108. */
  109. protected function render() {
  110. $sidebar = $this->get_settings_for_display( 'sidebar' );
  111. if ( empty( $sidebar ) ) {
  112. return;
  113. }
  114. dynamic_sidebar( $sidebar );
  115. }
  116. /**
  117. * Render sidebar widget output in the editor.
  118. *
  119. * Written as a Backbone JavaScript template and used to generate the live preview.
  120. *
  121. * @since 1.0.0
  122. * @access protected
  123. */
  124. protected function _content_template() {}
  125. /**
  126. * Render sidebar widget as plain content.
  127. *
  128. * Override the default render behavior, don't render sidebar content.
  129. *
  130. * @since 1.0.0
  131. * @access public
  132. */
  133. public function render_plain_content() {}
  134. }