• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to add permissions to an addon?

Matthew Hawley

Well-known member
#1
So I have this:

addonpermissions.png

And this is the code in the template:

Code:
<xen:if is="{$perms.FindPostsInThread}">
<xen:if is="{$hasPosted}">
        <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
</xen:if>
</xen:if>
Please don't just reply with some code, please tell me what to do with it.
 

Chris D

XenForo developer
Staff member
#2
I got your PM.

Best bit of advice I can give is to check how I've done it in my Hide Poll Results add-on (it's one of my more recent add-ons). It contains various code relating to permission checks.
 

James

Well-known member
#3
@Matthew Hawley what is this code for?
Code:
<xen:if is="{$perms.FindPostsInThread}">
Permission checking in templates is done in this form:
Code:
<xen:if is="{$visitor.permissions.permissionGroupID.permissionID}">
Permission Group ID -> Find Your Posts In A Thread (whatever the ID is)
Permission ID -> canFindPostsInThread
 

Matthew Hawley

Well-known member
#4
Okay so i have this

Code:
<xen:if is="!{$xenOptions.findPostsInThreadEnable}">
<xen:foreach loop="$posts" value="$post">
      <xen:if is="{$post.user_id} == {$visitor.user_id}">
            <xen:set var="$hasPosted">1</xen:set>
      </xen:if>
</xen:foreach>
<xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">
<xen:if is="{$hasPosted}">
        <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
</xen:if>
</xen:if>
</xen:if>
And the your posts link doesn't show up. I have the permission set as enabled for admins.
 

James

Well-known member
#5
Code:
<xen:if is="!{$xenOptions.findPostsInThreadEnable}">
The exclamation mark is asking if the variable is false. Given that you're using "Enable" at the end, I imagine that is supposed to evaluate to true.
 

Matthew Hawley

Well-known member
#7
Code:
<xen:if is="!{$xenOptions.findPostsInThreadEnable}">
The exclamation mark is asking if the variable is false. Given that you're using "Enable" at the end, I imagine that is supposed to evaluate to true.
Thats not the problem. Though I did what you said and it still didn't work.
 

James

Well-known member
#9
Put debug code inside your code.

Code:
<xen:if is="!{$xenOptions.findPostsInThreadEnable}">
<p style="background:red;">Enabled</p>

<xen:foreach loop="$posts" value="$post">
      <xen:if is="{$post.user_id} == {$visitor.user_id}">
            <xen:set var="$hasPosted">1</xen:set>

<p style="background:red;">Variable Set</p>
      
</xen:if>
</xen:foreach>
<xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">

<p style="background:red;">Has Permission</p>

<xen:if is="{$hasPosted}">

<p style="background:red;">Has Posted</p>

        <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
</xen:if>
</xen:if>
</xen:if>
 
#10
Put debug code inside your code.

Code:
<xen:if is="!{$xenOptions.findPostsInThreadEnable}">
<p style="background:red;">Enabled</p>

<xen:foreach loop="$posts" value="$post">
      <xen:if is="{$post.user_id} == {$visitor.user_id}">
            <xen:set var="$hasPosted">1</xen:set>

<p style="background:red;">Variable Set</p>
     
</xen:if>
</xen:foreach>
<xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">

<p style="background:red;">Has Permission</p>

<xen:if is="{$hasPosted}">

<p style="background:red;">Has Posted</p>

        <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
</xen:if>
</xen:if>
</xen:if>
whats the background red for?
 

James

Well-known member
#15
I'm currently at work and recently formatted my PC. I don't have a test setup of XF as I don't have a local webserver.