Plugin Directory

Changeset 1949555


Ignore:
Timestamp:
10/01/2018 08:37:38 AM (8 years ago)
Author:
radishconcepts
Message:

Add options page to exclude specific variables.

Location:
gf-fields-persistence/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gf-fields-persistence/trunk/README.md

    r1918317 r1949555  
    1111## What fields does it support
    1212Currently only text and textarea fields are supported. We will add more fields along the way. Please also submit you requests as an issue!
    13 
     13 
    1414## Props
    1515Thanks to https://wisdmlabs.com/blog/gravity-forms-data-persistent-for-save-progress/ which gave us the initial idea, however we needed it to work with Varnish, so we created this Javascript-based version.
  • gf-fields-persistence/trunk/assets/js/gf-field-persistence.js

    r1918319 r1949555  
    2626            var dynamicName = $input.data('inputname');
    2727            var value = $input.val();
     28
     29            // Exclude defined variables.
     30            if( $.inArray( dynamicName, rcgfp_data.exclude_variables ) > -1 ) {
     31                return;
     32            }
    2833
    2934            dataToSave.push({
     
    5560
    5661            var field = cookieValue[item];
     62
     63            if( $.inArray( field.name, rcgfp_data.exclude_variables ) > -1 ) {
     64                continue;
     65            }
    5766
    5867            $('[data-inputname="' + field.name + '"]', $form).val(field.value);
  • gf-fields-persistence/trunk/classes/class-persistence.php

    r1918317 r1949555  
    66   
    77    private static $instance;
    8     private $_version = '1.0.2';
     8    private $_version = '1.0.3';
    99    private $load_js_in_footer = true;
     10   
     11    var $option_name = 'rcgfp_options';
    1012   
    1113    public function __construct() {
     
    1517    public function run() {
    1618        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
    17         add_action( 'init', array( $this, 'init_filters'), 99 );
     19        add_action( 'init', array( $this, 'init_filters' ), 99 );
    1820    }
    1921   
    2022    public function init_filters() {
    2123        add_filter( 'gform_field_content', function ( $content, $field ) {
    22             if( ! empty( $field->inputName ) ) {
     24            if ( ! empty( $field->inputName ) ) {
    2325                $current_name_attr = "name='input_" . $field->id . "'";
    24                 $new_attr = $current_name_attr . " data-inputname='" . esc_attr( $field->inputName ) . "'";
     26                $new_attr          = $current_name_attr . " data-inputname='" . esc_attr( $field->inputName ) . "'";
    2527               
    26                 $content           = str_replace( $current_name_attr, $new_attr, $content );
     28                $content = str_replace( $current_name_attr, $new_attr, $content );
    2729            }
    2830           
    2931            return $content;
    30         }, 99, 2);
     32        }, 99, 2 );
    3133    }
    3234   
     
    3537     */
    3638    public function enqueue_scripts() {
     39        // Get options to include in JS.
     40        $exclude_variables = Admin::get_option( 'exclude_variables' );
     41        if( ! empty( $exclude_variables ) ) {
     42            $exclude_variables = explode( ',', $exclude_variables );
     43            $exclude_variables = array_map( 'trim', $exclude_variables );
     44        }
     45       
    3746        wp_enqueue_script( 'rcgfp_script', RCGFP_PLUGIN_URI . 'assets/js/gf-field-persistence.js', array( 'jquery' ), $this->_version, $this->load_js_in_footer );
    3847        wp_localize_script( 'rcgfp_script', 'rcgfp_data', array(
    39             'ajax_url' => admin_url( 'admin-ajax.php' ),
    40             'sec_nonce' => wp_create_nonce('rcgfp_nonce' ),
     48            'exclude_variables' => $exclude_variables,
    4149        ) );
    4250    }
  • gf-fields-persistence/trunk/gravityforms-fields-persistence.php

    r1918317 r1949555  
    44Plugin URI: https://github.com/radishconcepts/gravityforms-field-persistence/
    55Description: Adds persistence to the Gravity Forms fields, so inputs will be saved in order to use it in other forms. This will improve user experience and boost your goals!
    6 Version: 1.0.2
     6Version: 1.0.3
    77Author: Radish Concepts <info@radishconcepts.com>
    88Author URI: https://www.radishconcepts.com
     
    1818// Fire those classes.
    1919new Radish\GravityForms\Persistence\Core();
     20new Radish\GravityForms\Persistence\Admin();
Note: See TracChangeset for help on using the changeset viewer.