wpDiscuz - WordPress Comment Plugin
Share:
Notifications
Clear all

[Solved] Changng output text for disabled coments for user (global) and single user


Orakel
Posts: 96
Topic starter
(@orakel)
Trusted Member
Joined: 1 year ago

Hello all, hello dear Asti

 

Some Weeks ago, you helped me to show a textline above the comment section, if comments are disabled,

 


add_action("wpdiscuz_comment_form_closed", function ($post, $currentUser, $commentsCount) {
echo "Comments are deactivated in this article";
}, 10, 3)

 

Yesterday i got it to work, to disable the comment form for a specific (comment banned) user.

It´s this lines if anyone like it:

 

just make a new role with only "read" permission, example name = locked)

add_filter( 'init', function()
{
$u = wp_get_current_user();

if( $u->exists() && in_array( 'locked', $u->roles, true ) )
add_filter( 'comments_open', '__return_false' );
} );

 

My question now is, how i get it to work to show different messages if its a post related comment close like the code at first (Comments are deactivated in this article) or a userrole related message like "You are not allowed to post comments".

Is it possible to include the second message with a if else code like if userrole = banned shwow this, if not show this, in that codelines?

add_action("wpdiscuz_comment_form_closed", function ($post, $currentUser, $commentsCount) {
echo "Comments are deactivated in this article";
If userrole = banned echo "you are locked and not possible to write a comment"
}, 10, 3)

 

further i was searchng for the css class (ok i am a realy new on css bt learning fast)

how can i format this text inside the php echo?

 

Thanks in adcance

Orakel

8 Replies
Asti
Posts: 3901
 Asti
Support
(@asti)
Support member
Joined: 4 years ago

@orakel,

You should use the hook provided by us and add custom code for either displaying the first message or the second one.

how can i format this text inside the php echo?

You can add your custom HTML codes with some classes, then apply the CSS rules for those classes.

Orakel
Posts: 96
Topic starter
(@orakel)
Trusted Member
Joined: 1 year ago

Hello dear Asti

 

I know the problem with the different messages are not wpdiscuz related, but you are so very helpfull in all.

I am not a good coder but i try to learn. Would it be ok for you to give me an example how i can get this different messages?

 

Thanks in advance

Orakel

Orakel
Posts: 96
Topic starter
(@orakel)
Trusted Member
Joined: 1 year ago
Posted by: @orakel

echo "Comments are deactivated in this article";

Can you explain how i define a class into the echo command?

 

Orakel

2 Replies
Orakel
(@orakel)
Joined: 1 year ago

Trusted Member
Posts: 96

got it to work with the formating text and own css style ^^

 

image
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 3901

@orakel,

So, can we mark this topic as solved? 

Orakel
Posts: 96
Topic starter
(@orakel)
Trusted Member
Joined: 1 year ago

Hello Asti

 

If you can, i would still need help, with the different messages :/

 

Orakel

1 Reply
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 3901

@orakel,

use this code:

add_action("wpdiscuz_comment_form_closed", function ($post, $currentUser, $commentsCount) {
if (!empty($currentUser->ID) && in_array("banned", $currentUser->roles)) {
echo "you are locked and not possible to write a comment";
} else {
echo "Comments are deactivated in this article";
}
}, 10, 3);

Put it in the active theme functions.php file.

Orakel
Posts: 96
Topic starter
(@orakel)
Trusted Member
Joined: 1 year ago

Hello Asti

 

This works great, thank you very much =)

 

Orakel

Share: