• Hi everyone,

    I have this code below. It’s for user role change. If status is complete, I give new role ‘contributor’. If status is ‘failed’, I give new role ‘subscriber’. How do I insert ‘frm_payment_status_failed’ and make $new_ role=’subscriber’ into this chunk of this code?

    add_action( ‘frm_payment_status_complete’, ‘frm_change_the_role’ );
    function frm_change_the_role( $atts ) {
    $new_role = ‘contributor’;
    $entry = isset( $atts[‘entry’] ) ? $atts[‘entry’] : $atts[‘payment’]->item_id;
    if ( is_numeric( $entry ) ) {
    $entry = FrmEntry::getOne( $entry );
    }

    $user_id = $entry->user_id;
    if ( ! empty( $user_id ) ) {
    $user = get_userdata($user_id);
    if ( ! $user ) {
    return; //don’t continue if user doesn’t exist
    }

    $updated_user = (array) $user;

    // Get the highest/primary role for this user
    $user_roles = $user->roles;
    $user_role = array_shift( $user_roles );
    if ( $user_role == ‘administrator’ ) {
    return; //make sure we don’t downgrade any admins
    }

    $updated_user[‘role’] = $new_role;

    wp_update_user( $updated_user );
    }
    }

    https://wordpress.org/plugins/formidable/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to add codes’ is closed to new replies.