Advertisement
designbymerovingi

Points for Gravity Form submissions

Jan 22nd, 2015
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. add_action( 'gform_after_submission', 'mycred_pro_gform_points', 10, 2 );
  2. function mycred_pro_gform_points( $lead, $form ) {
  3.  
  4.     // Login is required
  5.     if ( ! is_user_logged_in() || ! isset( $lead['form_id'] ) || ! function_exists( 'mycred' ) ) return;
  6.  
  7.     // Prep
  8.     $user_id = absint( $lead['created_by'] );
  9.     $form_id = absint( $lead['form_id'] );
  10.     $mycred  = mycred();
  11.  
  12.     $amount = 0;
  13.     $entry = '';
  14.     if ( isset( $form['fields'] ) && ! empty( $form['fields'] ) ) {
  15.         foreach ( (array) $form['fields'] as $field ) {
  16.  
  17.             // Amount override
  18.             if ( $field['label'] == 'mycred_amount' ) {
  19.                 $amount = $mycred->number( $field['Value'] );
  20.             }
  21.  
  22.             // Entry override
  23.             if ( $field['label'] == 'mycred_entry' ) {
  24.                 $entry = sanitize_text_field( $field['Value'] );
  25.             }
  26.  
  27.         }
  28.     }
  29.  
  30.     if ( $amount != 0 && $entry != '' ) {
  31.        
  32.         if ( ! $mycred->exclude_user( $user_id ) )
  33.             $mycred->add_creds(
  34.                 'gravity_form',
  35.                 $user_id,
  36.                 $amount,
  37.                 $entry
  38.             );
  39.  
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement