How to add wpDiscuz...
 

How to add wpDiscuz comments on author page  

  RSS

amjadkhalil
(@amjadkhalil)
New Member
Joined: 1 month ago
Posts: 2
12/06/2019 10:31 am  

Hello

I did write a filter to activate wp comments on author page but the problem is only wp native comments which follow with,it is not hooked with wpDiscuz comments.

Is there addon or filters that i can use or buy to solve the issue.

 

Thanks


Quote
Topic Tags
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 2903
12/06/2019 1:26 pm  

Hi @amjadkhalil,

Please provide us the code you've used for this purpose. 


ReplyQuote
amjadkhalil
(@amjadkhalil)
New Member
Joined: 1 month ago
Posts: 2
12/06/2019 1:31 pm  

Hello

Thanks for fast feedback.

I did write the code on author.php,and functions.php

 

On author.php

<?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();
?>


-----------------------------------------------
on function.php
function activate_comments_for_user($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','activate_comments_for_user');

ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 2903
12/06/2019 1:33 pm  

ok @amjadkhalil

I'll ask developers and let you know asap. 


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 2903
12/06/2019 3:08 pm  

@amjadkhalil,

We've added a new line in wp_insert_post function: 

'comment_status' => 'open',

Please try it:

$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,
'comment_status' => 'open',

));

Also please make sure the "Display comment form for post types" is enabled for the current post type. 

More info here:

Comment Form Settings


ReplyQuote
Share: