• Resolved dreamsoft

    (@dreamsoft)


    I show ranks in comments, but if the comment author is not registered I get this error:
    mycred_get_users_rank() : Missing required user idRank: mycred_get_users_rank() : Missing required user id

    How can I add a condition, if the comment author is not registered (if the user id is missing) to show nothing (well, not the error)

    thank you

    https://wordpress.org/plugins/mycred/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter dreamsoft

    (@dreamsoft)

    I added a condition to check if the user is registered if( $comment->user_id > 0 ) {

    But some people say this is not good for security, so if there is a condition in your plugin, please tell me about it.

    thanks again

    Plugin Author myCred

    (@designbymerovingi)

    Hi.

    Yes, the mycred_get_users_rank() function requires a user_id and when your comment author is not logged in, $comment->user_id will be left empty causing an error.

    When showing any user detail you need to make sure the comment was made by a logged in user and your suggestion

    if( $comment->user_id > 0 ) {

    will do just that.

    I am a bit unsure as to what security issues this could cause as we are basically just getting a user meta detail. If this meta does not exist, we query the users current rank during which the users ID is sanitized. If no rank is found (either because the user is excluded or because the user ID is not a ID but bad code) then nothing is shown and no further action is taken.

    You could show a users rank without using a myCRED function but instead using WordPress functions:

    // Show the comment authors rank (title)
    if ( $comment->user_id > 0 ) {
    	$user_id = absint( $comment->user_id );
    	$rank_post_id = get_user_meta( $user_id, 'mycred_rank', true );
    	if ( $rank_post_id != '' ) echo get_the_title( absint( $rank_post_id ) );
    }
    Thread Starter dreamsoft

    (@dreamsoft)

    great, thanks!

    Thread Starter dreamsoft

    (@dreamsoft)

    *solved*

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘error if comment author is not registered’ is closed to new replies.