__( 'LocaliQ', 'advanced-form-integration' ),
'tasks' => array(
'submit_lead' => __( 'Submit Lead', 'advanced-form-integration' ),
),
);
return $actions;
}
add_filter( 'adfoin_settings_tabs', 'adfoin_localiq_settings_tab', 10, 1 );
function adfoin_localiq_settings_tab( $providers ) {
$providers['localiq'] = __( 'LocaliQ', 'advanced-form-integration' );
return $providers;
}
add_action( 'adfoin_settings_view', 'adfoin_localiq_settings_view', 10, 1 );
function adfoin_localiq_settings_view( $current_tab ) {
if ( 'localiq' !== $current_tab ) {
return;
}
$title = __( 'LocaliQ', 'advanced-form-integration' );
$key = 'localiq';
$arguments = wp_json_encode( array(
'platform' => $key,
'fields' => array(
array(
'key' => 'endpoint',
'label' => __( 'Lead Intake URL', 'advanced-form-integration' ),
'hidden' => false,
'placeholder' => 'https://…/leads',
),
array(
'key' => 'apiKey',
'label' => __( 'Bearer Token', 'advanced-form-integration' ),
'hidden' => true,
),
),
) );
$instructions = sprintf(
'
- %s
- %s
- %s
',
esc_html__( 'Ask your LocaliQ account team for a Lead Intake URL and Bearer token. LocaliQ\'s public API is read-only for reporting and does not expose a standard "submit lead" endpoint — intake URLs are provisioned per account.', 'advanced-form-integration' ),
esc_html__( 'Paste the full URL (including any per-account path segments) and the Bearer token above.', 'advanced-form-integration' ),
esc_html__( 'AFI POSTs JSON to that URL with Authorization: Bearer {token}.', 'advanced-form-integration' )
);
echo adfoin_platform_settings_template( $title, $key, $arguments, $instructions ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
add_action( 'adfoin_action_fields', 'adfoin_localiq_action_fields' );
function adfoin_localiq_action_fields() {
?>
'firstName', 'value' => __( 'First Name', 'advanced-form-integration' ) ),
array( 'key' => 'lastName', 'value' => __( 'Last Name', 'advanced-form-integration' ) ),
array( 'key' => 'email', 'value' => __( 'Email', 'advanced-form-integration' ), 'required' => true ),
array( 'key' => 'phone', 'value' => __( 'Phone', 'advanced-form-integration' ) ),
array( 'key' => 'postalCode', 'value' => __( 'Postal Code', 'advanced-form-integration' ) ),
array( 'key' => 'message', 'value' => __( 'Message', 'advanced-form-integration' ), 'type' => 'textarea' ),
array( 'key' => 'source', 'value' => __( 'Source', 'advanced-form-integration' ), 'description' => __( 'Defaults to "AFI" when blank.', 'advanced-form-integration' ) ),
array( 'key' => 'campaignId', 'value' => __( 'Campaign ID', 'advanced-form-integration' ) ),
);
wp_send_json_success( $fields );
}
add_action( 'adfoin_localiq_job_queue', 'adfoin_localiq_job_queue', 10, 1 );
function adfoin_localiq_job_queue( $data ) {
adfoin_localiq_send_data( $data['record'], $data['posted_data'] );
}
function adfoin_localiq_send_data( $record, $posted_data ) {
if ( 'submit_lead' !== ( $record['task'] ?? '' ) ) {
return;
}
$record_data = json_decode( $record['data'], true );
if ( adfoin_check_conditional_logic( $record_data['action_data']['cl'] ?? array(), $posted_data ) ) {
return;
}
$data = isset( $record_data['field_data'] ) ? $record_data['field_data'] : array();
$cred_id = isset( $data['credId'] ) ? $data['credId'] : '';
if ( ! $cred_id ) {
return;
}
$fields = array();
foreach ( $data as $key => $value ) {
if ( 'credId' === $key ) {
continue;
}
$parsed = adfoin_get_parsed_values( $value, $posted_data );
if ( '' !== $parsed && null !== $parsed ) {
$fields[ $key ] = $parsed;
}
}
if ( empty( $fields['email'] ) ) {
return;
}
$payload = array(
'contact' => array_filter( array(
'firstName' => $fields['firstName'] ?? '',
'lastName' => $fields['lastName'] ?? '',
'email' => $fields['email'],
'phone' => $fields['phone'] ?? '',
'postalCode' => $fields['postalCode'] ?? '',
) ),
'message' => $fields['message'] ?? '',
'source' => $fields['source'] ?? 'AFI',
);
if ( ! empty( $fields['campaignId'] ) ) {
$payload['campaignId'] = $fields['campaignId'];
}
adfoin_localiq_request( $payload, $record, $cred_id );
}
if ( ! function_exists( 'adfoin_localiq_request' ) ) :
/**
* POST a JSON payload to the configured LocaliQ intake URL.
*
* @return array|WP_Error
*/
function adfoin_localiq_request( $data, $record = array(), $cred_id = '' ) {
$credentials = adfoin_get_credentials_by_id( 'localiq', $cred_id );
if ( ! $credentials ) {
return new WP_Error( 'missing_credentials', __( 'LocaliQ credentials not found.', 'advanced-form-integration' ) );
}
$endpoint = isset( $credentials['endpoint'] ) ? trim( $credentials['endpoint'] ) : '';
$token = isset( $credentials['apiKey'] ) ? trim( $credentials['apiKey'] ) : '';
if ( ! $endpoint || ! $token ) {
return new WP_Error( 'missing_auth', __( 'LocaliQ intake URL or Bearer token missing.', 'advanced-form-integration' ) );
}
$args = array(
'timeout' => 30,
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $token,
),
'body' => wp_json_encode( $data ),
);
$response = wp_remote_request( esc_url_raw( $endpoint ), $args );
if ( $record ) {
adfoin_add_to_log( $response, $endpoint, $args, $record );
}
return $response;
}
endif;
function adfoin_localiq_credentials_list() {
foreach ( adfoin_read_credentials( 'localiq' ) as $option ) {
printf( '', esc_attr( $option['id'] ), esc_html( $option['title'] ) );
}
}