1

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.

6
  • 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, 2018 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";? Jun 29, 2018 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, 2018 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, 2018 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! Jul 3, 2018 at 17:49

1 Answer 1

2

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 https://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: Debug output during filter execution doesn't work

This might also help to understand https://stackoverflow.com/questions/7878279/… and for plugin specifc logging How to log plugin errors to plugin error_log file

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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