Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save joshuaiz/b7cfbe4d56220555d397319413feae9e to your computer and use it in GitHub Desktop.

Select an option

Save joshuaiz/b7cfbe4d56220555d397319413feae9e to your computer and use it in GitHub Desktop.

Revisions

  1. joshuaiz revised this gist Aug 23, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions update-custom-user-field-with-donation-amount.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@

    function update_usar_sponsorship_amount($entry, $form) {
    // get required GF fields
    $team = rgar( $entry, "14"); // GF radio button field
    $team = rgar( $entry, "14"); // GF radio buttons (select Team to sponsor)
    $amount = rgar($entry, "2"); // donation amount

    // query through users
    @@ -12,7 +12,7 @@ function update_usar_sponsorship_amount($entry, $form) {
    foreach ( $users as $user ) {
    $userteam = $user->display_name;
    $currentAmount = $user->sponsorship_amount;
    // $amount = $currentAmount + $amount; // this doesn't work
    // $amount = $currentAmount + $amount; // this doesn't work because $amount isn't a number

    // if selected Team name matches user display name, update that user
    if ( $userteam == $team ) {
  2. joshuaiz revised this gist Aug 23, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions update-custom-user-field-with-donation-amount.php
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@

    function update_usar_sponsorship_amount($entry, $form) {
    // get required GF fields
    $team = rgar( $entry, "14");
    $amount = rgar($entry, "2");
    $team = rgar( $entry, "14"); // GF radio button field
    $amount = rgar($entry, "2"); // donation amount

    // query through users
    $users = get_users();
    @@ -13,6 +13,8 @@ function update_usar_sponsorship_amount($entry, $form) {
    $userteam = $user->display_name;
    $currentAmount = $user->sponsorship_amount;
    // $amount = $currentAmount + $amount; // this doesn't work

    // if selected Team name matches user display name, update that user
    if ( $userteam == $team ) {
    update_user_meta( $user->ID, 'sponsorship_amount', $amount );
    }
  3. joshuaiz revised this gist Aug 22, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion update-custom-user-field-with-donation-amount.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    add_action("gform_after_submission_6", "update_usar_sponsorship_amount", 10, 2);

    function update_usar_sponsorship_amount($entry, $form) {
    @@ -16,4 +17,6 @@ function update_usar_sponsorship_amount($entry, $form) {
    update_user_meta( $user->ID, 'sponsorship_amount', $amount );
    }
    }
    }
    }

    ?>
  4. joshuaiz created this gist Aug 22, 2017.
    19 changes: 19 additions & 0 deletions update-custom-user-field-with-donation-amount.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    add_action("gform_after_submission_6", "update_usar_sponsorship_amount", 10, 2);

    function update_usar_sponsorship_amount($entry, $form) {
    // get required GF fields
    $team = rgar( $entry, "14");
    $amount = rgar($entry, "2");

    // query through users
    $users = get_users();
    // loop through users
    foreach ( $users as $user ) {
    $userteam = $user->display_name;
    $currentAmount = $user->sponsorship_amount;
    // $amount = $currentAmount + $amount; // this doesn't work
    if ( $userteam == $team ) {
    update_user_meta( $user->ID, 'sponsorship_amount', $amount );
    }
    }
    }