if user role is then echo text

You are passing a role name, administrator, to current_user_can. Looking at the Codex page this is supported but not guaranteed to work, and should generally be avoided: Passing role names to current_user_can() is discouraged as this is not guaranteed to work correctly (see #22624). Instead, you should use a capability: if ( current_user_can( ‘manage_options’ ) … Read more

How to check if a comment has replies?

Here’s one example how to construct such a custom function: /** * Check if a comment has children. * * @param int $comment_id Comment ID * @return bool Has comment children. */ function has_comment_children_wpse( $comment_id ) { return get_comments( [ ‘parent’ => $comment_id, ‘count’ => true ] ) > 0; } using the get_comments() function … Read more

Ajax submit comments

you might find these links handy if you’re going to code it yourself http://byronyasgur.wordpress.com/2011/06/27/frontend-forward-facing-ajax-in-wordpress/ http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/ I am fairly sure your URL is wrong url: “../wp-comments-post.php” – ajax in wordpress has to be sent (quite strangely) to/through admin-ajax.php (even if it’s not on the admin side). If you read the first link it is explained in … Read more

Getting comment count per post not working

Try this: <?php $popular = new WP_Query(‘orderby=comment_count&posts_per_page=5’); ?> <?php while ($popular->have_posts()) : $popular->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/108038/<?php the_permalink(); ?>”><?php the_title(); ?></a> has <?php comments_number( ‘no responses’, ‘one response’, ‘% responses’ ); ?>.</li> <?php endwhile; ?> From the codex.

“Discussion” checkboxes unchecked by default on pages? [duplicate]

You can re-register the “page” post type and leave out the comments capability. add_action( ‘init’, ‘my_new_page_type’ ); function my_new_page_type() { register_post_type( ‘page’, array( ‘labels’ => array( ‘name_admin_bar’ => _x( ‘Page’, ‘add new on admin bar’ ), ), ‘public’ => true, ‘publicly_queryable’ => false, ‘_builtin’ => true, /* internal use only. don’t use this when registering … Read more

How to hide trackbacks on wp-admin/edit-comments.php

While this is not impossible, this is very likely to have ton of edge cases and backfire in some. In a nutshell comments are retrieved with comment query, which can be adjusted with something like this (if in admin and comment type not specified then only fetch normal comments): add_action( ‘pre_get_comments’, ‘exclude_pings’ ); function exclude_pings( … Read more