class-vamtam-customize-button-control.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class Vamtam_Customize_Button_Control extends Vamtam_Customize_Control {
  3. public $type = 'vamtam-button';
  4. // class name for the .button element
  5. public $class;
  6. // href attribute value
  7. public $href;
  8. // assoc array for data-* properties
  9. public $data;
  10. // button text
  11. public $button_title;
  12. /**
  13. * Render the control's content.
  14. */
  15. protected function render_content() {
  16. $setting_value = $this->value();
  17. $name = '_customize-radio-' . $this->id;
  18. if ( ! empty( $this->label ) ) : ?>
  19. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  20. <?php endif;
  21. if ( ! empty( $this->description ) ) : ?>
  22. <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span>
  23. <?php endif;
  24. $data = array();
  25. if ( isset( $this->data ) ) {
  26. foreach ( $this->data as $attr_name => $attr_value ) {
  27. $data[] = 'data-' . sanitize_title_with_dashes( $attr_name ) . '="' . esc_attr( $attr_value ) . '"';
  28. }
  29. }
  30. $data = implode( ' ', $data );
  31. echo '<a href="' . ( isset( $this->href ) ? esc_attr( $this->href ) : '#' ) . '" id="' . esc_attr( $this->id ) . '" title="' . esc_attr( $this->button_title ) . '" class="button ' . esc_attr( $this->class ) . '" ' . $data . '>' . esc_html( $this->button_title ) . '</a>'; // xss ok - $data escaped above
  32. }
  33. public function enqueue() {
  34. wp_enqueue_script(
  35. 'customizer-control-vamtam-button-js',
  36. VAMTAM_CUSTOMIZER_LIB_URL . 'assets/js/button' . ( WP_DEBUG ? '' : '.min' ) . '.js',
  37. array( 'jquery-core', 'customize-base' ),
  38. time(),
  39. true
  40. );
  41. }
  42. }