1

I am saving some additional fields using default wordpress user page in admin panel.

The function save_extra_profile_fields() used to save additional fields along with original user's fields.

(In short: i am modifying the user editing page in wordpress adminpanel)

In this function now i've some custom conditions/checks.

Some example code here :

//function to embed form fields
    function hf_show_extra_profile_fields( $user ) {
    <tr>

                        <th><label for="_user_status">User Status</label></th> 
                        <td class="user-status">

                        <?php $userstatus= esc_attr( get_the_author_meta( 'userstatus', $user->ID ) ); ?> 
                        <input type="radio" name="_user_status" value="active" <?php if ($userstatus == 'active') echo 'checked="checked"'; ?> id="active"> <label for="active">ACTIVE</label> 



                        <input type="radio" name="_user_status" value="inactive" <?php if ($userstatus == 'inactive') echo 'checked="checked"'; ?> id="inactive"> <label for="inactive">DEACTIVATE</label> 


                        </td>

                        </tr>
    }
    //function to get and save the data
        function hf_save_extra_profile_fields( $user_id ) {
        if( empty($_POST['_user_status']) || $_POST['_user_status']=='inactive'){ 
                    return false;
                     //HERE THE ALERT SHOULD BE PROMPT AND SAVING DATA SHOULD BE ABORT
                    }
        }


        add_action( 'personal_options_update', 'hf_save_extra_profile_fields' ); 
        add_action( 'edit_user_profile_update', 'hf_save_extra_profile_fields' );

Question: I want to abort all the functionality and show an alert box when it comes in to the specific condition.

Note: I don't want to use wp_die() method, because it takes user to next empty page and upon coming back the data gets clear into the fields. Into code above i just copied one field as an example. There are several fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.