WordPress - Allowing comments on author pages
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 commentscomments_template();//reset wordpress to ture post$wp_query->is_single = false;wp_reset_query();
You can hook a new filter to wp_insert_user function (if you're using it to insert user on registration step) using insert_user_meta hook, so, after creating new user, this filter will be called on meta array before saving it. Here is the example code that might be helpful:
<?phpadd_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; }?>
You Can update your user-author.php file with the below code.
<?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(); ?>
You need to understand here we assume with blog id for the particular blog. please let me know if there are any other issue you are facing.