XF 2.0 ErrorException: Template error: Cannot call method isMemberOf on a non-object (NULL)

Hi,
this error is spamming my Xenforo error log, it generates likely everytime someone loads a post page.

How I could stop/fix this?

Rich (BB code):
ErrorException: Template error: Cannot call method isMemberOf on a non-object (NULL) src/XF/Template/Templater.php:926
Generated by: Account sconosciuto 22 Agosto 2018 alle 12:59
Stack trace
#0 [internal function]: XF\Template\Templater->handleTemplateError(512, 'Cannot call met...', '/home/sciax2/pu...', 926, Array)
#1 src/XF/Template/Templater.php(926): trigger_error('Cannot call met...', 512)
#2 internal_data/code_cache/templates/l4/s7/public/message_macros.php(70): XF\Template\Templater->method(NULL, 'isMemberOf', Array)
#3 src/XF/Template/Templater.php(662): XF\Template\Templater->{closure}(Object(ThemeHouse\UIX\XF\Template\Templater), Array, Array)
#4 internal_data/code_cache/templates/l4/s7/public/post_macros.php(41): XF\Template\Templater->callMacro('message_macros', 'user_info', Array, Array)
#5 src/XF/Template/Templater.php(662): XF\Template\Templater->{closure}(Object(ThemeHouse\UIX\XF\Template\Templater), Array, Array)
#6 internal_data/code_cache/templates/l4/s7/public/thread_view.php(680): XF\Template\Templater->callMacro('post_macros', 'post', Array, Array)
#7 src/XF/Template/Templater.php(1249): XF\Template\Templater->{closure}(Object(ThemeHouse\UIX\XF\Template\Templater), Array)
#8 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('public:thread_v...', Array)
#9 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#10 src/XF/Mvc/Dispatcher.php(332): XF\Mvc\Renderer\Html->renderView('XF:Thread\\View', 'public:thread_v...', Array)
#11 src/XF/Mvc/Dispatcher.php(303): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(44): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#13 src/XF/App.php(1931): XF\Mvc\Dispatcher->run()
#14 src/XF.php(328): XF\App->run()
#15 index.php(13): XF::runApp('XF\\Pub\\App')
#16 {main}
Request state
array(4) {
  ["url"] => string(44) "/forum/threads/nuovo-distintivo-mela.618683/"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 

Nope, but I have a similar code in messagge_macros template:

PHP:
                <xf:if is="{{$user.isMemberOf(152)}}">
                    <span class="userlvl lvl3" data-xf-init="tooltip" title="Utente di Livello 3"><i class="fa fa-star"></i></span>
                <xf:elseif is="{{$user.isMemberOf(153)}}" />
                    <span class="userlvl lvl2" data-xf-init="tooltip" title="Utente di Livello 2"><i class="fa fa-star"></i></span>
                <xf:elseif is="{{$user.isMemberOf(2)}}" />
                    <span class="userlvl lvl1" data-xf-init="tooltip" title="Utente di Livello 1"><i class="fa fa-star"></i></span>
                </xf:if>

Here's another code in PAGE_CONTAINER template:
PHP:
                <xf:if is="in_array({$forum.node_id}, [545, 785, 1894, 1042, 1092, 79, 56, 35, 40, 37, 1972, 268, 1975, 1979, 545, 307, 681, 731, 679])">
                    <xf:widget key="gameparade" />
                </xf:if>

And this in post_macros template:
PHP:
                            <xf:if is="$post.user_id == $thread.user_id">
                            <span class="threadauthor">Autore del topic</span>
                            </xf:if>
 
HTML:
                <xf:if is="$user is not empty">
                    <xf:if is="$user.isMemberOf(152)">
                        <span class="userlvl lvl3" data-xf-init="tooltip" title="Utente di Livello 3"><i class="fa fa-star"></i></span>
                    <xf:elseif is="$user.isMemberOf(153)" />
                        <span class="userlvl lvl2" data-xf-init="tooltip" title="Utente di Livello 2"><i class="fa fa-star"></i></span>
                    <xf:elseif is="$user.isMemberOf(2)" />
                        <span class="userlvl lvl1" data-xf-init="tooltip" title="Utente di Livello 1"><i class="fa fa-star"></i></span>
                    </xf:if>
                </xf:if>
Perhaps that will fix it.


Fillip
 
I think just adding:

Code:
<xf:if is="$user">
// your code here
</xf:if>

similarly to what Fillip suggested should do the trick. I think it happens also if there are deleted users, since they're no more "users" for Xenforo, it'd log server errors, so this way you should prevent it.
 
Back
Top Bottom