Jump to content

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


Edison
 Share

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!

1835543671_ScreenShot2019-07-15at00_01_39.thumb.png.5a63a5993c3d80f36a90267360ddbc98.png

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.

1120339317_ScreenShot2019-07-15at00_03_08.thumb.png.73101daf9ca3ad49a663b23d2baf74f0.png

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.

1823058879_ScreenShot2019-07-14at23_56_42.thumb.png.90fc1b2c4fae9c59ad644a3621218cc4.png

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:

2146919217_ScreenShot2019-07-14at23_58_30.thumb.png.89de64f02d26aaef452c0a44a3227322.png

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

533364585_ScreenShot2019-07-14at23_59_39.thumb.png.e1ccd0c994d3b27b25b8b5f44ddd18bb.png

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.

918508579_ScreenShot2019-07-15at00_00_13.thumb.png.5e587667014bb870f8e8f60dfc77683c.png

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.

687248673_ScreenShot2019-07-15at00_01_50.thumb.png.065e4325f0d17a0fb7daf5febb3e0c0d.png

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...