WPCF7_Integration

The Contact Form 7 WPCF7 Integration class.

Defined (1)

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

/includes/integration.php  
  1. class WPCF7_Integration { 
  2.  
  3. private static $instance; 
  4.  
  5. private $services = array(); 
  6. private $categories = array(); 
  7.  
  8. private function __construct() {} 
  9.  
  10. public static function get_instance() { 
  11. if ( empty( self::$instance ) ) { 
  12. self::$instance = new self; 
  13.  
  14. return self::$instance; 
  15.  
  16. public function add_service( $name, WPCF7_Service $service ) { 
  17. $name = sanitize_key( $name ); 
  18.  
  19. if ( empty( $name ) || isset( $this->services[$name] ) ) { 
  20. return false; 
  21.  
  22. $this->services[$name] = $service; 
  23.  
  24. public function add_category( $name, $title ) { 
  25. $name = sanitize_key( $name ); 
  26.  
  27. if ( empty( $name ) || isset( $this->categories[$name] ) ) { 
  28. return false; 
  29.  
  30. $this->categories[$name] = $title; 
  31.  
  32. public function service_exists( $name = '' ) { 
  33. if ( '' == $name ) { 
  34. return (bool) count( $this->services ); 
  35. } else { 
  36. return isset( $this->services[$name] ); 
  37.  
  38. public function get_service( $name ) { 
  39. if ( $this->service_exists( $name ) ) { 
  40. return $this->services[$name]; 
  41. } else { 
  42. return false; 
  43.  
  44. public function list_services( $args = '' ) { 
  45. $args = wp_parse_args( $args, array( 
  46. 'include' => array(),  
  47. ) ); 
  48.  
  49. $singular = false; 
  50. $services = (array) $this->services; 
  51.  
  52. if ( ! empty( $args['include'] ) ) { 
  53. $services = array_intersect_key( $services,  
  54. array_flip( (array) $args['include'] ) ); 
  55.  
  56. if ( 1 == count( $services ) ) { 
  57. $singular = true; 
  58.  
  59. if ( empty( $services ) ) { 
  60. return; 
  61.  
  62. $action = wpcf7_current_action(); 
  63.  
  64. foreach ( $services as $name => $service ) { 
  65. $cats = array_intersect_key( $this->categories,  
  66. array_flip( $service->get_categories() ) ); 
  67. ?> 
  68. <div class="card<?php echo $service->is_active() ? ' active' : ''; ?>" id="<?php echo esc_attr( $name ); ?>"> 
  69. <?php $service->icon(); ?> 
  70. <h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2> 
  71. <div class="infobox"> 
  72. <?php echo esc_html( implode( ', ', $cats ) ); ?> 
  73. <br /> 
  74. <?php $service->link(); ?> 
  75. </div> 
  76. <br class="clear" /> 
  77.  
  78. <div class="inside"> 
  79. <?php 
  80. if ( $singular ) { 
  81. $service->display( $action ); 
  82. } else { 
  83. $service->display(); 
  84. ?> 
  85. </div> 
  86. </div> 
  87. <?php 
  88.