button.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor button control.
  8. *
  9. * A base control for creating a button control. Displays a button that can
  10. * trigger an event.
  11. *
  12. * @since 1.9.0
  13. */
  14. class Control_Button extends Base_UI_Control {
  15. /**
  16. * Get button control type.
  17. *
  18. * Retrieve the control type, in this case `button`.
  19. *
  20. * @since 1.9.0
  21. * @access public
  22. *
  23. * @return string Control type.
  24. */
  25. public function get_type() {
  26. return 'button';
  27. }
  28. /**
  29. * Get button control default settings.
  30. *
  31. * Retrieve the default settings of the button control. Used to
  32. * return the default settings while initializing the button
  33. * control.
  34. *
  35. * @since 1.9.0
  36. * @access protected
  37. *
  38. * @return array Control default settings.
  39. */
  40. protected function get_default_settings() {
  41. return [
  42. 'text' => '',
  43. 'event' => '',
  44. 'button_type' => 'default',
  45. ];
  46. }
  47. /**
  48. * Render button control output in the editor.
  49. *
  50. * Used to generate the control HTML in the editor using Underscore JS
  51. * template. The variables for the class are available using `data` JS
  52. * object.
  53. *
  54. * @since 1.9.0
  55. * @access public
  56. */
  57. public function content_template() {
  58. ?>
  59. <div class="elementor-control-field">
  60. <label class="elementor-control-title">{{{ data.label }}}</label>
  61. <div class="elementor-control-input-wrapper">
  62. <button type="button" class="elementor-button elementor-button-{{{ data.button_type }}}" data-event="{{{ data.event }}}">{{{ data.text }}}</button>
  63. </div>
  64. </div>
  65. <# if ( data.description ) { #>
  66. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  67. <# } #>
  68. <?php
  69. }
  70. }