hidden.php 776 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. add_action( 'wpcf7_init', 'wpcf7_add_form_tag_hidden', 10, 0 );
  3. function wpcf7_add_form_tag_hidden() {
  4. wpcf7_add_form_tag( 'hidden',
  5. 'wpcf7_hidden_form_tag_handler',
  6. array(
  7. 'name-attr' => true,
  8. 'display-hidden' => true,
  9. )
  10. );
  11. }
  12. function wpcf7_hidden_form_tag_handler( $tag ) {
  13. if ( empty( $tag->name ) ) {
  14. return '';
  15. }
  16. $atts = array();
  17. $class = wpcf7_form_controls_class( $tag->type );
  18. $atts['class'] = $tag->get_class_option( $class );
  19. $atts['id'] = $tag->get_id_option();
  20. $value = (string) reset( $tag->values );
  21. $value = $tag->get_default_option( $value );
  22. $atts['value'] = $value;
  23. $atts['type'] = 'hidden';
  24. $atts['name'] = $tag->name;
  25. $atts = wpcf7_format_atts( $atts );
  26. $html = sprintf( '<input %s />', $atts );
  27. return $html;
  28. }