Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions RWListFieldCalculations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Gravity Forms List Field Calculations Add-On
Plugin URI:
Description: A simple add-on to enable the use of List fields in calculations.
Version: 0.6
Version: 0.7
Author: Richard Wawrzyniak
Author URI:

Expand All @@ -27,12 +27,12 @@

//------------------------------------------

if ( class_exists( 'GFForms' ) ) {
add_action( 'gform_loaded', function(){
GFForms::include_addon_framework();

class RWListFieldCalculations extends GFAddOn {

protected $_version = '0.6';
protected $_version = '0.7';
protected $_min_gravityforms_version = '2.3';
protected $_slug = 'RWListFieldCalculations';
protected $_path = 'RWListFieldCalculations/RWListFieldCalculations.php';
Expand All @@ -47,7 +47,7 @@ public function init() {
add_filter( 'gform_custom_merge_tags', array( $this, 'list_field_calculations_merge_tags' ), 10, 4 );
}

function has_list_field_merge_tag( $form ) {
public static function has_list_field_merge_tag( $form ) {
foreach ( $form['fields'] as $field ) {
if ( ! $field->has_calculation() ) {
continue;
Expand All @@ -62,7 +62,7 @@ function has_list_field_merge_tag( $form ) {
// get the $field object for the provided id
$field_id = $match[1];
$lfield = GFAPI::get_field( $form, $field_id );

// check that we have a field
if ( ! $lfield ) {
continue;
Expand All @@ -84,7 +84,7 @@ function has_list_field_merge_tag( $form ) {
return false;
}

function list_field_calculations_script( $form ) {
public function list_field_calculations_script( $form ) {

if ( self::has_list_field_merge_tag( $form ) ) {
wp_enqueue_script( 'LFCalc', $this->get_base_url() . '/js/LFCalc.js', array(
Expand All @@ -95,7 +95,7 @@ function list_field_calculations_script( $form ) {

}

function list_field_calculations( $formula, $field, $form, $lead ) {
public function list_field_calculations( $formula, $field, $form, $lead ) {

// {List:1.3} - {Label:ID.Column} - sum column values
// {List:1} - {Label:ID} - count rows
Expand All @@ -112,7 +112,7 @@ function list_field_calculations( $formula, $field, $form, $lead ) {
// get the $field object for the provided id
$field_id = $match[1];
$field = GFAPI::get_field( $form, $field_id );

// check that we have a field
if ( ! $field ) {
continue;
Expand Down Expand Up @@ -163,7 +163,7 @@ function list_field_calculations( $formula, $field, $form, $lead ) {
return $formula;
}

function list_field_calculations_merge_tags( $merge_tags, $form_id, $fields, $element_id ) {
public function list_field_calculations_merge_tags( $merge_tags, $form_id, $fields, $element_id ) {

// check the type of merge tag dropdown
if ( $element_id != 'field_calculation_formula' ) {
Expand Down Expand Up @@ -206,4 +206,4 @@ function list_field_calculations_merge_tags( $merge_tags, $form_id, $fields, $el
}

new RWListFieldCalculations();
}
}, 10, 0 );
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-------------------------------------------------------------------------------------------------------------------
Version 0.7
- Use gravity form hook gform_loaded for loading the addon

-------------------------------------------------------------------------------------------------------------------
Version 0.6
- Updated min Gravity Forms version to 2.3
Expand Down