• Resolved guytimes

    (@guytimes)


    I am using “ultimate member” for wordpress, and I have a field called agreement_signed. When a logged in user signs an agreement, I want to update the field to “YES”. After they sign, i direct them to: …. website .com/user/username/?sign=yes

    I am not a php coder and I struggled with this for hours and came up with this, which works MOST of the time. For whatever reason, it fails about 25% of the time and I don’t know why. It’s ok if you laugh at my code ??

    What am I doing wrong?
    Thanks,
    Tom

    function check_agreement_signed () {

    $check = $_REQUEST[‘sign’];
    $user_id = get_current_user_id() ;
    $agreement = ‘YES’;
    if(!empty($check) && $check==’yes’) {
    $result = update_user_meta( $user_id, ‘agreement_signed’, $agreement);
    echo “<h2><center>Thank you for signing your Adoption Agreement. A copy was emailed to you.</center></h2>”;
    }
    }
    add_filter( ‘um_before_form’, ‘check_agreement_signed’, 1, 2 );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @guytimes

    You need to use add_action function.

    Please do try this code snippet:

    function check_agreement_signed () {
    
         $check = $_REQUEST[‘sign’];
         $user_id = get_current_user_id() ;
         $agreement = ‘YES’;
         if( ! empty( $check ) && $check== ’yes’ ) {
           $result = update_user_meta( $user_id, ‘agreement_signed’, $agreement);
           echo “<h2><center>Thank you for signing your Adoption Agreement. A copy was emailed to you.</center></h2>”;
         }
    }
    add_action( ‘um_before_form’, ‘check_agreement_signed’, 1, 2 );
    

    Regards,

    Thread Starter guytimes

    (@guytimes)

    Thank you I will try that. What is the difference between add_filter and add_action?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @guytimes

    There’s no um_before_form filter hook that’s declared in the UM plugin.

    Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘update field with code’ is closed to new replies.