Check on user ID is null throws error

Support MB Views Check on user ID is null throws errorResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37016
    ArnoArno
    Participant

    Hello,

    I have this in my view:

    {% if (user.ID is null) %}
    	Anonymous, throwing error
    
    {% else %}
    	Logged on
    
    {% endif %}

    When no user is logged in, it shows the text but it also throws this error in the frontend: "Warning: array_merge(): Expected parameter 2 to be an array, null given in /home/user/example.com/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/src/Renderer/User.php on line 15".

    There is no error if a user is logged on.

    #37030
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The error is displayed because if the user is not logged in, there is no property ID. If you want to check the user logged in, please use the WordPress function is_user_logged_in(). For example

    {% if( mb.is_user_logged_in() ) %}
    Logged in
    {% else %}
    Guest
    {% endif %}

    Read more on the documentation https://developer.wordpress.org/reference/functions/is_user_logged_in/

    #37033
    ArnoArno
    Participant

    Thank you, that works great!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.