Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'gform_after_submission', 'mycred_pro_gform_points', 10, 2 );
- function mycred_pro_gform_points( $lead, $form ) {
- // Login is required
- if ( ! is_user_logged_in() || ! isset( $lead['form_id'] ) || ! function_exists( 'mycred' ) ) return;
- // Prep
- $user_id = absint( $lead['created_by'] );
- $form_id = absint( $lead['form_id'] );
- $mycred = mycred();
- $amount = 0;
- $entry = '';
- if ( isset( $form['fields'] ) && ! empty( $form['fields'] ) ) {
- foreach ( (array) $form['fields'] as $field ) {
- // Amount override
- if ( $field['label'] == 'mycred_amount' ) {
- $amount = $mycred->number( $field['Value'] );
- }
- // Entry override
- if ( $field['label'] == 'mycred_entry' ) {
- $entry = sanitize_text_field( $field['Value'] );
- }
- }
- }
- if ( $amount != 0 && $entry != '' ) {
- if ( ! $mycred->exclude_user( $user_id ) )
- $mycred->add_creds(
- 'gravity_form',
- $user_id,
- $amount,
- $entry
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement