WPCF7_Integration{} │ CF7 1.0
Integration API
Хуков нет.
Использование
$WPCF7_Integration = new WPCF7_Integration();
// use class methods
Методы
- private __construct()
- public add_category( $name, $title )
- public add_service( $name, WPCF7_Service $service )
- public static get_builtin_categories()
- public static get_instance()
- public get_service( $name )
- public list_services( $args = '' )
- public service_exists( $name = '' )
Код WPCF7_Integration{} WPCF7 Integration{}
CF7 5.7.7
<?php
class WPCF7_Integration {
private static $instance;
private $services = array();
private $categories = array();
private function __construct() {}
/**
* Returns initially supported service categories.
*
* @return array Service categories.
*/
public static function get_builtin_categories() {
return array(
'spam_protection' => __( 'Spam protection', 'contact-form-7' ),
'email_marketing' => __( 'Email marketing', 'contact-form-7' ),
'payments' => __( 'Payments', 'contact-form-7' ),
);
}
/**
* Returns the singleton instance of this class.
*
* @return WPCF7_Integration The instance.
*/
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
self::$instance->categories = self::get_builtin_categories();
}
return self::$instance;
}
/**
* Adds a service to the services list.
*/
public function add_service( $name, WPCF7_Service $service ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->services[$name] ) ) {
return false;
}
$this->services[$name] = $service;
}
/**
* Adds a service category to the categories list.
*/
public function add_category( $name, $title ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->categories[$name] ) ) {
return false;
}
$this->categories[$name] = $title;
}
/**
* Returns true if a service with the name exists in the services list.
*
* @param string $name The name of service to search.
*/
public function service_exists( $name = '' ) {
if ( '' == $name ) {
return (bool) count( $this->services );
} else {
return isset( $this->services[$name] );
}
}
/**
* Returns a service object with the name.
*
* @param string $name The name of service.
* @return WPCF7_Service|bool The service object if it exists,
* false otherwise.
*/
public function get_service( $name ) {
if ( $this->service_exists( $name ) ) {
return $this->services[$name];
} else {
return false;
}
}
/**
* Prints services list.
*/
public function list_services( $args = '' ) {
$args = wp_parse_args( $args, array(
'include' => array(),
) );
$singular = false;
$services = (array) $this->services;
if ( ! empty( $args['include'] ) ) {
$services = array_intersect_key( $services,
array_flip( (array) $args['include'] )
);
if ( 1 == count( $services ) ) {
$singular = true;
}
}
if ( empty( $services ) ) {
return;
}
$action = wpcf7_current_action();
foreach ( $services as $name => $service ) {
$cats = array_intersect_key( $this->categories,
array_flip( $service->get_categories() )
);
?>
<div class="card<?php echo $service->is_active() ? ' active' : ''; ?>" id="<?php echo esc_attr( $name ); ?>">
<?php $service->icon(); ?>
<h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2>
<div class="infobox">
<?php echo esc_html( implode( ', ', $cats ) ); ?>
</div>
<br class="clear" />
<div class="inside">
<?php
if ( $singular ) {
$service->display( $action );
} else {
$service->display();
}
?>
</div>
</div>
<?php
}
}
}