Нет описания

PopupClose.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. /**
  6. * Class PUM_Shortcode_PopupClose
  7. *
  8. * Registers the popup_close shortcode.
  9. */
  10. class PUM_Shortcode_PopupClose extends PUM_Shortcode {
  11. public $version = 2;
  12. public $has_content = true;
  13. /**
  14. * The shortcode tag.
  15. */
  16. public function tag() {
  17. return 'popup_close';
  18. }
  19. public function label() {
  20. return __( 'Popup Close Button', 'popup-maker' );
  21. }
  22. public function description() {
  23. return __( 'Make text or html a close trigger for your popup.', 'popup-maker' );
  24. }
  25. public function inner_content_labels() {
  26. return array(
  27. 'label' => __( 'Content', 'popup-maker' ),
  28. 'description' => __( 'Can contain other shortcodes, images, text or html content.' ),
  29. );
  30. }
  31. public function post_types() {
  32. return array( 'popup' );
  33. }
  34. public function fields() {
  35. return array(
  36. 'general' => array(
  37. 'main' => array(
  38. 'tag' => array(
  39. 'label' => __( 'HTML Tag', 'popup-maker' ),
  40. 'desc' => __( 'The HTML tag used for this element.', 'popup-maker' ),
  41. 'type' => 'select',
  42. 'options' => array(
  43. 'a' => 'a',
  44. 'button' => 'button',
  45. 'div' => 'div',
  46. 'img' => 'img',
  47. 'li' => 'li',
  48. 'p' => 'p',
  49. 'span' => 'span',
  50. ),
  51. 'std' => 'span',
  52. 'required' => true,
  53. ),
  54. 'href' => array(
  55. 'label' => __( 'Value for href', 'popup-maker' ),
  56. 'placeholder' => '#',
  57. 'desc' => __( 'Enter the href value for your link. Leave blank if you do not want this link to take the visitor to a different page.', 'popup-maker' ),
  58. 'type' => 'text',
  59. 'std' => '',
  60. 'dependencies' => array(
  61. 'tag' => array( 'a' ),
  62. ),
  63. ),
  64. 'target' => array(
  65. 'label' => __( 'Target for the element', 'popup-maker' ),
  66. 'placeholder' => '',
  67. 'desc' => __( 'Enter the target value for your link. Can be left blank.', 'popup-maker' ),
  68. 'type' => 'text',
  69. 'std' => '',
  70. 'dependencies' => array(
  71. 'tag' => array( 'a' ),
  72. ),
  73. ),
  74. ),
  75. ),
  76. 'options' => array(
  77. 'main' => array(
  78. 'classes' => array(
  79. 'label' => __( 'CSS Class', 'popup-maker' ),
  80. 'placeholder' => 'my-custom-class',
  81. 'type' => 'text',
  82. 'desc' => __( 'Add additional classes for styling.', 'popup-maker' ),
  83. 'std' => '',
  84. ),
  85. 'do_default' => array(
  86. 'type' => 'checkbox',
  87. 'label' => __( 'Do not prevent the default click functionality.', 'popup-maker' ),
  88. 'desc' => __( 'This prevents us from disabling the browsers default action when a close button is clicked. It can be used to allow a link to a file to both close a popup and still download the file.', 'popup-maker' ),
  89. ),
  90. ),
  91. ),
  92. );
  93. }
  94. /**
  95. * Process shortcode attributes.
  96. *
  97. * Also remaps and cleans old ones.
  98. *
  99. * @param $atts
  100. *
  101. * @return array
  102. */
  103. public function shortcode_atts( $atts ) {
  104. $atts = parent::shortcode_atts( $atts );
  105. if ( empty( $atts['tag'] ) ) {
  106. $atts['tag'] = 'span';
  107. }
  108. if ( empty( $atts['href'] ) ) {
  109. $atts['href'] = '#';
  110. }
  111. if ( ! empty( $atts['class'] ) ) {
  112. $atts['classes'] .= ' ' . $atts['class'];
  113. unset( $atts['class'] );
  114. }
  115. return $atts;
  116. }
  117. /**
  118. * Shortcode handler
  119. *
  120. * @param array $atts shortcode attributes
  121. * @param string $content shortcode content
  122. *
  123. * @return string
  124. */
  125. public function handler( $atts, $content = null ) {
  126. $atts = $this->shortcode_atts( $atts );
  127. $do_default = $atts['do_default'] ? " data-do-default='" . esc_attr( $atts['do_default'] ) . "'" : '';
  128. // Sets up our href and target, if the tag is an `a`.
  129. $href = 'a' === $atts['tag'] ? "href='{$atts['href']}'" : '';
  130. $target = 'a' === $atts['tag'] && ! empty( $atts['target'] ) ? "target='{$atts['target']}'" : '';
  131. $return = "<{$atts['tag']} $href $target class='pum-close popmake-close {$atts['classes']}' {$do_default}>";
  132. $return .= PUM_Helpers::do_shortcode( $content );
  133. $return .= "</{$atts['tag']}>";
  134. return $return;
  135. }
  136. public function template() { ?>
  137. <{{{attrs.tag}}} class="pum-close popmake-close <# if (typeof attrs.classes !== 'undefined') print(attrs.classes); #>">{{{attrs._inner_content}}}</{{{attrs.tag}}}><?php
  138. }
  139. }