我需要能够允许用户在作者个人资料页面上发表评论。
我在这里找到了另一个答案,它给了我一个基本的概述,说明需要做些什么才能允许它:https://wordpress.stackexchange.com/questions/8996/author-page-comments-and-ratings
那就是说,我不确定如何继续实施。我创建了一个自定义帖子类型来保存评论,但我不知道如何制作它以便每次用户/作者注册我们的网站(我们正在建立一个开放注册的网站)时,会创建一个帖子用于保存评论的自定义帖子类型,然后自动与其用户个人资料相关联。
非常感谢比链接问题提供的更详细的答案,以便我能够准确理解如何启动和运行。
非常感谢
答案 0 :(得分:3)
实际上你需要简单地将Stuff与 user_register Action挂钩,如
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');
以上代码是您在原始帖子https://wordpress.stackexchange.com/questions/8996/author-page-comments-and-ratings中实际遗漏的内容所以在添加上述代码后,您只需要对 author.php 进行操作,就像一样那段代码
$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();
答案 1 :(得分:0)
您可以使用insert_user_meta钩子将新过滤器挂钩到wp_insert_user函数(如果您正在使用它来在注册步骤中插入用户),因此,在创建新用户之后,将在保存它之前在元数组上调用此过滤器。以下是可能有用的示例代码:
<?php
add_filter('insert_user_meta', 'nl_associate_cp_to_user', 10, 3);
function nl_associate_cp_to_user($meta, $user, $update ){
$meta['cpid_for_comments'] = nl_get_new_cpid_for_comments();
return $meta;
}
function nl_get_new_cpid_for_comments(){
$data = array(
'post_type' => 'CCPT',
'post_title' => 'Stub Post',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
);
$post_id = wp_insert_post( $data );
if(!is_wp_error($post_id)) return $post_id;
}
?>
答案 2 :(得分:0)
您可以使用以下代码更新user-author.php文件。
<?php
//save blog Id
$blog_id = $post->ID;
// now map your post with author post
$author_post_id = get_user_meta($user_id, author_post_id,blog);
query_posts("p=$author_post_id");
the_post();
//Your are in a single post page
$wp_query->is_single = blog;
//get comments
comments_template();
//reset wordpress to particular post
$wp_query->is_single = false;
query_posts("p=$blog_id");
the_post();
?>
您需要了解这里我们假设特定博客的博客ID。如果您有任何其他问题,请告诉我。