icon.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: icon
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_icon' ) ) {
  11. class CSF_Field_icon extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $args = wp_parse_args( $this->field, array(
  17. 'button_title' => esc_html__( 'Add Icon', 'sakurairo_csf' ),
  18. 'remove_title' => esc_html__( 'Remove Icon', 'sakurairo_csf' ),
  19. ) );
  20. echo $this->field_before();
  21. $nonce = wp_create_nonce( 'csf_icon_nonce' );
  22. $hidden = ( empty( $this->value ) ) ? ' hidden' : '';
  23. echo '<div class="csf-icon-select">';
  24. echo '<span class="csf-icon-preview'. esc_attr( $hidden ) .'"><i class="'. esc_attr( $this->value ) .'"></i></span>';
  25. echo '<a href="#" class="button button-primary csf-icon-add" data-nonce="'. esc_attr( $nonce ) .'">'. $args['button_title'] .'</a>';
  26. echo '<a href="#" class="button csf-warning-primary csf-icon-remove'. esc_attr( $hidden ) .'">'. $args['remove_title'] .'</a>';
  27. echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="csf-icon-value"'. $this->field_attributes() .' />';
  28. echo '</div>';
  29. echo $this->field_after();
  30. }
  31. public function enqueue() {
  32. add_action( 'admin_footer', array( 'CSF_Field_icon', 'add_footer_modal_icon' ) );
  33. add_action( 'customize_controls_print_footer_scripts', array( 'CSF_Field_icon', 'add_footer_modal_icon' ) );
  34. }
  35. public static function add_footer_modal_icon() {
  36. ?>
  37. <div id="csf-modal-icon" class="csf-modal csf-modal-icon hidden">
  38. <div class="csf-modal-table">
  39. <div class="csf-modal-table-cell">
  40. <div class="csf-modal-overlay"></div>
  41. <div class="csf-modal-inner">
  42. <div class="csf-modal-title">
  43. <?php esc_html_e( 'Add Icon', 'sakurairo_csf' ); ?>
  44. <div class="csf-modal-close csf-icon-close"></div>
  45. </div>
  46. <div class="csf-modal-header">
  47. <input type="text" placeholder="<?php esc_html_e( 'Search...', 'sakurairo_csf' ); ?>" class="csf-icon-search" />
  48. </div>
  49. <div class="csf-modal-content">
  50. <div class="csf-modal-loading"><div class="csf-loading"></div></div>
  51. <div class="csf-modal-load"></div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <?php
  58. }
  59. }
  60. }