评论“喜欢”问题--“喜欢这个”头像链接到当前用户配置文件,而不是“点赞”用户的配置文件

时间:2017-01-07 作者:kosmicbird

此问题与wp ulike插件有关。对这个插件的支持似乎不存在,所以我必须进入文件中,试图找出如何修复一些东西。

更深入地描述我正在处理的问题:

如果用户A“喜欢”一条评论,刷新页面后,该评论上会显示+1 like,并且还会显示该用户的头像,该头像应该链接到该用户的个人资料。

现在的问题是URL链接到当前用户的配置文件,而不是正确链接到用户A的配置文件。

假设我已登录我的帐户。我去看看喜欢这个评论的用户。嗯,头像显示了用户A的图像(应该是这样),但他的头像链接到了我的个人资料。当注释上有类似的内容时,就会出现此问题。

现在,当评论上有两个赞(比如,来自两个不包括我在内的用户)时,它将显示这两个用户的头像。现在,当我点击查看他们的个人资料时。。用户A仍然链接到当前用户(我的个人资料),而第二个用户的化身(用户B)链接到用户A的个人资料。

我希望我描述得很清楚。下面是控制注释的代码,如下所示:

/**
 * wp_ulike_comments function for comments like/unlike display
 *
 * @author          Alimir      
 * @since           1.6
 * @updated         2.3
 * @return          String
 */
function wp_ulike_comments($arg) {
    //global variables
    global $wp_ulike_class,$wp_user_IP;

    $CommentID      = get_comment_ID();
    $comment_meta   = get_comment_meta($CommentID, \'_commentliked\', true);
    $get_like       = $comment_meta != \'\' ? $comment_meta : 0;
    $return_userID  = $wp_ulike_class->get_reutrn_id();
    $theme_class    = wp_ulike_get_setting( \'wp_ulike_comments\', \'theme\');

    if(
    (wp_ulike_get_setting( \'wp_ulike_comments\', \'only_registered_users\') != \'1\')
    or
    (wp_ulike_get_setting( \'wp_ulike_comments\', \'only_registered_users\') == \'1\' && is_user_logged_in())
    ){

    $data = array(
        "id"        => $CommentID,              //Comment ID
        "user_id"   => $return_userID,          //User ID (if the user is guest, we save ip as user_id with "ip2long" function)
        "user_ip"   => $wp_user_IP,             //User IP
        "get_like"  => $get_like,               //Number Of Likes
        "method"    => \'likeThisComment\',       //JavaScript method
        "setting"   => \'wp_ulike_comments\',     //Setting Key
        "type"      => \'post\',                  //Function type (post/process)
        "table"     => \'ulike_comments\',        //Comments table
        "column"    => \'comment_id\',            //ulike_comments table column name          
        "key"       => \'_commentliked\',         //meta key
        "cookie"    => \'comment-liked-\'         //Cookie Name
    );      

    //call wp_get_ulike function from class-ulike calss
    $counter        = $wp_ulike_class->wp_get_ulike($data);     

    $wp_ulike       = \'<div id="wp-ulike-comment-\'.$CommentID.\'" class="wpulike \'.$theme_class.\'">\';
    $wp_ulike       .= \'<div class="counter">\'.$counter.\'</div>\';
    $wp_ulike       .= \'</div>\';
    $wp_ulike       .= $wp_ulike_class->get_liked_users($CommentID,\'ulike_comments\',\'comment_id\',\'wp_ulike_comments\');

    if ($arg == \'put\') {
        return $wp_ulike;
    }
    else {
        echo $wp_ulike;
    }

    }//end !only_registered_users condition

    else if (wp_ulike_get_setting( \'wp_ulike_comments\', \'only_registered_users\') == \'1\' && !is_user_logged_in()){
        $login_type = wp_ulike_get_setting( \'wp_ulike_general\', \'login_type\');
        if($login_type == "button"){
            $template = $wp_ulike_class->get_template($CommentID,\'likeThisComment\',$get_like,1,0);
            if (wp_ulike_get_setting( \'wp_ulike_general\', \'button_type\') == \'image\') {
                return \'<div id="wp-ulike-comment-\'.$CommentID.\'" class="wpulike \'.$theme_class.\'"><div class="counter">\' . $template[\'login_img\'] . \'</div></div>\';        
            }
            else {
                return \'<div id="wp-ulike-comment-\'.$CommentID.\'" class="wpulike \'.$theme_class.\'"><div class="counter">\' . $template[\'login_text\'] . \'</div></div>\';   
            }
        }
        else
            return \'<p class="alert alert-info fade in" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>\'.__(\'You need to login in order to like this comment: \',WP_ULIKE_SLUG).\'<a href="\'.wp_login_url( get_permalink() ).\'"> \'.__(\'click here\',WP_ULIKE_SLUG).\' </a></p>\';   
    }//end only_registered_users condition

}
这一行似乎特别涉及获取和显示带有用户头像的“喜欢此评论的用户”区域。

    $wp_ulike          .= $wp_ulike_class->get_liked_users($CommentID,\'ulike_comments\',\'comment_id\',\'wp_ulike_comments\');
Edit: 下面是额外的代码块,可以更好地描述-

get\\u reutrn\\u ID()>>插件作者对该函数进行了输入错误,并在其余代码中使用了该函数

        /**
     * Return user ID
     *
     * @author          Alimir
     * @since           2.0
     * @return          String
     */         
    function get_reutrn_id(){
        global $user_ID,$wp_user_IP;
        if(!is_user_logged_in()){
            return ip2long($wp_user_IP);
        }
        else
            return $user_ID;
    }


}

//global variables
global $wp_ulike_class;
$wp_ulike_class = new wp_ulike();
get\\u liked\\u users()函数-

        /**
     * Get Liked User
     *
     * @author          Alimir
     * @param           Integer $id
     * @param           String $table
     * @param           String $column_id
     * @param           String $setting_key
     * @since           2.0
     * @updated         2.3
     * @return          String
     */
    public function get_liked_users($id,$table,$column_id,$setting_key){
        $users_list = \'\';
        $limit_num  = wp_ulike_get_setting( $setting_key, \'number_of_users\');
        if($limit_num == 0) $limit_num = 10;
        $get_users  = $this->wpdb->get_results("SELECT user_id FROM ".$this->wpdb->prefix."$table WHERE $column_id = \'$id\' AND status = \'like\' AND user_id BETWEEN 1 AND 999999 GROUP BY user_id LIMIT $limit_num");
        if(wp_ulike_get_setting( $setting_key, \'users_liked_box\') == \'1\' && !$get_users == \'\'){
            $get_template = wp_ulike_get_setting( $setting_key, \'users_liked_box_template\' );
            if($get_template == \'\')
            $get_template = \'<br /><p style="margin-top:5px"> \'.__(\'Users who have liked this post:\',WP_ULIKE_SLUG).\'</p> <ul class="tiles"> %START_WHILE% <li><a class="user-tooltip" title="%USER_NAME%">%USER_AVATAR%</a></li> %END_WHILE%</ul>\';
            $inner_template = $this->get_template_between($get_template,"%START_WHILE%","%END_WHILE%");
            foreach ( $get_users as $get_user ) 
            {
                $user_info = get_userdata($get_user->user_id);
                $out_template = $inner_template;
                if ($user_info):
                    if (strpos($out_template, \'%USER_AVATAR%\') !== false) {
                        $avatar_size = wp_ulike_get_setting( $setting_key, \'users_liked_box_avatar_size\');


                                                    $user_profile_link = um_user_profile_url();
                        $USER_AVATAR = \'<a href="\' . $user_profile_link . \'">\' .get_avatar( $user_info->user_email, $avatar_size, \'\' , \'avatar\');
                        $out_template = str_replace("%USER_AVATAR%", $USER_AVATAR, $out_template);
                    }
                    if (strpos($out_template, \'%USER_NAME%\') !== false) {
                        $USER_NAME = $user_info->display_name;
                        $out_template = str_replace("%USER_NAME%", $USER_NAME, $out_template);
                    }
                    if (strpos($out_template, \'%UM_PROFILE_URL%\') !== false && function_exists(\'um_fetch_user\')) {
                        global $ultimatemember;
                        um_fetch_user($user_info->ID);
                        $UM_PROFILE_URL = um_user_profile_url();
                        $out_template = str_replace("%UM_PROFILE_URL%", $UM_PROFILE_URL, $out_template);
                    }
                    if (strpos($out_template, \'%BP_PROFILE_URL%\') !== false && function_exists(\'bp_core_get_user_domain\')) {
                        $BP_PROFILE_URL = bp_core_get_user_domain( $user_info->ID );
                        $out_template = str_replace("%BP_PROFILE_URL%", $BP_PROFILE_URL, $out_template);
                    }
                    $users_list .= $out_template;
                endif;
            }
            if($users_list!=\'\')
            $users_list = $this->put_template_between($get_template,$users_list,"%START_WHILE%","%END_WHILE%");
        }
        return $users_list;
    }
有人能帮我弄清楚吗?如何使用户头像链接到正确的用户配置文件?

1 个回复
最合适的回答,由SO网友:CK MacLeod 整理而成

这里我只能给出部分答案,因为细节可能取决于主题和安装的特性,包括UM和如何使用它。

如果没有安装和打开,我不确定我是否能弄清楚为什么你会得到意想不到的结果。但是,如果您想破解设置,可以在ulike类中访问上面提供的get\\u liked\\u users函数。php,第430-450行(或者可能在那个里添加一个过滤器),或者创建您自己的令牌,以和设置页面上显示和可用的令牌相匹配,或者重写已经提供的令牌之一,添加详细信息,包括指向您想要的任何配置文件、个人简介或作者页面等的链接,并根据您的需要添加。您需要的任何一组链接都应该以这样或那样的方式从$user\\u info中轻松派生出来,因为它依赖于get_userdata()

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请