• Resolved blisshome

    (@blisshome)


    I’ve added the following code to the bottom of html-forms.php but it fails to make the change in role desired. Am I putting this code in the right place? The form itself is located on the request page: https://memremix.com/request/.

    //change subscriber to contributor on successful form submission
    add_action( ‘hf_form_success’, function( $submission, $form ) {
    if ( ! is_page( ‘request’ ) ) return;
    $user_id = get_current_user_id();
    $user = get_userdata($user_id);
    $user_roles = $user->roles;
    if (in_array(“subscriber”, $user_roles)){
    $user->set_role(“contributor”);
    }
    }, 10, 2);

    Thank you for your assistance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Custom code can be added to your child theme functions.php file, or via a plugin like https://ww.wp.xz.cn/plugins/code-snippets/

    Hope that helps. If you have any questions, please let me know!

    Thread Starter blisshome

    (@blisshome)

    Thanks, Lap. I’ll try code-snippets again. Didn’t work before but I’ll re-examine. Child theme is plan B.

    Appreciate your plugin.

    Thread Starter blisshome

    (@blisshome)

    Got it working in Code Snippets. It seems that the third line in my code

    if ( ! is_page( ‘request’ ) ) return;

    breaks the snippet, no matter what way I try to restrict the code to run on just my “request” form page.

    Fortunately only pages with your plugin’s forms respond to your hf_form_success hook (as one would expect). I do have your forms on more than one page on my site, but your hidden input field (_hf_form_id) allowed me to restrict the code to just the one page:

    if ($_POST[‘_hf_form_id’] == 705) {…

    Thanks for the help!

    Sorry or the very very late reply, somehow your message slipped through.

    Let me know if you still need help with this.

    Double check that you always use ‘straight’ (not curly) quotation marks.

    Hope that helps. If you have any questions, please let me know!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘hf_form_success hook’ is closed to new replies.