Plugin Directory

Changeset 2084732


Ignore:
Timestamp:
05/09/2019 03:42:59 PM (7 years ago)
Author:
travisnorthcutt
Message:

Version 1.1.0

Location:
convertkit-gravity-forms
Files:
16 added
5 edited

Legend:

Unmodified
Added
Removed
  • convertkit-gravity-forms/trunk/components/gravityforms/class-gf-convertkit.php

    r1840318 r2084732  
    77GFForms::include_feed_addon_framework();
    88
     9/**
     10 * Class GFConvertKit
     11 */
    912class GFConvertKit extends GFFeedAddOn {
    1013
     
    124127                            'name'       => 'n',
    125128                            'label'      => __( 'Name' ),
    126                             'required'   => true,
     129                            'required'   => false,
    127130                            'field_type' => '',
    128131                        ),
     
    131134                ),
    132135                array(
    133                     'name' => 'convertkit_custom_fields',
    134                     'label' => '',
    135                     'type' => 'dynamic_field_map',
    136                     'field_map' => $this->get_custom_fields(),
    137                     'disable_custom' => true,
    138                 ),
    139                 array(
    140136                    'name'    => 'conditions',
    141137                    'label'   => __( 'Conditional Logic' ),
     
    146142        );
    147143
     144        $base_fields = $this->maybe_add_custom_field_mapping( $base_fields );
     145
    148146        return array( $base_fields );
    149147    }
    150148
    151149    /**
     150     * If the connected account returns custom fields, add custom field mapping to the feed settings
     151     * Otherwise, don't insert custom field mapping
     152     *
     153     * @param array $base_fields
     154     *
     155     * @return array
     156     */
     157    public function maybe_add_custom_field_mapping( $base_fields ) {
     158        $custom_mapping = array(
     159            'name'           => 'convertkit_custom_fields',
     160            'label'          => '',
     161            'type'           => 'dynamic_field_map',
     162            'field_map'      => $this->get_custom_fields(),
     163            'disable_custom' => true,
     164        );
     165
     166        if ( $this->get_custom_fields() ) {
     167            array_splice( $base_fields['fields'], 3, 0, array( $custom_mapping ) );
     168        }
     169
     170        return $base_fields;
     171    }
     172
     173    /**
    152174     * Get ConvertKit Custom Fields from the API to be used for the dynamic field map
    153175     *
     
    156178    public function get_custom_fields() {
    157179
    158         $path = 'custom_fields';
    159         $query_args = array();
     180        $path         = 'custom_fields';
     181        $query_args   = array();
    160182        $request_body = null;
    161183        $request_args = array();
    162         $fields = array();
     184        $fields       = array();
    163185
    164186        $response = ckgf_convertkit_api_request( $path, $query_args, $request_body, $request_args );
    165         $custom_fields = $response['custom_fields'];
    166 
    167         if ( $custom_fields && ! is_wp_error( $custom_fields ) ) {
     187
     188        // We don't want to do anything if there's an error...
     189        if ( is_wp_error( $response ) ) {
     190            return $fields;
     191        }
     192
     193        // Or if the `custom_fields` field is empty
     194        if ( empty( $response['custom_fields'] ) ) {
     195            return $fields;
     196        }
     197
     198        $fields[] = array(
     199            'label' => __( 'Choose a ConvertKit Field', 'convertkit' ),
     200        );
     201
     202        foreach ( $response['custom_fields'] as $field ) {
    168203
    169204            $fields[] = array(
    170                 'label'     => __( 'Choose a ConvertKit Field', 'convertkit' ),
    171                 );
    172 
    173             foreach ( $custom_fields as $field ) {
    174 
    175                 $fields[] = array(
    176                         'value'     => $field['key'],
    177                         'label'     => $field['label'],
    178                 );
    179             }
     205                'value' => $field['key'],
     206                'label' => $field['label'],
     207            );
    180208        }
    181209
     
    251279
    252280        if ( is_array( $forms ) && isset( $forms[ $form_id ] ) ) {
    253             $form = $forms[ $form_id ];
    254 
    255             return sprintf( '<a href="%s" target="_blank">%s</a>', esc_attr( esc_url( $form['url'] ) ), esc_html( $forms[ $form_id ]['name'] ) );
     281            $form_url = sprintf( '%s/forms/designers/%s/edit', CKGF_APP_BASE_URL, $form_id );
     282
     283            return sprintf( '<a href="%s" target="_blank">%s</a>',
     284                            esc_attr( esc_url( $form_url ) ),
     285                            esc_html( $forms[ $form_id ]['name'] )
     286            );
    256287        } else {
    257288            return __( 'N/A' );
     
    278309
    279310        $fields = array();
     311
     312        $email = $this->get_field_value( $form, $entry, $field_map_e );
     313        $name  = $this->get_field_value( $form, $entry, $field_map_n );
    280314
    281315        $custom_fields = $this->get_custom_fields();
     
    289323        }
    290324
    291         ckgf_convertkit_api_add_email( $form_id, $entry[ $field_map_e ], $entry[ $field_map_n ], null, $fields );
     325        ckgf_convertkit_api_add_email( $form_id, $email, $name, null, $fields );
    292326    }
    293327
  • convertkit-gravity-forms/trunk/components/gravityforms/views/section.php

    r1406616 r2084732  
    44
    55<p>
    6     <?php printf(__('If you already have an account, <a href="%s" target="_blank">click here to retrieve your API Key</a>.'), esc_attr(esc_html('https://app.convertkit.com/account/edit'))); ?>
     6    <?php printf( __( 'If you already have an account, <a href="%s" target="_blank">click here to retrieve your API Key</a>.' ),
     7                  esc_attr( esc_html( CKGF_APP_BASE_URL . '/account/edit' ) ) ); ?>
    78</p>
  • convertkit-gravity-forms/trunk/convertkit.php

    r1840318 r2084732  
    33 * Plugin Name: Gravity Forms ConvertKit Add-On
    44 * Description: Integrates Gravity Forms with ConvertKit allowing form submissions to be automatically sent to your ConvertKit account.
    5  * Version: 1.0.4
     5 * Version: 1.1.0
    66 * Author: ConvertKit
    77 * Author URI: https://convertkit.com/
     
    3030
    3131if ( ! defined( 'CKGF_VERSION' ) ) {
    32     define( 'CKGF_VERSION', '1.0.4' );
     32    define( 'CKGF_VERSION', '1.1.0' );
    3333}
    3434
     
    4747if ( ! defined( 'CKGF_SHORT_TITLE' ) ) {
    4848    define( 'CKGF_SHORT_TITLE', 'ConvertKit' );
     49}
     50
     51if ( ! defined( 'CKGF_API_BASE_URL' ) ) {
     52    define( 'CKGF_API_BASE_URL', 'https://api.convertkit.com/v3' );
     53}
     54
     55if ( ! defined( 'CKGF_APP_BASE_URL' ) ) {
     56    define( 'CKGF_APP_BASE_URL', 'https://app.convertkit.com' );
    4957}
    5058
  • convertkit-gravity-forms/trunk/functions/convertkit.php

    r1840318 r2084732  
    1717function ckgf_convertkit_api_request( $path, $query_args = array(), $request_body = null, $request_args = array() ) {
    1818    $path        = ltrim( $path, '/' );
    19     $request_url = "https://api.convertkit.com/v3/{$path}";
     19    $request_url = sprintf( '%s/%s', CKGF_API_BASE_URL,  $path );
    2020
    2121    $request_args = array_merge(array(
  • convertkit-gravity-forms/trunk/readme.txt

    r1840318 r2084732  
    11=== Gravity Forms ConvertKit Add-On ===
    2 Contributors: nathanbarry, growdev
     2Contributors: nathanbarry, growdev, travisnorthcutt
    33Donate link: https://convertkit.com
    44Tags: email, marketing, embed form, convertkit, capture
    55Requires at least: 3.6
    6 Tested up to: 4.9.4
    7 Stable tag: 1.0.4
     6Tested up to: 5.2
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939== Changelog ==
    4040
     41### 1.1.0  2019-06-09
     42
     43* Correctly send full name to ConvertKit when used in a field mapping
     44* Only show field mappings for ConvertKit custom fields if they exist
     45* Output correct form URL on feed settings screen
     46* No longer requires a name field mapping, for email-only forms
     47
    4148### 1.0.4  2018-03-14
    4249
Note: See TracChangeset for help on using the changeset viewer.