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

Arguments of ismemberof function?

Discussion in 'XenForo Questions and Support' started by fredrikse, Oct 20, 2012.

  1. fredrikse

    fredrikse Active Member


    What kind of value is argument $thread in the following example?

    {xen:helper ismemberof$thread11}
    Is it an array?
  2. Insy

    Insy Well-Known Member

    public static function helperIsMemberOf(array $user$userGroupId$multipleIds null)
    if (!
    // check multiple groups
    $userGroupId array_slice(func_get_args(), 1);
    Jake Bunce and fredrikse like this.
  3. fredrikse

    fredrikse Active Member

  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    $thread likely contains the thread record as well as the user record. Only the user part of the array is relevant here.

    ismemberof requires the full user record, not just the user_id. Make sure $thread contains the full user record.
    fredrikse likes this.
  5. fredrikse

    fredrikse Active Member

    What would be the correct usage of $thread in the ismemberof function? I want to point to the userID, but I'm not sure really how.
  6. Insy

    Insy Well-Known Member

    Here is how this code works:

    First, this query will retrieve the latest topics according to many conditions. The result will be an array ($recent).
    if (in_array($widget['options']['type'], array('recent''all'))) {
    $recent $threadModel->getThreads(
    array_merge($fetchOptions, array(
    'order' => 'last_post_date',
    'orderDirection' => 'desc',
    'join' => 0,
    'last_post_join' => XenForo_Model_Thread::FETCH_AVATAR,
    For each topic, the user id and user name are defined in such a way that the helper isMemberOf can identify the user.
    Here, the values ​​are defined by reference, no need to write something like $recent[$id] = $thread ;)
    foreach ($recent as &$thread) {
    $thread['user_id'] = $thread['last_post_user_id'];
    $thread['username'] = $thread['last_post_username'];
    } else {
    $recent = array();
    In the template wf_widget_threads, the $recent array is iterated. Each $thread is also an array.
    The two values defined above (user_id and username) will be sought by the isMemberOf helper into $thread.
    <xen:foreach loop="$recent" value="$thread">
                  <xen:avatar user="$thread" size="s" img="true" />
    <xen:include template="wf_widget_threads_thread_title">
    <xen:set var="$_showPrefix">{$widget.options.display.show_prefix}</xen:set>
    <xen:set var="$_threadLink">{xen:if '{$visitor.user_id} > 0', {xen:link threads/unread, $thread}, {xen:link posts, {xen:array 'post_id={$thread.last_post_id}'}}}</xen:set>
                  <div class="userTitle">{xen:phrase wf_x_replied, 'user=<a href="{xen:link 'members', $thread}">{$thread.username}</a>'} <xen:datetime time="{$thread.last_post_date}" /></div>
    To summarize, the isMemberOf helper needs to have as first parameter an array with two keys: user_id (int) and username (string).
    fredrikse likes this.
  7. fredrikse

    fredrikse Active Member

    Thanks for that great summary! (y)

    Does that mean that I only have to submit the $thread array in the isMemberOf helper without specifying user or username attribute of the array? :unsure:
  8. Insy

    Insy Well-Known Member

  9. fredrikse

    fredrikse Active Member

    When I look at the FAQ the example of a condition looks like this:

    How can I show content to a specific user group?
    <xen:if is="{xen:helper ismemberof, $visitor, x}">
    This content will show to members of user group x
    That's what I have used in my condition. Username is nowhere to be found as far as I can see. I'm probably the one where who's a little bit stupid at the moment not understanding what you are so clearly trying to tell me :)
  10. Insy

    Insy Well-Known Member

    I assume that $visitor is the current user.
    $visitor XenForo_Visitor::getInstance()->toArray();
    var_dump$visitor );
    array(48) {
      string(5) "Simon"
      string(16) "xxxxxxx@gmail.com"
      string(0) ""
      string(0) ""
    Or maybe I don't understand your question ? :confused:

Share This Page