label. * * @return array */ function a2leads_integrations() { return array( 'cf7' => 'Contact Form 7', 'wpforms' => 'WPForms', 'elementor' => 'Elementor Pro Forms', 'gravity' => 'Gravity Forms', 'ninja' => 'Ninja Forms', ); } /** * Default settings. * * @return array */ function a2leads_defaults() { return array( 'webhook_url' => '', 'secret' => '', 'integrations' => array_keys( a2leads_integrations() ), 'snippet' => 0, 'public_key' => '', 'blocking' => 0, ); } /** * Current settings merged with defaults. * * @return array */ function a2leads_settings() { $saved = get_option( A2LEADS_OPTION, array() ); if ( ! is_array( $saved ) ) { $saved = array(); } $settings = array_merge( a2leads_defaults(), $saved ); if ( ! is_array( $settings['integrations'] ) ) { $settings['integrations'] = array(); } return $settings; } /** * Is an integration switched on? * * @param string $key Integration key. * @return bool */ function a2leads_enabled( $key ) { $settings = a2leads_settings(); return in_array( $key, $settings['integrations'], true ); } /** * Base URL of the A2Leads app, worked out from the webhook URL. * "https://a2leads.com/api/v1/hooks/pk_123" => "https://a2leads.com". * * @return string */ function a2leads_api_base() { $settings = a2leads_settings(); $url = (string) $settings['webhook_url']; if ( '' === $url ) { return ''; } $base = preg_replace( '#/api/v1/hooks/.*$#', '', $url ); return untrailingslashit( (string) $base ); } /** * Public key: from the settings field, or taken from the webhook URL. * * @return string */ function a2leads_public_key() { $settings = a2leads_settings(); if ( '' !== $settings['public_key'] ) { return (string) $settings['public_key']; } if ( preg_match( '#/api/v1/hooks/([A-Za-z0-9_\-]+)#', (string) $settings['webhook_url'], $m ) ) { return $m[1]; } return ''; } /* ------------------------------------------------------------------------- * Sending * ---------------------------------------------------------------------- */ /** * Field keys that must never be sent (passwords, card data, captcha tokens). * * @param string $key Field name or label. * @return bool */ function a2leads_is_sensitive_key( $key ) { return (bool) preg_match( '/pass(word)?|card.?number|credit.?card|cvv|cvc|iban|sort.?code|account.?number|captcha|recaptcha|turnstile|nonce|^_wp|^_wpcf7/i', (string) $key ); } /** * Turns any value into a clean, bounded string. * * @param mixed $value Raw value. * @return string */ function a2leads_clean_value( $value ) { if ( is_array( $value ) ) { $parts = array(); foreach ( $value as $item ) { if ( is_scalar( $item ) ) { $item = trim( (string) $item ); if ( '' !== $item ) { $parts[] = $item; } } } $value = implode( ', ', $parts ); } elseif ( is_bool( $value ) ) { $value = $value ? 'yes' : ''; } elseif ( ! is_scalar( $value ) ) { return ''; } $value = wp_strip_all_tags( (string) $value ); $value = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); $value = trim( $value ); if ( function_exists( 'mb_substr' ) ) { return mb_substr( $value, 0, 5000 ); } return substr( $value, 0, 5000 ); } /** * Adds a field to the payload, skipping sensitive/empty ones and de-duplicating labels. * * @param array $fields Payload being built (by reference). * @param string $key Label or field name. * @param mixed $value Value. * @return void */ function a2leads_add_field( array &$fields, $key, $value ) { $key = trim( wp_strip_all_tags( (string) $key ) ); if ( '' === $key || a2leads_is_sensitive_key( $key ) ) { return; } $value = a2leads_clean_value( $value ); if ( '' === $value ) { return; } if ( function_exists( 'mb_substr' ) ) { $key = mb_substr( $key, 0, 120 ); } $unique = $key; $n = 2; while ( isset( $fields[ $unique ] ) ) { $unique = $key . ' (' . $n . ')'; $n++; } $fields[ $unique ] = $value; } /** * Best guess at the page the visitor submitted the form from. * * @return string */ function a2leads_current_page() { $referer = wp_get_referer(); if ( $referer ) { return esc_url_raw( $referer ); } if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ); $uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ); return esc_url_raw( ( is_ssl() ? 'https://' : 'http://' ) . $host . $uri ); } return home_url( '/' ); } /** * Sends a lead to A2Leads. Never throws; never slows the visitor down unless * "wait for a response" is switched on. * * @param string $plugin Short plugin id (cf7, wpforms…). * @param string $form_title Human form name. * @param array $fields Label => value. * @param string $page Page URL ('' = work it out). * @param bool|null $blocking Force blocking mode (used by the test button). * @return array{ok:bool,code:int,body:string,error:string} */ function a2leads_send( $plugin, $form_title, array $fields, $page = '', $blocking = null ) { $result = array( 'ok' => false, 'code' => 0, 'body' => '', 'error' => '', ); try { $settings = a2leads_settings(); $url = (string) $settings['webhook_url']; $secret = (string) $settings['secret']; if ( '' === $url || '' === $secret ) { $result['error'] = __( 'Webhook URL or secret is missing. Add them under Settings → A2Leads.', 'a2leads' ); return $result; } if ( empty( $fields ) ) { $result['error'] = __( 'The form had no fields to send.', 'a2leads' ); return $result; } if ( null === $blocking ) { $blocking = ! empty( $settings['blocking'] ); } $labels = a2leads_integrations(); $name = isset( $labels[ $plugin ] ) ? $labels[ $plugin ] : 'WordPress'; $source = $form_title ? $name . ' · ' . $form_title : $name; $body = array( 'fields' => $fields, '_a2leads' => array( 'source' => function_exists( 'mb_substr' ) ? mb_substr( $source, 0, 160 ) : substr( $source, 0, 160 ), 'page' => $page ? $page : a2leads_current_page(), 'site' => home_url( '/' ), 'plugin' => 'a2leads-wp/' . A2LEADS_VERSION, ), ); /** * Filter the payload before it is sent to A2Leads. * * @param array $body Payload. * @param string $plugin Integration key. */ $body = apply_filters( 'a2leads_payload', $body, $plugin ); $response = wp_remote_post( $url, array( 'timeout' => $blocking ? 10 : 5, 'blocking' => (bool) $blocking, 'headers' => array( 'Content-Type' => 'application/json', 'X-A2Leads-Secret' => $secret, 'X-A2Leads-Source' => 'wordpress/' . sanitize_key( $plugin ), ), 'body' => wp_json_encode( $body ), ) ); if ( is_wp_error( $response ) ) { $result['error'] = $response->get_error_message(); } elseif ( ! $blocking ) { $result['ok'] = true; } else { $result['code'] = (int) wp_remote_retrieve_response_code( $response ); $result['body'] = (string) wp_remote_retrieve_body( $response ); $result['ok'] = $result['code'] >= 200 && $result['code'] < 300; if ( ! $result['ok'] ) { // Known statuses get the plain-English hint (it says how to fix it); anything else shows A2Leads' own message. $decoded = json_decode( $result['body'], true ); $result['error'] = ! in_array( $result['code'], array( 401, 404, 422, 429 ), true ) && is_array( $decoded ) && ! empty( $decoded['error'] ) ? (string) $decoded['error'] : a2leads_status_hint( $result['code'] ); } } a2leads_log( $source, $result, (bool) $blocking ); } catch ( \Throwable $e ) { $result['error'] = $e->getMessage(); } return $result; } /** * Plain-English hint for an HTTP status. * * @param int $code HTTP status. * @return string */ function a2leads_status_hint( $code ) { switch ( (int) $code ) { case 401: return __( 'Wrong or missing webhook secret. Copy it again from “Connect your website” in A2Leads (or rotate it).', 'a2leads' ); case 404: return __( 'A2Leads did not recognise this webhook URL. Copy it again from “Connect your website”.', 'a2leads' ); case 422: return __( 'The enquiry had no valid email address or phone number.', 'a2leads' ); case 429: return __( 'Too many requests in a short time. Wait a minute and try again.', 'a2leads' ); default: /* translators: %d: HTTP status code */ return sprintf( __( 'A2Leads replied with HTTP %d.', 'a2leads' ), (int) $code ); } } /** * Keeps a tiny log of the last sends. * * @param string $source Source label. * @param array $result Send result. * @param bool $blocking Whether we waited for the reply. * @return void */ function a2leads_log( $source, array $result, $blocking ) { $log = get_option( A2LEADS_LOG_OPTION, array() ); if ( ! is_array( $log ) ) { $log = array(); } $status = ''; if ( $result['error'] && ! $result['code'] ) { $status = 'Error: ' . $result['error']; } elseif ( ! $blocking ) { $status = 'Sent (not waiting for reply)'; } else { $decoded = json_decode( $result['body'], true ); $status = 'HTTP ' . $result['code']; if ( is_array( $decoded ) && ! empty( $decoded['status'] ) ) { $status .= ' · ' . sanitize_text_field( (string) $decoded['status'] ); } } array_unshift( $log, array( 'time' => time(), 'form' => sanitize_text_field( $source ), 'status' => sanitize_text_field( function_exists( 'mb_substr' ) ? mb_substr( $status, 0, 200 ) : substr( $status, 0, 200 ) ), ) ); update_option( A2LEADS_LOG_OPTION, array_slice( $log, 0, A2LEADS_LOG_MAX ), false ); } /* ------------------------------------------------------------------------- * Form plugin integrations * ---------------------------------------------------------------------- */ /** * Contact Form 7. * * @param object $contact_form WPCF7_ContactForm. * @return void */ function a2leads_cf7( $contact_form ) { try { if ( ! a2leads_enabled( 'cf7' ) || ! class_exists( 'WPCF7_Submission' ) ) { return; } $submission = WPCF7_Submission::get_instance(); if ( ! $submission ) { return; } $posted = (array) $submission->get_posted_data(); $skip = array(); if ( is_object( $contact_form ) && method_exists( $contact_form, 'scan_form_tags' ) ) { foreach ( (array) $contact_form->scan_form_tags() as $tag ) { $type = is_object( $tag ) ? (string) $tag->basetype : ''; if ( in_array( $type, array( 'file', 'captchac', 'captchar', 'quiz', 'recaptcha', 'password' ), true ) && ! empty( $tag->name ) ) { $skip[] = (string) $tag->name; } } } $fields = array(); foreach ( $posted as $name => $value ) { if ( in_array( (string) $name, $skip, true ) || 0 === strpos( (string) $name, '_' ) ) { continue; } a2leads_add_field( $fields, (string) $name, $value ); } $title = is_object( $contact_form ) && method_exists( $contact_form, 'title' ) ? (string) $contact_form->title() : ''; $page = method_exists( $submission, 'get_meta' ) ? (string) $submission->get_meta( 'url' ) : ''; a2leads_send( 'cf7', $title, $fields, $page ? esc_url_raw( $page ) : '' ); } catch ( \Throwable $e ) { return; } } /** * Remembers which CF7 form we already sent, so mail_sent + mail_failed can't double-send. * * @param object $contact_form WPCF7_ContactForm. * @return void */ function a2leads_cf7_once( $contact_form ) { static $done = false; if ( $done ) { return; } $done = true; a2leads_cf7( $contact_form ); } /** * WPForms. * * @param array $fields Processed fields. * @param array $entry Raw entry. * @param array $form_data Form settings. * @param int $entry_id Entry id. * @return void */ function a2leads_wpforms( $fields, $entry, $form_data, $entry_id = 0 ) { try { if ( ! a2leads_enabled( 'wpforms' ) ) { return; } $skip_types = array( 'password', 'file-upload', 'captcha', 'hcaptcha', 'recaptcha', 'turnstile', 'html', 'divider', 'pagebreak', 'content', 'entry-preview', 'credit-card', 'stripe-credit-card', 'square', 'authorize_net', 'paypal-commerce' ); $out = array(); foreach ( (array) $fields as $field ) { if ( ! is_array( $field ) ) { continue; } $type = isset( $field['type'] ) ? (string) $field['type'] : ''; if ( in_array( $type, $skip_types, true ) ) { continue; } $label = isset( $field['name'] ) && '' !== $field['name'] ? (string) $field['name'] : 'Field ' . ( isset( $field['id'] ) ? $field['id'] : '' ); if ( 'name' === $type && ( ! empty( $field['first'] ) || ! empty( $field['last'] ) ) ) { a2leads_add_field( $out, 'First name', isset( $field['first'] ) ? $field['first'] : '' ); a2leads_add_field( $out, 'Last name', isset( $field['last'] ) ? $field['last'] : '' ); continue; } a2leads_add_field( $out, $label, isset( $field['value'] ) ? $field['value'] : '' ); } $title = isset( $form_data['settings']['form_title'] ) ? (string) $form_data['settings']['form_title'] : ''; a2leads_send( 'wpforms', $title, $out ); } catch ( \Throwable $e ) { return; } } /** * Elementor Pro Forms. * * @param object $record ElementorPro\Modules\Forms\Classes\Form_Record. * @param object $handler Ajax handler. * @return void */ function a2leads_elementor( $record, $handler = null ) { try { if ( ! a2leads_enabled( 'elementor' ) || ! is_object( $record ) || ! method_exists( $record, 'get' ) ) { return; } $skip_types = array( 'upload', 'password', 'recaptcha', 'recaptcha_v3', 'honeypot', 'html', 'step', 'acceptance_hidden' ); $out = array(); foreach ( (array) $record->get( 'fields' ) as $id => $field ) { if ( ! is_array( $field ) ) { continue; } $type = isset( $field['type'] ) ? (string) $field['type'] : ''; if ( in_array( $type, $skip_types, true ) ) { continue; } $label = ! empty( $field['title'] ) ? (string) $field['title'] : ( ! empty( $field['id'] ) ? (string) $field['id'] : (string) $id ); if ( 'acceptance' === $type ) { $label = $label ? $label : 'Consent'; } a2leads_add_field( $out, $label, isset( $field['value'] ) ? $field['value'] : '' ); } $title = method_exists( $record, 'get_form_settings' ) ? (string) $record->get_form_settings( 'form_name' ) : ''; $meta = (array) $record->get( 'meta' ); $page = isset( $meta['page_url']['value'] ) ? esc_url_raw( (string) $meta['page_url']['value'] ) : ''; a2leads_send( 'elementor', $title, $out, $page ); } catch ( \Throwable $e ) { return; } } /** * Gravity Forms. * * @param array $entry Entry values keyed by field/input id. * @param array $form Form definition. * @return void */ function a2leads_gravity( $entry, $form ) { try { if ( ! a2leads_enabled( 'gravity' ) || ! is_array( $entry ) || ! is_array( $form ) ) { return; } $skip_types = array( 'password', 'fileupload', 'captcha', 'html', 'section', 'page', 'creditcard', 'stripe_creditcard', 'square_creditcard', 'post_image' ); $out = array(); foreach ( (array) ( isset( $form['fields'] ) ? $form['fields'] : array() ) as $field ) { if ( ! is_object( $field ) ) { continue; } $type = isset( $field->type ) ? (string) $field->type : ''; if ( in_array( $type, $skip_types, true ) ) { continue; } $label = ! empty( $field->label ) ? (string) $field->label : 'Field ' . $field->id; $inputs = isset( $field->inputs ) && is_array( $field->inputs ) ? $field->inputs : array(); if ( $inputs && in_array( $type, array( 'name', 'address' ), true ) ) { // Multi-part fields: "Name (First)", "Name (Last)", "Address (City)"… A2Leads maps these automatically. foreach ( $inputs as $input ) { if ( ! empty( $input['isHidden'] ) || ! isset( $input['id'] ) ) { continue; } $sub = ! empty( $input['customLabel'] ) ? (string) $input['customLabel'] : ( isset( $input['label'] ) ? (string) $input['label'] : '' ); a2leads_add_field( $out, $sub ? $label . ' (' . $sub . ')' : $label, isset( $entry[ (string) $input['id'] ] ) ? $entry[ (string) $input['id'] ] : '' ); } continue; } if ( $inputs ) { // Checkboxes, consent, email + confirm, etc. if ( method_exists( $field, 'get_value_export' ) ) { $value = $field->get_value_export( $entry, (string) $field->id, true ); } else { $parts = array(); foreach ( $inputs as $input ) { if ( isset( $input['id'] ) && ! empty( $entry[ (string) $input['id'] ] ) ) { $parts[] = $entry[ (string) $input['id'] ]; } } $value = 'email' === $type ? reset( $parts ) : $parts; } if ( 'email' === $type && is_string( $value ) && false !== strpos( $value, ',' ) ) { $value = trim( strtok( $value, ',' ) ); } a2leads_add_field( $out, $label, $value ); continue; } $value = isset( $entry[ (string) $field->id ] ) ? $entry[ (string) $field->id ] : ''; if ( is_string( $value ) && '' !== $value && '[' === substr( $value, 0, 1 ) ) { $decoded = json_decode( $value, true ); // Multi-select stores JSON. if ( is_array( $decoded ) ) { $value = $decoded; } } a2leads_add_field( $out, $label, $value ); } $title = isset( $form['title'] ) ? (string) $form['title'] : ''; $page = isset( $entry['source_url'] ) ? esc_url_raw( (string) $entry['source_url'] ) : ''; a2leads_send( 'gravity', $title, $out, $page ); } catch ( \Throwable $e ) { return; } } /** * Ninja Forms. * * @param array $form_data Submission data. * @return void */ function a2leads_ninja( $form_data ) { try { if ( ! a2leads_enabled( 'ninja' ) || ! is_array( $form_data ) ) { return; } $skip_types = array( 'submit', 'html', 'hr', 'recaptcha', 'recaptcha_v3', 'password', 'passwordconfirm', 'file_upload', 'spam', 'creditcard', 'creditcardnumber', 'creditcardcvc', 'creditcardexpiration', 'creditcardzip', 'creditcardfullname' ); $out = array(); foreach ( (array) ( isset( $form_data['fields'] ) ? $form_data['fields'] : array() ) as $field ) { if ( ! is_array( $field ) ) { continue; } $type = isset( $field['type'] ) ? (string) $field['type'] : ''; if ( in_array( $type, $skip_types, true ) ) { continue; } $label = ! empty( $field['label'] ) ? (string) $field['label'] : ( isset( $field['key'] ) ? (string) $field['key'] : '' ); a2leads_add_field( $out, $label, isset( $field['value'] ) ? $field['value'] : '' ); } $title = isset( $form_data['settings']['title'] ) ? (string) $form_data['settings']['title'] : ''; a2leads_send( 'ninja', $title, $out ); } catch ( \Throwable $e ) { return; } } add_action( 'wpcf7_mail_sent', 'a2leads_cf7_once', 20, 1 ); add_action( 'wpcf7_mail_failed', 'a2leads_cf7_once', 20, 1 ); // Still capture the lead if the site's own email fails. add_action( 'wpforms_process_complete', 'a2leads_wpforms', 20, 4 ); add_action( 'elementor_pro/forms/new_record', 'a2leads_elementor', 20, 2 ); add_action( 'gform_after_submission', 'a2leads_gravity', 20, 2 ); add_action( 'ninja_forms_after_submission', 'a2leads_ninja', 20, 1 ); /* ------------------------------------------------------------------------- * Optional JS snippet for any other form * ---------------------------------------------------------------------- */ /** * Works out the snippet's settings: where capture.js lives, the public key and which forms it watches. * * @return array{src:string,key:string,forms:string}|null Null when the snippet is switched off or not set up. */ function a2leads_snippet_config() { $settings = a2leads_settings(); if ( empty( $settings['snippet'] ) || is_admin() ) { return null; } $base = a2leads_api_base(); $key = a2leads_public_key(); if ( '' === $base || '' === $key ) { return null; } // Forms already sent by the webhook integrations are skipped, so nothing arrives twice. // (Ninja Forms submits by AJAX without a normal form submit, so the snippet never sees it.) $not = array( '#commentform' ); $map = array( 'cf7' => '.wpcf7-form', 'wpforms' => '.wpforms-form', 'elementor' => '.elementor-form', 'gravity' => '[id^="gform_"]', ); foreach ( $map as $integration => $selector ) { if ( a2leads_enabled( $integration ) ) { $not[] = $selector; } } $forms = 'form'; foreach ( $not as $selector ) { $forms .= ':not(' . $selector . ')'; } return array( 'src' => $base . '/capture.js', 'key' => $key, 'forms' => $forms, ); } /** * Adds the A2Leads capture snippet to the footer of the public pages. * * @return void */ function a2leads_enqueue_snippet() { $config = a2leads_snippet_config(); if ( null === $config ) { return; } wp_enqueue_script( 'a2leads-capture', $config['src'], array(), A2LEADS_VERSION, true ); } add_action( 'wp_enqueue_scripts', 'a2leads_enqueue_snippet', 99 ); /** * Gives the snippet's script tag its key, its form list and "async". * * @param string $tag The script tag WordPress is about to print. * @param string $handle The script's handle. * @return string */ function a2leads_snippet_tag( $tag, $handle ) { if ( 'a2leads-capture' !== $handle ) { return $tag; } $config = a2leads_snippet_config(); if ( null === $config ) { return $tag; } $attrs = sprintf( 'async data-key="%1$s" data-forms="%2$s" ', esc_attr( $config['key'] ), esc_attr( $config['forms'] ) ); return preg_replace( '/ 'array', 'sanitize_callback' => 'a2leads_sanitize_settings', 'default' => a2leads_defaults(), ) ); } add_action( 'admin_init', 'a2leads_register_settings' ); /** * Sanitises the settings form. An empty secret box keeps the saved secret. * * @param mixed $input Raw input. * @return array */ function a2leads_sanitize_settings( $input ) { $old = a2leads_settings(); $input = is_array( $input ) ? $input : array(); $out = a2leads_defaults(); $url = isset( $input['webhook_url'] ) ? esc_url_raw( trim( (string) $input['webhook_url'] ), array( 'https', 'http' ) ) : ''; if ( $url && ! preg_match( '#/api/v1/hooks/[A-Za-z0-9_\-]+#', $url ) ) { add_settings_error( A2LEADS_OPTION, 'a2leads_url', __( 'That doesn’t look like an A2Leads webhook URL. It should end in /api/v1/hooks/pk_… – copy it from “Connect your website” in A2Leads.', 'a2leads' ) ); } $out['webhook_url'] = $url; $secret = isset( $input['secret'] ) ? trim( sanitize_text_field( (string) $input['secret'] ) ) : ''; if ( ! empty( $input['clear_secret'] ) ) { $out['secret'] = ''; } else { $out['secret'] = '' !== $secret ? $secret : (string) $old['secret']; } $valid = array_keys( a2leads_integrations() ); $chosen = isset( $input['integrations'] ) && is_array( $input['integrations'] ) ? array_map( 'sanitize_key', $input['integrations'] ) : array(); $out['integrations'] = array_values( array_intersect( $valid, $chosen ) ); $out['snippet'] = empty( $input['snippet'] ) ? 0 : 1; $out['public_key'] = isset( $input['public_key'] ) ? preg_replace( '/[^A-Za-z0-9_\-]/', '', (string) $input['public_key'] ) : ''; $out['blocking'] = empty( $input['blocking'] ) ? 0 : 1; return $out; } /** * Masked secret for display: "whsec_••••••••3f9a". * * @param string $secret Secret. * @return string */ function a2leads_mask_secret( $secret ) { $secret = (string) $secret; if ( '' === $secret ) { return ''; } $prefix = 0 === strpos( $secret, 'whsec_' ) ? 'whsec_' : ''; return $prefix . '••••••••' . substr( $secret, -4 ); } /** * Which supported form plugins are active on this site. * * @return array */ function a2leads_detected() { return array( 'cf7' => defined( 'WPCF7_VERSION' ) || class_exists( 'WPCF7_ContactForm' ), 'wpforms' => function_exists( 'wpforms' ) || defined( 'WPFORMS_VERSION' ), 'elementor' => defined( 'ELEMENTOR_PRO_VERSION' ), 'gravity' => class_exists( 'GFForms' ), 'ninja' => class_exists( 'Ninja_Forms' ), ); } /** * Renders the settings page. * * @return void */ function a2leads_render_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = a2leads_settings(); $detected = a2leads_detected(); $log = get_option( A2LEADS_LOG_OPTION, array() ); $log = is_array( $log ) ? $log : array(); $test = get_transient( 'a2leads_test_' . get_current_user_id() ); if ( false !== $test ) { delete_transient( 'a2leads_test_' . get_current_user_id() ); } $name = A2LEADS_OPTION; ?>


'Test Lead', 'Email' => 'test+' . time() . '@example.com', 'Phone' => '01632 960000', 'Company' => get_bloginfo( 'name' ), 'Message' => __( 'This is a test enquiry sent from the A2Leads WordPress plugin. You can delete it.', 'a2leads' ), ); $result = a2leads_send( 'test', __( 'Test lead', 'a2leads' ), $fields, home_url( '/' ), true ); set_transient( 'a2leads_test_' . get_current_user_id(), $result, 5 * MINUTE_IN_SECONDS ); wp_safe_redirect( admin_url( 'options-general.php?page=a2leads' ) ); exit; } add_action( 'admin_post_a2leads_test', 'a2leads_handle_test' ); /** * "Settings" link on the Plugins screen. * * @param array $links Action links. * @return array */ function a2leads_action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'a2leads' ) . '' ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'a2leads_action_links' );