I created this selectbox inside my user-edit.php screen trough edit_user_profile hook.

<table class="form-table">
    <tbody>
        <tr>
            <th>
                <label for="select_membership">Plano de Membros</label>
            </th>
            <td>
                <select id="select_membership" name="select_membership"><option id="0">Sem plano</option>
                    <option value="1">Plano 1</option>
                    <option value="2" selected="selected">Plano 2</option>
                    <option value="3">Plano 3</option>
                    <option value="4">Plano 4</option>
                    <option value="5">Plano 5</option>
                    <option value="6">Plano 6</option>
                    <option value="7">Plano 7</option>
                </select>
            </td>       
        </tr> 
    </tbody>
</table>

Now I'm trying to get the selectbox value inside the user_register hook with this function:

public function update_membership_field( $user_id ){
        $membership_methods = new IMS_Membership_Method();
        $membership_methods->update_user_membership($user_id, $_POST['select_membership']);
    }

But nothing happens. How I can know if some data is passing through this function to check if something is happening? How to debug? I can't print nothing using this function.

  • Rafael, 'user_register' fires when a user registers, not when a user is edited or updated. Please also show the add_action code and when that is being added in case the problem lies there. Try something like codex.wordpress.org/edit_user_profile_update – anmari Jun 29 at 5:03
  • Hi anmari, thanks for your answer. It was the wrong hook i'm using...I change to edit_user_profile_update and know I can update my db with my methods. Thanks! Just to understand 100% this hook can not print anything? like echo "test";? – Rafael Figueiredo Jun 29 at 13:44
  • Hi Rafael, re output in hooks. It depends when/how the hook is being executed. The user profile ones are tricky because wp does stuff to prevent a double submission. One could use error_log to output where one can read it. More detail here: wordpress.stackexchange.com/questions/131212/… – anmari Jun 30 at 2:41
  • This might also help to understand stackoverflow.com/questions/7878279/… and for plugin specifc logging wordpress.stackexchange.com/questions/291108/… – anmari Jun 30 at 2:43
  • Hi Anmari, you helped me a lot! Now I can debug this function...I understand the idea through your links and now I'm redirecting the values to an email :) thanks! – Rafael Figueiredo Jul 3 at 17:49
up vote 2 down vote accepted

Rafael, (as requested, turning comments into answer)

'user_register' fires when a user registers, not when a user is edited or updated. Try something like codex.wordpress.org/edit_user_profile_update

Wrt output in hooks. It depends when/how the hook is being executed. The user profile ones are tricky because wp does stuff to prevent a double submission. One could use error_log to output where one can read it. More detail here: wordpress.stackexchange.com/questions/131212/…

This might also help to understand stackoverflow.com/questions/7878279/… and for plugin specifc logging wordpress.stackexchange.com/questions/291108/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.