Нема описа

class-acf-field-message.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. if ( ! class_exists( 'acf_field_message' ) ) :
  3. class acf_field_message extends acf_field {
  4. public $show_in_rest = false;
  5. /*
  6. * __construct
  7. *
  8. * This function will setup the field type data
  9. *
  10. * @type function
  11. * @date 5/03/2014
  12. * @since 5.0.0
  13. *
  14. * @param n/a
  15. * @return n/a
  16. */
  17. function initialize() {
  18. // vars
  19. $this->name = 'message';
  20. $this->label = __( 'Message', 'acf' );
  21. $this->category = 'layout';
  22. $this->defaults = array(
  23. 'message' => '',
  24. 'esc_html' => 0,
  25. 'new_lines' => 'wpautop',
  26. );
  27. }
  28. /*
  29. * render_field()
  30. *
  31. * Create the HTML interface for your field
  32. *
  33. * @param $field - an array holding all the field's data
  34. *
  35. * @type action
  36. * @since 3.6
  37. * @date 23/01/13
  38. */
  39. function render_field( $field ) {
  40. // vars
  41. $m = $field['message'];
  42. // wptexturize (improves "quotes")
  43. $m = wptexturize( $m );
  44. // esc_html
  45. if ( $field['esc_html'] ) {
  46. $m = esc_html( $m );
  47. }
  48. // new lines
  49. if ( $field['new_lines'] == 'wpautop' ) {
  50. $m = wpautop( $m );
  51. } elseif ( $field['new_lines'] == 'br' ) {
  52. $m = nl2br( $m );
  53. }
  54. // return
  55. echo acf_esc_html( $m );
  56. }
  57. /*
  58. * render_field_settings()
  59. *
  60. * Create extra options for your field. This is rendered when editing a field.
  61. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  62. *
  63. * @param $field - an array holding all the field's data
  64. *
  65. * @type action
  66. * @since 3.6
  67. * @date 23/01/13
  68. */
  69. function render_field_settings( $field ) {
  70. // default_value
  71. acf_render_field_setting(
  72. $field,
  73. array(
  74. 'label' => __( 'Message', 'acf' ),
  75. 'instructions' => '',
  76. 'type' => 'textarea',
  77. 'name' => 'message',
  78. )
  79. );
  80. // formatting
  81. acf_render_field_setting(
  82. $field,
  83. array(
  84. 'label' => __( 'New Lines', 'acf' ),
  85. 'instructions' => __( 'Controls how new lines are rendered', 'acf' ),
  86. 'type' => 'select',
  87. 'name' => 'new_lines',
  88. 'choices' => array(
  89. 'wpautop' => __( 'Automatically add paragraphs', 'acf' ),
  90. 'br' => __( 'Automatically add &lt;br&gt;', 'acf' ),
  91. '' => __( 'No Formatting', 'acf' ),
  92. ),
  93. )
  94. );
  95. // HTML
  96. acf_render_field_setting(
  97. $field,
  98. array(
  99. 'label' => __( 'Escape HTML', 'acf' ),
  100. 'instructions' => __( 'Allow HTML markup to display as visible text instead of rendering', 'acf' ),
  101. 'name' => 'esc_html',
  102. 'type' => 'true_false',
  103. 'ui' => 1,
  104. )
  105. );
  106. }
  107. /*
  108. * translate_field
  109. *
  110. * This function will translate field settings
  111. *
  112. * @type function
  113. * @date 8/03/2016
  114. * @since 5.3.2
  115. *
  116. * @param $field (array)
  117. * @return $field
  118. */
  119. function translate_field( $field ) {
  120. // translate
  121. $field['message'] = acf_translate( $field['message'] );
  122. // return
  123. return $field;
  124. }
  125. /*
  126. * load_field()
  127. *
  128. * This filter is appied to the $field after it is loaded from the database
  129. *
  130. * @type filter
  131. * @since 3.6
  132. * @date 23/01/13
  133. *
  134. * @param $field - the field array holding all the field options
  135. *
  136. * @return $field - the field array holding all the field options
  137. */
  138. function load_field( $field ) {
  139. // remove name to avoid caching issue
  140. $field['name'] = '';
  141. // remove instructions
  142. $field['instructions'] = '';
  143. // remove required to avoid JS issues
  144. $field['required'] = 0;
  145. // set value other than 'null' to avoid ACF loading / caching issue
  146. $field['value'] = false;
  147. // return
  148. return $field;
  149. }
  150. }
  151. // initialize
  152. acf_register_field_type( 'acf_field_message' );
  153. endif; // class_exists check