Categories

Monday, December 23, 2024
#919814419350 therichposts@gmail.com
Wordpress Cheat Codes

WordPress cheat code to update User details from frontend

How to add custom meta title and meta description in Wordpress?

Hello to all, welcome to therichpost.com. In this post, I will tell you, WordPress cheat code to update User details from frontend.

Today again, I am coming with WordPress cheat code to update User details from frontend and this is very easy and useful.

I am sharing these codes because, these codes are very simple but sometime simple thing takes very much time so.

With this post code, I am making frontend form and with that form, I will update login user details. I will hope this will be useful.

Here is the code for wordpress cheat code to update user details from frontend and please use this carefully into your WordPress theme’s template file:


<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
global $current_user; // Get login user data
get_currentuserinfo();
$args = array(
    'ID'         => $current_user->id,
    'user_email' => esc_attr( $_POST['user_email'] ),
    'user_nicename' => esc_attr( $_POST['user_nicename'] )
);
wp_update_user( $args ); // Update user data
}?>
<!-- Content -->
<div class="content">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card">
                    <div class="card-header">
                        <div class="crd-flx">
                            <h2 class="card-title">My Profile</h2>
                        </div>
                    </div>
                    <div class="card-body">
                        <form class="My-profile" id="new_post" name="new_post" method="post" action="">
                            <div class="row">
                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                    <div class="form-group">
                                        <label>Name</label>
                                        <input type='text' class="form-control" name="user_nicename" required value="<?php echo $current_user->user_nicename; ?>" />
                                    </div>
                                    <div class="form-group">
                                        <label>Username</label>
                    
                    <!--This is disabled because we can not change the Username-->
                    
                                        <input disabled="disabled" type='text' class="form-control" name="username" value="<?php echo $current_user->user_login; ?>" />
                                    </div>
                                    <div class="form-group">
                                        <label>Email</label>
                                        <input type='email' class="form-control" name="user_email" required value="<?php echo $current_user->user_email; ?>" />
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                                            <div class="form-group">
                                                <input type="submit" value="Save" class="btn btn-custom login-btn pull-right"/>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <input type="hidden" name="action" value="new_post" />
                            <?php wp_nonce_field( 'new-post' ); ?>
                        </form>
                    </div>
                </div>
            </div>
        </div>
</div>
<!-- /.content -->

 

This is it and if you have any query related to this post then please do comment.

Harjas,

Thank you

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.