Skip to content

Instantly share code, notes, and snippets.

@EddyRespondek
Last active August 29, 2015 14:07
Show Gist options
  • Save EddyRespondek/f7df2d46d0d59c4d9886 to your computer and use it in GitHub Desktop.
Save EddyRespondek/f7df2d46d0d59c4d9886 to your computer and use it in GitHub Desktop.
<?php
if ( !class_exists( 'GFForms' ) || !defined( 'WPINC' ) ) {
return;
}
class BTFunds {
/**
* Dashboard-only initialization.
*/
public static function admin_init() {
// ...
}
/**
* Initialization.
*/
public static function init() {
// ...
add_filter( 'gform_field_value_paymentoption', array( __CLASS__, 'populate_paymentoption' ) );
// ...
}
public static function populate_paymentoption( $value ) {
if ( !isset( $_POST["input_264"] ) ) {
return;
}
// get selected fund options
$funds = self::unserialize( $_POST["input_264"] );
$reinvest = 0;
$paytobank = 0;
foreach ( $funds as $fund ) {
if ( isset( $fund['selected'] ) && isset( $fund['reinvest'] ) && isset( $fund['pay_to_bank'] ) && $fund['selected'] == 'true' ) {
if ( $fund['reinvest'] == 'true' ) {
$reinvest++;
}
if ( $fund['pay_to_bank'] == 'true' ) {
$paytobank++;
}
}
}
if ( $reinvest > 0 ) { $value = 'reinvest'; }
if ( $paytobank > 0 ) { $value = 'paytobank'; }
if ( $reinvest > 0 && $paytobank > 0 ) { $value = 'both'; }
return $value;
}
}
add_action( 'admin_init', array( 'BTFunds', 'admin_init' ) );
add_action( 'init', array( 'BTFunds', 'init' ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment