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' => ...


4

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

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

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 ...


3

is_page() is not available at that point try using global $post that way the post ID should be available for comparison. add_filter( 'preprocess_comment', 'wpb_preprocess_comment' ); function wpb_preprocess_comment($comment) { global $post; if ((strlen( $comment['comment_content'] ) < 60 ) && ($post->ID == 42)) { wp_die('Minimum allowed ...


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

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

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

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

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

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 ); } ...


2

Because comment_status is not a built-in query argument - but you can easily implement it: function wpse_214323_query_by_comment_status( $where, $wp_query ) { global $wpdb; if ( ! empty( $wp_query->query_vars['comment_status'] ) ) { $status = $wp_query->query_vars['comment_status']; if ( $status !== 'open' ) ...


2

You probably can hack comments in somehow, but don't. Create a custom post type for your musicians using register_post_type() and including "comments" support. You can then create post type templates to customize the display: archive-{post_type}.php -- for archives single-{post_type}.php -- and for single posts ...


2

Note that with the following: add_filter ('comments_template', 'fbcommentbox', 100); we expect fbcommentbox() to return the path to the new comments template file. The default is the path of comments.php. If you create the fbcommentbox.php file in your theme, then you could try: add_filter( 'comments_template', 'fbcommentbox', 100); function ...


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, ...


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

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

In your comment callback, you could get that info with the help of the comment_parent property of the current $comment object. We can then use the comment_author() function to display the comment author's name: // Display the parent comment author's name: if( $comment->comment_parent ) comment_author( $comment->comment_parent ); and the ...


2

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 ...


2

By default WordPress organizes the comment pages from oldest to newest. This does not change, even if the Settings-Discussion options have been modified. This is the sticking point, one might suspect changing these settings to reorganize the comment pages, it doesn't. These settings, basically, define comment order in the default comment loop, and what page ...


2

If you use wp-comments-post.php it would be better to customize comment_form by hook comment_form_default_fields, I don't know why you create the new one. But as per of your functions you can handle it like this add_filter( 'preprocess_comment', 'verify_comment_meta_data', 1, 1 ); function verify_comment_meta_data( $commentdata ) { ...


2

There are several ways you can approach this. I wouldn't recommend deleting edit-comments.php as this is changing the core files, and your changes will be lost when you update WordPress. htaccess 301 Redirect /wp-admin/edit-comments.php http://www.example.com/wp-admin/ OR functions.php Part 1 // Redirect any user trying to access comments page function ...


2

In order to add a new comment you really only need a couple of fields and a POST method. In a typical comment form, requests are submitted to http://www.example.com/wp-comments-post.php which parses the $_POST data and sends it off to wp_handle_comment_submission. A POST method varies from a GET request in that params are usually sent in a non-visual way. ...


2

Using comment_notification_text you will get comment notification text and comment ID. To check the post type you need to get the post associated with comment and then you can check for post type Example (Read the inline comments): function custom_notificaion($notify_message, $comment_id) { $comment_obj = get_comment($comment_id); //Get comment object ...



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