Use the value of a field to adjust the user's balance (myCRED and Gravity Forms)
-
Hello!
I would like to use the value entered for admin in a text field in a form editor to adjust the users balance.To apply custom points of custom types of points, I thought of using CSS class to distinguish fields which adds points to a particular type of points.
Please do not laugh, this is a bit of what I am researching to create this plugin:
<?php add_action( 'gform_after_update_entry', array( $this, 'adjust_amount_field' ), 10, 2 ); function adjust_amount_field( $form, $lead, $field, $value ) { // Requiremetns if ( $form_id = $entry['id'] || ! current_user_can( 'edit_users' ) ) return; $field_class = explode(' ', $field['cssClass']); $field_class_matches = array_intersect($field_class, array('points-type-A')); $field_class = explode(' ', $field['cssClass']); $field_class_matches = array_intersect($field_class, array('points-type-B')); // Get the user object $user = get_userdata( absint( $lead['created_by'] ) ); if ( ! isset( $user->ID ) ) return; // Get Field Value add_filter("gform_get_field_value", "get_field_value", 10, 3); function get_field_value($value, $lead, $field){ //Aply Field Value in Amount adjust //????????????????????????????????? if(is_array($value)){ foreach($value as $key => $input_value){ $value[$key] = mycred_amount($input_value); } return $amount = sanitize_text_field( $value ); } // mycred = Amount override if ( $field['label'] || ! $field_class['points-type-A'] == 'points-type-A_amount' ) { $amount = sanitize_text_field( $field = $value ); } if ( $field['label'] || ! $field_class['points-type-B'] == 'points-type-B_amount' ) { $amount = sanitize_text_field( $field = $value ); } // Override entry at Lead ID if ( $field['label'] == 'mycred_entry' ) { $entry = sanitize_text_field( $field = $lead['id'] ); } } } ?>
The idea is:
1 – Admin creates text field visible only to admins (“Points”). Field with class “points-type-A” add points to “points-type-A” custom point type;
2 – While reading a message, admin can adjust the score of the user filling out the value in the text field “Points” and updating the entry;
Images to illustrate,
A – Create form:
https://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-00.57.54.pngB- Adjust Balance:
https://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-00.57.54.pngThanks since right now!
- The topic ‘Use the value of a field to adjust the user's balance (myCRED and Gravity Forms)’ is closed to new replies.