Making user profile without plugin
-
hello
I need a code (not a plugin) to show profile fields in a public pages. for example:
example.com/users/user_name
and then I want to see this user information such as email or first name.
is it possible?
Viewing 1 replies (of 1 total)
-
<strong>Add this code in your template</strong> if($_POST['post_submit']=='Sumbit'){ $user_login = $_POST['user_login']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $nickname = $_POST['nickname']; $email = $_POST['email']; $url = $_POST['url']; $description = $_POST['description']; $userdata = array( 'user_login' => $user_login, 'user_email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'nickname' => $nickname, 'last_name' => $last_name, 'nickname' => $nickname, 'url' => $url, 'description' => $description, 'role' => 'subscriber' ); $user = wp_insert_user($userdata); } ?> <form class="mx-5 py-3" method="post" action="<?php echo home_url('/') ?>"> <input class="form-control" type="text" name="user_login" placeholder="Username"><br> <input class="form-control" type="text" name="first_name" placeholder="First Name"><br> <input class="form-control" type="text" name="last_name" placeholder="Last Name"><br> <input class="form-control" type="text" name="nickname" placeholder="Nickname"><br> <input class="form-control" type="text" name="email" placeholder="Email"><br> <input class="form-control" type="text" name="url" placeholder="Website"><br> <input class="form-control" type="text" name="description" placeholder="Biographical Info"><br> <input class="form-control" type="text" name="address" placeholder="Address"><br> <input class="form-control" type="text" name="city" placeholder="City"><br> <input class="form-control" type="text" name="postalcode" placeholder="Postal Code"><br> <input class="form-control" type="text" name="test1" placeholder="Test One"><br> <input class="form-control" type="text" name="test2" placeholder="Test Two"><br> <input class="form-control" type="text" name="test3" placeholder="Test Three"><br> <input class="form-control" type="text" name="test4" placeholder="Test Four"><br> <input class="form-control" type="text" name="test5" placeholder="Test Five"><br> <input class="form-control" type="text" name="test6" placeholder="Test Six"><br> <input class="form-control" type="text" name="test7" placeholder="Test Seven"><br> <input class="form-control" type="text" name="test8" placeholder="Test Eight"><br> <input class="form-control" type="text" name="test9" placeholder="Test Nine"><br> <input id="sumbit" class="btn-block btn-lg" type="submit" name="post_submit" value="Sumbit" /> </form> <strong>Add this code in your functions.php</strong> dd_action( 'show_user_profile', 'extra_user_profile_fields' ); add_action( 'edit_user_profile', 'extra_user_profile_fields' ); function extra_user_profile_fields( $user ) { ?> <h3><?php _e("Extra profile information", "blank"); ?></h3> <table class="form-table"> <tr> <th><label for="address"><?php _e("Address"); ?></label></th> <td> <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your address."); ?></span> </td> </tr> <tr> <th><label for="city"><?php _e("City"); ?></label></th> <td> <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your city."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th> <td> <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test One"); ?></label></th> <td> <input type="text" name="test1" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test1', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test One"); ?></label></th> <td> <input type="text" name="test2" id="test2" value="<?php echo esc_attr( get_the_author_meta( 'test2', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test Three"); ?></label></th> <td> <input type="text" name="test3" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test3', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test Four"); ?></label></th> <td> <input type="text" name="test4" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test4', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test Five"); ?></label></th> <td> <input type="text" name="test5" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test5', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test six"); ?></label></th> <td> <input type="text" name="test6" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test6', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test seven"); ?></label></th> <td> <input type="text" name="test7" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test7', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test eight"); ?></label></th> <td> <input type="text" name="test8" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test8', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Test nine"); ?></label></th> <td> <input type="text" name="test9" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'test9', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></span> </td> </tr> </table> <?php } add_action( 'user_register', 'crf_user_register' ); function crf_user_register( $user_id ) { update_user_meta( $user_id, 'address', $_POST['address'] ); update_user_meta( $user_id, 'city', $_POST['city'] ); update_user_meta( $user_id, 'postalcode', $_POST['postalcode'] ); update_user_meta( $user_id, 'address', $_POST['address'] ); update_user_meta( $user_id, 'test1', $_POST['test1'] ); update_user_meta( $user_id, 'test2', $_POST['test2'] ); update_user_meta( $user_id, 'test3', $_POST['test3'] ); update_user_meta( $user_id, 'test4', $_POST['test4'] ); update_user_meta( $user_id, 'test5', $_POST['test5'] ); update_user_meta( $user_id, 'test6', $_POST['test6'] ); update_user_meta( $user_id, 'test7', $_POST['test7'] ); update_user_meta( $user_id, 'test8', $_POST['test8'] ); update_user_meta( $user_id, 'test9', $_POST['test9'] ); }
- This reply was modified 3 years, 3 months ago by yogeshyadav20.
- This reply was modified 3 years, 3 months ago by yogeshyadav20.
Viewing 1 replies (of 1 total)
- The topic ‘Making user profile without plugin’ is closed to new replies.