WPCF7_TagGenerator

The Contact Form 7 WPCF7 TagGenerator class.

Defined (1)

The class is defined in the following location(s).

/admin/includes/tag-generator.php  
  1. class WPCF7_TagGenerator { 
  2.  
  3. private static $instance; 
  4.  
  5. private $panels = array(); 
  6.  
  7. private function __construct() {} 
  8.  
  9. public static function get_instance() { 
  10. if ( empty( self::$instance ) ) { 
  11. self::$instance = new self; 
  12.  
  13. return self::$instance; 
  14.  
  15. public function add( $id, $title, $callback, $options = array() ) { 
  16. $id = trim( $id ); 
  17.  
  18. if ( '' === $id || ! wpcf7_is_name( $id ) ) { 
  19. return false; 
  20.  
  21. $this->panels[$id] = array( 
  22. 'title' => $title,  
  23. 'content' => 'tag-generator-panel-' . $id,  
  24. 'options' => $options,  
  25. 'callback' => $callback,  
  26. ); 
  27.  
  28. return true; 
  29.  
  30. public function print_buttons() { 
  31. echo '<span id="tag-generator-list">'; 
  32.  
  33. foreach ( (array) $this->panels as $panel ) { 
  34. echo sprintf( 
  35. '<a href="#TB_inline?width=900&height=500&inlineId=%1$s" class="thickbox button" title="%2$s">%3$s</a>',  
  36. esc_attr( $panel['content'] ),  
  37. esc_attr( sprintf( 
  38. __( 'Form-tag Generator: %s', 'contact-form-7' ),  
  39. $panel['title'] ) ),  
  40. esc_html( $panel['title'] ) ); 
  41.  
  42. echo '</span>'; 
  43.  
  44. public function print_panels( WPCF7_ContactForm $contact_form ) { 
  45. foreach ( (array) $this->panels as $id => $panel ) { 
  46. $callback = $panel['callback']; 
  47.  
  48. $options = wp_parse_args( $panel['options'], array() ); 
  49. $options = array_merge( $options, array( 
  50. 'id' => $id,  
  51. 'title' => $panel['title'],  
  52. 'content' => $panel['content'],  
  53. ) ); 
  54.  
  55. if ( is_callable( $callback ) ) { 
  56. echo sprintf( '<div id="%s" class="hidden">',  
  57. esc_attr( $options['content'] ) ); 
  58. echo sprintf( 
  59. '<form action="" class="tag-generator-panel" data-id="%s">',  
  60. $options['id'] ); 
  61.  
  62. call_user_func( $callback, $contact_form, $options ); 
  63.  
  64. echo '</form></div>'; 
  65.