update
This commit is contained in:
@@ -38,9 +38,7 @@ function wpcf7_sendinblue_save_contact_form( $contact_form, $args, $context ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prop = isset( $_POST['wpcf7-sendinblue'] )
|
||||
? (array) $_POST['wpcf7-sendinblue']
|
||||
: array();
|
||||
$prop = (array) ( $_POST['wpcf7-sendinblue'] ?? array() );
|
||||
|
||||
$prop = wp_parse_args(
|
||||
$prop,
|
||||
@@ -98,15 +96,15 @@ function wpcf7_sendinblue_editor_panels( $panels ) {
|
||||
),
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
|
||||
__( 'Brevo (formerly Sendinblue) integration', 'contact-form-7' )
|
||||
__( 'Brevo integration', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
$lists = $service->get_lists();
|
||||
$lists = wpcf7_sendinblue_get_lists();
|
||||
$templates = $service->get_templates();
|
||||
|
||||
?>
|
||||
<h2><?php echo esc_html( __( 'Brevo (formerly Sendinblue)', 'contact-form-7' ) ); ?></h2>
|
||||
<h2><?php echo esc_html( __( 'Brevo', 'contact-form-7' ) ); ?></h2>
|
||||
|
||||
<fieldset>
|
||||
<legend><?php echo $description; ?></legend>
|
||||
@@ -301,3 +299,39 @@ function wpcf7_sendinblue_editor_panels( $panels ) {
|
||||
|
||||
return $panels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves contact lists from Brevo's database.
|
||||
*/
|
||||
function wpcf7_sendinblue_get_lists() {
|
||||
static $lists = array();
|
||||
|
||||
$service = WPCF7_Sendinblue::get_instance();
|
||||
|
||||
if ( ! empty( $lists ) or ! $service->is_active() ) {
|
||||
return $lists;
|
||||
}
|
||||
|
||||
$limit = 50;
|
||||
$offset = 0;
|
||||
|
||||
while ( count( $lists ) < $limit * 10 ) {
|
||||
$lists_next = (array) $service->get_lists( array(
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
) );
|
||||
|
||||
if ( ! empty( $lists_next ) ) {
|
||||
$lists = array_merge( $lists, $lists_next );
|
||||
}
|
||||
|
||||
if ( count( $lists_next ) < $limit ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$offset += $limit;
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Brevo (formerly Sendinblue) module main file
|
||||
* Brevo module main file
|
||||
*
|
||||
* @link https://contactform7.com/sendinblue-integration/
|
||||
*/
|
||||
@@ -219,6 +219,18 @@ function wpcf7_sendinblue_collect_parameters() {
|
||||
}
|
||||
}
|
||||
|
||||
$params = array_map(
|
||||
function ( $param ) {
|
||||
if ( is_array( $param ) ) {
|
||||
$param = wpcf7_array_flatten( $param );
|
||||
$param = reset( $param );
|
||||
}
|
||||
|
||||
return $param;
|
||||
},
|
||||
$params
|
||||
);
|
||||
|
||||
$params = apply_filters(
|
||||
'wpcf7_sendinblue_collect_parameters',
|
||||
$params
|
||||
|
||||
@@ -27,7 +27,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return __( 'Brevo (formerly Sendinblue)', 'contact-form-7' );
|
||||
return __( 'Brevo', 'contact-form-7' );
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
@@ -47,7 +47,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
|
||||
|
||||
public function link() {
|
||||
echo wpcf7_link(
|
||||
'https://www.brevo.com/?tap_a=30591-fb13f0&tap_s=1031580-b1bb1d',
|
||||
'https://get.brevo.com/wpcf7-integration',
|
||||
'brevo.com'
|
||||
);
|
||||
}
|
||||
@@ -88,9 +88,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
|
||||
$this->reset_data();
|
||||
$redirect_to = $this->menu_page_url( 'action=setup' );
|
||||
} else {
|
||||
$this->api_key = isset( $_POST['api_key'] )
|
||||
? trim( $_POST['api_key'] )
|
||||
: '';
|
||||
$this->api_key = trim( $_POST['api_key'] ?? '' );
|
||||
|
||||
$confirmed = $this->confirm_key();
|
||||
|
||||
@@ -153,7 +151,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
|
||||
'<p><strong>%s</strong></p>',
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
|
||||
__( 'Brevo (formerly Sendinblue) integration', 'contact-form-7' )
|
||||
__( 'Brevo integration', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
@@ -252,12 +250,14 @@ trait WPCF7_Sendinblue_API {
|
||||
}
|
||||
|
||||
|
||||
public function get_lists() {
|
||||
public function get_lists( $options = '' ) {
|
||||
$options = wp_parse_args( $options, array(
|
||||
'limit' => 50,
|
||||
'offset' => 0,
|
||||
) );
|
||||
|
||||
$endpoint = add_query_arg(
|
||||
array(
|
||||
'limit' => 50,
|
||||
'offset' => 0,
|
||||
),
|
||||
$options,
|
||||
'https://api.sendinblue.com/v3/contacts/lists'
|
||||
);
|
||||
|
||||
@@ -336,7 +336,7 @@ trait WPCF7_Sendinblue_API {
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
'body' => json_encode( $properties ),
|
||||
'body' => wp_json_encode( $properties ),
|
||||
);
|
||||
|
||||
$response = wp_remote_post( $endpoint, $request );
|
||||
@@ -364,7 +364,7 @@ trait WPCF7_Sendinblue_API {
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
'body' => json_encode( $properties ),
|
||||
'body' => wp_json_encode( $properties ),
|
||||
);
|
||||
|
||||
$response = wp_remote_post( $endpoint, $request );
|
||||
|
||||
Reference in New Issue
Block a user