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. $singular = false; 
  49. $services = (array) $this->services; 
  50.  
  51. if ( ! empty( $args['include'] ) ) { 
  52. $services = array_intersect_key( $services,  
  53. array_flip( (array) $args['include'] ) ); 
  54.  
  55. if ( 1 == count( $services ) ) { 
  56. $singular = true; 
  57.  
  58. if ( empty( $services ) ) { 
  59. return; 
  60.  
  61. $action = wpcf7_current_action(); 
  62.  
  63. foreach ( $services as $name => $service ) { 
  64. $cats = array_intersect_key( $this->categories,  
  65. array_flip( $service->get_categories() ) ); 
  66. ?> 
  67. <div class="card<?php echo $service->is_active() ? ' active' : ''; ?>" id="<?php echo esc_attr( $name ); ?>"> 
  68. <?php $service->icon(); ?> 
  69. <h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2> 
  70. <div class="infobox"> 
  71. <?php echo esc_html( implode( ', ', $cats ) ); ?> 
  72. <br /> 
  73. <?php $service->link(); ?> 
  74. </div> 
  75. <br class="clear" /> 
  76.  
  77. <div class="inside"> 
  78. <?php 
  79. if ( $singular ) { 
  80. $service->display( $action ); 
  81. } else { 
  82. $service->display(); 
  83. ?> 
  84. </div> 
  85. </div> 
  86. <?php 
  87.