Development of a personal WordPress account

Today I want to talk about how to solve the problem of creating a personal account in WordPress.. This tutorial is not ideal., but for example, I think it will be enough for you, to understand, how to do it right and what is needed for this.

The first thing we need, is to learn how to output data, which are stored in the admin panel, and it's very easy to do, like everything that is done in the wonderful content management system WordPress.

First you need in the theme folder /wp-content/themes/{theme folder}/ create template file, let's call it page-user-profile.php. For the template to work, it is necessary to create the basic structure correctly. I suggest to create the following structure at the very top of the created file:

Below comment /* Get user info. */ add output code:

After adding, save the file. We go to Admin Panel -> Creating a new page – > Choosing a template for data output.

создаем профиль пользователя wordpress

 

After displaying the template selection and publishing the page, click on the button [View changes]. You will see something like the following on your screen::

View user profile on frontendExcellent, now we have the data displayed and I think we should take a closer look at what exactly we did and what functions were used.

get_avatar( $current_user->ID, 60 ) – Displays the current user's avatar in size 60 on 60 pixels. If you, like me, have an avatar just flattened, then this can be easily fixed by simply overriding styles for a given image of the following kind in theme styles, just add .avatar img{ width: auto !important; }.

Proportional avatar on WordPress user side

Where did I get these stocks and other similar:

$current_user->user_firstname
$current_user->user_lastname

To make it clear, it will be enough to look at such a picture made by me by inspecting the administrator profile in the administrator panel.

Remove field from WordPress user profile

In the same way, you can display any field on the profile page. Most often, there is another situation when you need to add fields for the profile. And this moment is solved very simply, by simply adding code to the functions.php file, which is in the theme folder.

Excellent at this stage, we have configured the output of profile data, added new fields and removed some old ones.

Editing data on the user side

A little searching on the Internet, i found an interesting code structure, with which you can edit the data of the current user from the frontend. Let's create a new file for the future template and name it page-edit-user-profile.php.

In the file we create a structure already familiar to us, which will help the CMS see our template:

Add code below:

After pasting the code, as before, create a new page and assign a template to it Edit User Profile. Save the created page and click the button [View changes]:

Editing a WordPress User Profile

 

If everything is done correctly, you will see this form of editing, she should work. Displaying other fields from the admin panel is implemented in a similar way. Go to the panel and take the name of the field, which needs to be taken out.

Getting the Field Name to Edit WordPress

By analogy with the presented code, we display the author's metadata:
<?php the_author_meta( ‘first_name’, $current_user->ID ); ?>

One task left, this is the ability to edit the avatar for the author, but unfortunately WordPress is blocking attempts to edit the avatar from the user side, I'll be happy to hear your suggestions and ideas on how to work with the avatar, I would like to do everything right and work with the WordPress API.

Continuation of improvements to the article, wait, maybe even write a plugin on the theme to make it easier to work in new projects.


Buy WordPress hosting
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal