Hot answers tagged

5

I was curious about any existing plugins and searched the plugin directory. There exists an old Sticky Comments plugin, I'm not related to it. It seems to use a sticky meta key. It uses a LEFT JOIN query but creates it's own version of the whole comments_template() core function, to override the current query. One would need to update that custom function, ...


5

Note that the function wp_list_comments() doesn't fetch the comments, only displays them in various ways depending on the input arguments. You're actually using the WP_Comment_Query/get_comments input arguments into wp_list_comments(). You could try this instead: $postID = 12345; // Adjust this! $comments = get_comments( [ 'date_query' => ...


5

Comment.php The way I see your comment.php seems messy and more complex than it needs to be, you can post this piece of code to in your comment.php and it should work okay. <?php /** * If the current post is protected by a password and * the visitor has not yet entered the password we will * return early without loading the commend */ if (...


4

What you need to use here is the WP_Comment_Query() function. So on the author.php page, you can easily get the author info and ID as followed: // get author info $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); // set ID $user_id = $curauth->ID; Then we add the user ID in the query ...


4

Refrain from editing core files WordPress was developed with extensibility in mind, and provides many ways to change the appearance and functionality of an installation without altering the WordPress software itself (mostly using Hooks in conjunction with Plugins and Themes). The software is comprised of it's "core files", which are generally everything ...


4

It's not a bug (gasp!) really just not provided for. You have to add a filter to do this, eg add_filter( 'comments_clauses', function ( $pieces, $query ) { if ( empty( $query->query_vars['wpse_no_password'] ) ) return $pieces; global $wpdb; $pieces[ 'where' ] .= $wpdb->prepare( ' AND ' . $wpdb->posts . '.post_password = %s', '' ); ...


4

We can use comment_form function's submit_button parameter to change submit button HTML. Default HTML for submit_button is <input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" /> You can change your code like this. $comments_args = array( .... 'submit_button' => '<div class="form-group"> <input name="...


3

WordPres will not allow you, using its default comment process, to insert empty comments into the database. This is enforced by wp_handle_comment_submission() with the following unconditional code: if ( '' == $comment_content ) { return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); } ...


3

The alternative way to handle this problem is to use paginate_links() with get_comments() (or any similar query). Specifically to get the equivalent of max_num_pages, you can use the built-in function wp_count_comments(). So, to get your maximum number of pages, you'd first produce a count of all the comments you want. Presuming you don't want unapproved ...


3

For flexibility, you could assign the CSS bubblecount class to the corresponding menu item: and then target it with: if( in_array( 'bubblecount', (array) $item->classes ) ) $output .= '<span class="unread">'.my_function_here().'</span>'; in your code snippet above.


3

You won't get a comment ID until the post is is inserted into the database. Before that point, the ID doesn't exist. You have to use a hook that fires after that event... 1735 /** 1736 * Fires immediately after a comment is inserted into the database. 1737 * 1738 * @since 1.2.0 1739 * 1740 ...


3

If you need to modify the max depth, you could use the thread_comments_depth_max filter: /** * Set max comments depth to 15 on the discussion settings page */ add_filter( 'thread_comments_depth_max', function( $max ) { return 15; } ); then the dropdown on the discussion settings page will show the range 1 - 15. But I can imagine very deep comment ...


3

Lets try the following: By default, all posts are returned regardless of comment_status, so lets run the main query as normal, that is, query all posts regardless of comment_status. We will also run a small, but very lean secondary query where we will get all posts which have a comment_status of closed which have a meta value of not yes The returned ...


3

We could rewrite: wp_list_comments( array( 'callback' => 'bootstrap_comment_callback', )); with the null walker parameter: wp_list_comments( array( 'walker' => null, 'callback' => 'bootstrap_comment_callback', )); which means we are using the default Walker_Comment class: wp_list_comments( array( 'walker' ...


3

Here are some options on how we can override the native layout for each comment: Approach #1 - Overriding start_el() with a custom walker Let's define our custom wpse comment format: // Arguments for wp_list_comments() $args = [ 'style' => 'ol', 'format' => 'html5', 'short_ping' => true, ]; // Use our custom walker if it'...


3

Yes, possible. Add this to your theme's functions.php file- add_filter( 'get_comment_text', 'replace_comment_texts' ); function replace_comment_texts() { return "This comment is hidden"; } I have written a plugin few days back, that does the exact thing. You can try this too- https://wordpress.org/plugins/mask-comments/


3

Here are a few functions that make use of WP_Comment_Query to pull the user's Comments, then loop through to find any replies, and trash them all. $current_user = wp_get_current_user(); $deleteReplies = true; $force_delete = false; deleteUserComments ( $current_user->ID, $deleteReplies, $force_delete ); If you want to test this without permanently ...


3

Please place below code in your theme's functions.php file and it will wrap the submit button inside div: // define the comment_form_submit_button callback function filter_comment_form_submit_button( $submit_button, $args ) { // make filter magic happen here... $submit_before = '<div class="form-group">'; $submit_after = '</div>'; ...


3

Currently it is not available in WP CLI. See https://github.com/wp-cli/wp-cli/blob/master/php/commands/comment.php#L136 If you want, you can have your own customized comment generation command. See command cookbook. http://wp-cli.org/docs/commands-cookbook/


2

I've often thought this would make a good feature, though I've never seen a plugin for it. I think the term "comment" is probably throwing off your search. I wouldn't think that this would be stored as a comment internally, but rather as metadata for the post. I did a search for plugins using the term "revision description" instead of revision comment, and I ...


2

Re: random avatar generation, this was an extremely helpful answer and worked a treat with one minor modification - the function in question required an argument to pass through. Without the argument, the code returned included a jumble of html which included both the desired url of the image, as well as url of the default icon from gravitar. I changed it ...


2

This deserves a new answer, because the answer is simple. WordPress is written in the programming language PHP. The date formatting functions in WordPress use PHP's built-in date formatting functions. This quote can be found on the wordpress codex here This information is super important because PHP has the following formatting tag 'U' The ...


2

Post authors are notified of new comments by default; there are several plugins that modify this behavior. See wp_notify_postauthor. You can hook into comment_notification_recipients and add an aribtrary list of recipients as described here. Then you could create a metabox or dashboard widget to manage the recipient list. Keep in mind that this ...


2

You're re-inventing the wheel here ;-) The Problem You're bypassing WordPress with this approach, so that's explains the error message. Accessing any custom file, within your theme directory, will not load WordPress core automatically. Already available This is already supported by the WordPress core. You should check out comments_popup_link() and ...


2

Add following code in your theme's functions.php. // To add extra column in column headers add_filter('manage_posts_columns', 'bs_event_table_head'); function bs_event_table_head( $defaults ) { $defaults['pending_comments'] = 'Pending Comments'; return $defaults; } // To add data in column for each post. add_action( 'manage_posts_custom_column', '...


2

From 4.4 on this seems to get easier with a brand-new filter: feed_links_show_posts_feed. So add_filter( 'feed_links_show_comments_feed', '__return_false' ); will do then.


2

Here are three different methods to modify the trash count, to 999 as an example: Method #1 The views_edit-comments filter: add_filter( 'views_edit-comments', function( $views ) { $trash_count = 999; // <-- Adjust this count // Override the 'trash' link: $views['trash'] = sprintf( "<a href=%s>%s <span class='count'>(<...


2

Note that it might be easier to use get_comments() here, since it's defined as: function get_comments( $args = '' ) { $query = new WP_Comment_Query; return $query->query( $args ); } If you need the comment url, within your foreach comment loop, you can use: $comment_url = esc_url( get_comment_link( $comment ) ); You can also get the post id ...


2

You can pass the number argument to get_comments() to retrieve only a specific number of comments. They will, by standard, be sorted descending, so you get the latest comments first. As WordPress automatically seperates comments for each post, you will not have to worry about mixing comments up. This seems to be the easiest way for me. Multiple comment ...


2

Finally I figured it out. you may simply add your arguments to the wp_list_comments as associative key => value pairs like this: $args = array( 'callback' => 'my_callback', 'avatar_size' => 48, 'type' => 'comment', 'arg1' => $arg1 ); wp_list_comments( $args ); and then in your my_callback you have: function my_callback( $comment, $args, $...



Only top voted, non community-wiki answers of a minimum length are eligible