Hacking the K2 User Profile (J1.5)

For those who know how to properly use Joomla!®, you will agree with me that K2 is one hell of a powerful extension for the content management system and if configured correctly, it can be useful in turning your site into anything!

Of late, K2 has been frustrating me. I have been having trouble trying to add custom registration fields to the core Joomla!® user object while still being able to use the K2 user plugin to populate the extra fields. My first thought was to simply disable the K2 user plugin, which I did. This though, prevented useful features like allowing users to add content from the frontend via K2. Disabling the plugin also seemingly broke frontend moderation and these were core features that I (my client) required.

So, how do you add custom fields to Joomla!® and link these fields to the K2 User profile? Read on!

The first thing you would have to do, I suppose is add the custom registration fields to Joomla!®. To do so, you will need to edit at least three files, namely

  1. libraries/joomla/database/table/user.php – declare your new variables in this class. You may also include checking code here
  2. components/com_user/views/register/tmpl/default.php – edit the front-end registration form accordingly
  3. administrator/components/com_users/views/user/tmpl/form.php – edit the back-end registration form accordingly as well

NB: Please note that the last two files may be overwritten by the template in use. Therefore if edits to the forms do not show up on the site, please look into editing the overriding templates in the html folder of your template.

There are other files around the Joomla!® user system that may be edited for a more complete addition of custom fields but that is a story for another blog post. Moving on.

Now that we have edited the relevant files, please add required fields into the users table of your Joomla!® installation or the user system will crash. Ensure the field names match the variable names you added in the class of the first file.

Now that the Joomla!® core system is able to properly save your custom registration fields, now we need to add these fields into the K2 user profile, and here is how you do so.

Edit the following files in K2 to allow the viewing of the new custom registration fields

  1. components/com_k2/templates/register.php – edit the front end registration form accordingly, adding the fields you added into the Joomla!® core system
  2. components/com_k2/templates/profile.php – edit the front end profile edit forms according to allow editing of the user profile including custom fields added.

And there you have it! K2 can now manage your extra fields without any hustle whatsoever. And you can now enable the K2 User plugin and take advantage of all its powerful features.

Should any of the steps above be too summarized of should you need more details in getting an extended K2 User profile, please do not hesitate to ask in the comments.

Please note that the above hack is works on Joomla 1.5 only!

Share

4 comments

  1. Could you please perhaps explain in more detail how one would go about these steps? Please?

Leave a Reply