OUGC Network

How to hide xThreads fields until user rates a thread?

* This tutorial is using the develop branch from GitHub. Official support will be for future release to be marked as 1.8.22.

[Image: 9hNUDMH.gif]

Hi, here I'm going to share how to use OUGC Custom Reputation xThreads integration to hide thread field data unless users rate a thread. You should be aware that xThreads only works on threads or first posts and thus this feature isn't meant to work on replies or regular not first posts.

For this tutorial we are going to use the most basic integration feature, which allows us to require users to rate a thread using any rate available. Later we could expand this tutorial to explain how to allow users to request specific ratings rather than any available.

Because of this, we are going to skip the process of adding custom reputations, as this tutorial assumes that you have already created some that are available for all users in all forums (the default custom rating created at installation should work with this tutorial).

Configure phptpl_allowed_funcs.txt
The first step is to add the OUGC Custom Reputation function to the white list of xThreads functions. If you have already configured your fields you will need to save the fields again so that the cache gets updated.

  1. /inc/xthreads/phptpl_allowed_funcs.txt Access your site server files and open this file to edit it.
  2. Addougc_customrep_xthreads_hide at the end of the file, in a new line if you want.


xThreads Field
Next step would be us creating and configuring our xThreads field, which will be hidden content. We are going to create a basic text field using the following details:

  1. Key: ougc_customrep_content There is no restriction regarding this value, just take note on all the times this is found within this tutorial once you create additional fields.
  2. Applicable Forums: This field will be activated in all forums, remember this tutorial considers your users have rates available in all forums. If there are no available rates users could be unable to view the content.
  3. Hide Thread Field: Don't activate this options as Ajax support won't work and users will need to reload the page to see updates. It is possible to make Ajax features work even if hiding the field, but that isn't covered in this tutorial.
  4. Input Field Type: Multiline Textbox This field is going to behave similar to the message field.
  5. Editable by / Required Field?: Everyone Any user will be able to use this field if they wish to.
  6. Description: Users will be required to rate this thread to see this content.
  7. Field Input Width: 160
  8. Field Input Height: 20
  9. Display Parsing: Use MyBB Parser (MyCode)
  10. MyBB Parser Options: Activate all options but HTML parsing:
    • Allow newlines
    • Filter Badwords
    • Allow MyCode
    • Allow [img] MyCode
    • Allow [video] MyCode
    • Parse Smilies
  11. Use Custom Input HTML: Yes
  12. Input Field HTML:
    <script type="text/javascript">
    <!--
    	$(document).ready(function() {
    		OUGC_CustomReputation.xThreadsHideSet('ougc_customrep_content');
    	});
    //-->
    </script>

    This will avoid the field from hiding in the edit post page (a feature that isn't exploited in this tutorial).
  13. Blank Replacement Value:
    <script type="text/javascript">
    <!--
    	$(document).ready(function() {
    		$('#xt_ougc_customrep_content').hide();
    	});
    //-->
    </script>

    This will hide the xThreads field if not content was inserted by the user.
  14. Display Format:
    <?=ougc_customrep_xthreads_hide({VALUE})?>

    This is what will actually do the trick. This function has more options but non is covered in this tutorial.
  15. Viewable by Usergroups: You can restrict the content to be viable only for specific groups.
  16. Save the field.

Any field not mentioned configure as you see fit.

Configure OUGC Custom Reputation
Then, we need to configure OUGC Custom Reputation plugin settings.


  1. Go to Home » Board Settings » OUGC Custom Reputation
  2. Active xThreads Hide Feature: Select the field you just configured. You can select multiple fields because there is not a set limit to the amount of configurations you can set.

Template Edits
Finally, we need to edit two xThreads templates.

  1. showthread_threadfield_row:
    <tr id="xt_{$k}"><td width="15%" class="{$bgcolor}"><strong>{$title}</strong></td><td class="{$bgcolor}">{$value}</td></tr>

  2. post_threadfields_inputrow:
    <tr class="xthreads_inputrow" id="xt_{$tf['field']}">
    <td class="{$altbg}" width="20%"><strong>{$tf['title']}</strong></td>
    <td class="{$altbg}">{$inputfield}<small style="display: block;">{$tf['desc']}</small></td>
    </tr>

We are basically just adding an ID to the parent HTML tag in these templates. Thi will allow both, the hiding of the field in the edit post page and Ajax support for updating content.


I decided to integrate xThreads support in OUGC Custom Reputation because the plugin already offers a lot of features. You can, for example, create file fields, which you can configure to hide until the users rate the thread.

You can test that example in this community, in the thread Tutorial Replacing MyBB ratings with Semantic UI ratings module. you are required to rate the thread to view the attached file.

Eventually I could expand this tutorial to describe additional configurations.
This post was last modified: 04-26-2020, 04:50 AM by Omar G.. Edited 3 times in total.
There are currently no posts to display. Be the first one to leave a reply.

Current time: 07-05-2020, 04:08 PM

This forum uses Lukasz Tkacz MyBB addons.