Jump to content
Sign in to follow this  

Setup a User Public Name for display in Uikit 3 Site/Blog Profile

Recommended Posts

When you install PW for the first time choosing Uikit 3 Site/Blog Profile you feel good. You immediately understand it will take you sometime to fine tune your site, but you will not regret other popular CMS. 

After a short front end navigation with Uikit 3 Site/Blog Profile the theme looks simple but complete, so a great starting point. But suddenly your eyes will point at something strange … why my reserved user name which I took 10 minutes to invent … is right there in front of me: "Posted by mySecretUserName …" so that every visitor can see it ?! Uh!


Let's make a step back. When you first installed PW you were asked for a user name and password. I tend to avoid generic user names like "admin" … "administrator" … but I normally build a complex user name using lowercase/uppercase/digits. 

If you open the post, and look at the bottom you will see that your reserved user name not only is below the post title but also in the preset data of the comment form.


OK, keep calm! After a quick learning about Output Strategies and ... scrolling each file in /site/template you finally understand ... that what you are looking for is ukBlogPost() function in _uikit.php. Yes, this is the magic function that renders a blog-post, both when it is just summarized in a list of items or fully displayed in a page. The line of code that was waiting for me was:

$name = $page->createdUser->name;

Uh! So no mistakes, my reserved user name was going public ...

After a quick course on the Admin side and reading this forum, you start to feel how PW is powerful. What we have to do to solve our problem it is simply to enhance the User template adding a publicName field to it. Let's proceed step by step.

Login the Admin panel, select Setup, then Fields. Let's create a new text field named publicName, then save.


Then select Setup, then Templates. In PW you can also edit system templates, but to do that you have to select the show system templates option:


Once the list of system templates appears, we will select the template "user", and we will add the new field publicName, then save.


Now clicking on your user name on the top you are going to open your user profile. A blank field named Public Name is now available. There we will write our public name, that.. by chance … will be "Administrator". Of course you can choose whatever you like, and any new user you are going to create will have available such a field. So each user can have a complex user name for login purposes and a public name that will be shown, for example when posting blog posts or replying to comments.


Now that the new field is available we can go back to ukBlogPost() function in _uikit.php and change the code as follows:

  //$name = $page->createdUser->name;
  $name = $page->createdUser->publicName; //>>>>> REPLACE WITH THIS LINE

Let's go back to the front end, and now we see that our reserved user name is no longer there: "Posted by Administrator on …". Good... I feel better.


Please note that reserved user name in the comment form will be shown only for logged-in user, and you can manually overwrite it in case you have to reply a comment. Otherwise it's necessary to modify FieldtypeComments module. In particular the function render() of ContactForm.php:

if($user->isLoggedin()) {
  //$inputValues['cite'] = $user->name;
  $inputValues['cite'] = $user->publicName; //>>>>> REPLACE WITH THIS LINE
  $inputValues['email'] = $user->email;

As I already did few other modifications to FieldtypeComments I also took the opportunity to fix that, but if you are a new PW user, please wait to modify FieldtypeComments until you are more familiar with the environment. It will be necessary to clone the module as described in the first steps of this tutorial:

I hope some new user will find those information of help. Wish a good week start to everybody!

  • Like 3

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...