is_active() ) { $properties += array( 'constant_contact' => array(), ); } return $properties; } add_filter( 'wpcf7_contact_form_property_constant_contact', 'wpcf7_constant_contact_setup_property', 10, 2 ); /** * Sets up the constant_contact property value. For back-compat, this attempts * to take over the value from old settings if the property is empty. */ function wpcf7_constant_contact_setup_property( $property, $contact_form ) { if ( ! empty( $property ) ) { $property = wp_parse_args( $property, array( 'enable_contact_list' => false, 'contact_lists' => array(), ) ); return $property; } $property = array( 'enable_contact_list' => true, 'contact_lists' => array(), ); if ( $contact_form->initial() ) { return $property; } $service_option = (array) WPCF7::get_option( 'constant_contact' ); $property['enable_contact_list'] = ! $contact_form->is_false( 'constant_contact' ); if ( isset( $service_option['contact_lists'] ) ) { $contact_lists = (array) $service_option['contact_lists']; $contact_lists_selected = array(); foreach ( $contact_lists as $list ) { if ( empty( $list['selected'] ) ) { continue; } foreach ( (array) $list['selected'] as $key => $val ) { if ( ! isset( $contact_lists_selected[$key] ) ) { $contact_lists_selected[$key] = array(); } $contact_lists_selected[$key][] = $list['list_id']; } } $related_keys = array( sprintf( 'wpcf7_contact_form:%d', $contact_form->id() ), 'default', ); foreach ( $related_keys as $key ) { if ( ! empty( $contact_lists_selected[$key] ) ) { $property['contact_lists'] = $contact_lists_selected[$key]; break; } } } return $property; } add_action( 'wpcf7_save_contact_form', 'wpcf7_constant_contact_save_contact_form', 10, 1 ); /** * Saves the constant_contact property value. */ function wpcf7_constant_contact_save_contact_form( $contact_form ) { $service = WPCF7_ConstantContact::get_instance(); if ( ! $service->is_active() ) { return; } $prop = isset( $_POST['wpcf7-ctct'] ) ? (array) $_POST['wpcf7-ctct'] : array(); $prop = wp_parse_args( $prop, array( 'enable_contact_list' => false, 'contact_lists' => array(), ) ); $contact_form->set_properties( array( 'constant_contact' => $prop, ) ); } add_filter( 'wpcf7_editor_panels', 'wpcf7_constant_contact_editor_panels', 10, 1 ); /** * Builds the editor panel for the constant_contact property. */ function wpcf7_constant_contact_editor_panels( $panels ) { $service = WPCF7_ConstantContact::get_instance(); if ( ! $service->is_active() ) { return $panels; } $contact_form = WPCF7_ContactForm::get_current(); $prop = wp_parse_args( $contact_form->prop( 'constant_contact' ), array( 'enable_contact_list' => false, 'contact_lists' => array(), ) ); $editor_panel = static function () use ( $prop, $service ) { $description = sprintf( esc_html( __( "You can set up the Constant Contact integration here. For details, see %s.", 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/constant-contact-integration/', 'contact-form-7' ), __( 'Constant Contact integration', 'contact-form-7' ) ) ); $lists = $service->get_contact_lists(); ?>
array( 'title' => __( 'Constant Contact', 'contact-form-7' ), 'callback' => $editor_panel, ), ); return $panels; }