wpDiscuz - WordPress Comment Plugin
Share:
Notifications
Clear all

[Solved] Using avatar from jReviews

10 Posts
2 Users
1 Likes
238 Views
Baze
Posts: 9
 Baze
Topic starter
(@baze)
Active Member
Joined: 5 months ago

Hi guys,

i'm struggling to show the jReviews user avatar in the comments, basically i started this topic Cannot add php code in theme files – How-to and Troubleshooting – wpDiscuz Support Forum, since the plan was to add the php directly but as you explained i have to use custom shortcode with the php there.

So i've done that, but i cannot get the id of the user who is the poster of the comment, so i'm seeing specific avatars (from user id = 1) on all comments.

 

In the override for the avatar view i have:

<div class="{AVATAR_WRAPPER_CLASSES}">
   [useravatar]
    <div class="userinfo">    
	</div>
   <div class="auth">{AUTHOR}</div>
</div>

And in functions.php i have:

function useravatar_link() {
    ob_start();

	require_once ABSPATH.'/wp-content/plugins/jreviews/jreviews/framework.php'; 
	S2App::import('Component','userprofiles_profile','jreviews');
	S2App::import('Model','everywhere_com_content','jreviews');
	$profile = UserprofilesProfileComponent::getOneProfile($userId = "1");
	
	echo '<img class="avatar avatar-64 photo" src="'.$profile['MainMedia']['media_info']['thumbnail']['65x65c']['url'].'">';
	
    return ob_get_clean();
}
add_shortcode('useravatar', 'useravatar_link'); 

add_filter("wpdiscuz_comment_end", function ($commentOutput, $comment, $depth, $args) {
    if ($depth > 2) {
        $commentOutput .= "[useravatar]";
    }
    return $commentOutput;
}, 10, 4);

As you can see here in the line "$profile = UserprofilesProfileComponent::getOneProfile($userId = "1");" i need to put the user id of the comment poster instead of "1". So could you please let me know how can i get that?

9 Replies
Asti
Posts: 5071
 Asti
Support
(@asti)
Illustrious Member
Joined: 5 years ago

Dear @baze,

Please note that we don't support any kinds of customizations. Just a bit hint. 

$profile = UserprofilesProfileComponent::getOneProfile($userId = "1");

You'll need to paste the right value for the $userId. Don't add just 1. 

8 Replies
Baze
 Baze
(@baze)
Joined: 5 months ago

Active Member
Posts: 9

@asti i'm aware of that, the problem is that i don't know how to get userid from wpdiscuz, that's the question 🙂

Asti
 Asti
Support
(@asti)
Joined: 5 years ago

Illustrious Member
Posts: 5071

@baze,

You can try this value get_current_user_id(). More info here: https://developer.wordpress.org/reference/functions/get_current_user_id/

Baze
 Baze
(@baze)
Joined: 5 months ago

Active Member
Posts: 9

@asti but that will return the currently logged in user, i need the user id of the author of the comment.

Asti
 Asti
Support
(@asti)
Joined: 5 years ago

Illustrious Member
Posts: 5071

@baze,

Please try to add this one in the functions.php file:

add_filter("wpdiscuz_comment_end", function ($commentOutput, $comment, $depth, $args) {
    if ($comment->user_id) {
        require ABSPATH . '/wp-content/plugins/jreviews/jreviews/framework.php';
        S2App::import('Component', 'userprofiles_profile', 'jreviews');
        S2App::import('Model', 'everywhere_com_content', 'jreviews');
        $profile = UserprofilesProfileComponent::getOneProfile($comment->user_id);
        $avatar = '<img class="avatar avatar-64 photo" src="' . $profile['MainMedia']['media_info']['thumbnail']['65x65c']['url'] . '">';
    } else {
        $avatar = '<img class="avatar avatar-64 photo" src="default-avatar.jpg">';
    }
    $commentOutput = str_replace('[useravatar]', $avatar, $commentOutput);
    return $commentOutput;
}, 10, 4);

It may work fine.

Baze
 Baze
(@baze)
Joined: 5 months ago

Active Member
Posts: 9

@asti Works like a charm, thanks!!!

Asti
 Asti
Support
(@asti)
Joined: 5 years ago

Illustrious Member
Posts: 5071

@baze,

We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.

Baze
 Baze
(@baze)
Joined: 5 months ago

Active Member
Posts: 9

@asti just did (user: gixxermkd), thanks again guys!

Asti
 Asti
Support
(@asti)
Joined: 5 years ago

Illustrious Member
Posts: 5071

Thank you very much @baze,

We really appreciate it. 

Share: