donglijuan8227 2015-12-09 11:48
浏览 105
已采纳

WordPress - 允许对作者页面发表评论

I need to be able to allow users to leave comments on author profile pages.

I came across another answer here that has given me a basic outline of what needs to be done to allow it: https://wordpress.stackexchange.com/questions/8996/author-page-comments-and-ratings

That said, I am unsure how to proceed with getting it implemented. I have created a custom post type to hold the comments, but I do not know how to make it so that each time a user/author signs up to our site (we are building a site with open registration), a post gets created in the custom post type to hold comments, and then automatically associated to their user profile.

Would much appreciate a more detailed answer than what was provided on the linked question, so that I am able to understand exactly how to get this up and running.

Many Thanks

  • 写回答

3条回答 默认 最新

  • dqu94359 2015-12-16 10:06
    关注

    Actually you need to simply hook the Stuff with the user_register Action like

    function my_user_register($user_id){
    
        $user = get_user_by( 'id', $user_id );
    
        /**
         * if required you can limit this profile creation action to some limited 
         * roles only
         */
    
        /**
         * Created new Page under "user_profile_page" every time a new User 
         * is being created
         */
    
        $profile_page = wp_insert_post(array(
            'post_title'        => " $user->display_name Profile ", // Text only to Map those page @ admin
            'post_type'         => "user_profile_page", // Custom Post type which you have created 
            'post_status'       => 'publish',
            'post_author'       => $user_id,
        ));
    
        /**
         * Save the Profile Page id into the user meta
         */
        if(!is_wp_error($profile_page))
            add_user_meta($user_id,'user_profile_page',$profile_page,TRUE);
    }
    
    /**
     * Action which is being trigger Every time when a new User is being created
     */
    add_action('user_register','my_user_register');
    

    Above code is something which you are actually missing from the original post https://wordpress.stackexchange.com/questions/8996/author-page-comments-and-ratings So after adding the above code you simple need to follow that over the author.php same like that code

    $profile_page = get_the_author_meta('user_profile_page');
    
    global $post;
    $post = get_post($profile_page);
    
    setup_postdata( $post ); 
    
    //fool wordpress to think we are on a single post page
    $wp_query->is_single = true;
    //get comments
    comments_template();
    //reset wordpress to ture post
    $wp_query->is_single = false;
    
    wp_reset_query();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?