What’s the easiest way to close comments on media/attachments?

This ought to do it: function wpse15750_comment_check( $id ){ if( get_post_type( $id ) == ‘attachment’ ) exit; } add_action( ‘pre_comment_on_post’, ‘wpse15750_comment_check’ ); EDIT Ignore the above. That will stop new comments, but to do what you want, this is much better: function wpse15750_comments_closed( $open, $id ){ if( get_post_type( $id ) == ‘attachment’ ) return false; … Read more

Comment visibility

By using the ‘pre_get_comments’ action, found in wp-includes/comment.php: function restrict_visible_comments( $comments_query ) { if ( !is_singular() ) return; if ( current_user_can( ‘moderate_comments’ ) ) return; // moderators can see all comments if ( get_current_user_id() == get_queried_object()->post_author ) return; // the author of the post can see all comments $comments_query->query_vars[‘user_id’] = get_current_user_id(); } if ( !is_admin() … Read more

How to use a custom comments template

The comments_template() template tag sets up the commenting variables and functions, and includes the comments.php template-part file. So, to create a custom comments template, use comments.php. From there, you will need to get comfortable with the arguments, filters, and callbacks for wp_list_comments(), which is used to output the comment list, and comment_form(), which is used … Read more

Disable saving comment details (name, e-mail) in cookie?

That is actually dead simple. Cookies are set by wp_set_comment_cookies() and this function is hooked into ‘set_comment_cookies’. Just remove the function from the action: <?php # -*- coding: utf-8 -*- /* Plugin Name: No Comment Cookies */ remove_action( ‘set_comment_cookies’, ‘wp_set_comment_cookies’ ); Download on GitHub.

Writing a plugin that notify my friends of new post that mentions(@) them

Twice edited according to kaiser’s suggestions, unsecure version removed. <?php function my_email_friend($post_id = ”) { // get post object $post = get_post($post_id); // get post content $content = $post->post_content; // if @David exists if( 0 !== preg_match(‘/(@\w)/’, $content, $matches) ) $friend_display_name_like=”%” . like_escape($matches[0]) . ‘%’; else return; // do nothing if no matches global $wpdb; … Read more

One comment per user per post but be able to reply to existing comments

So after some time I done exactly what I wanted and I thought it would be nice to share. So in functions.php add function c_parent_comment_counter($pid,$uid){ global $wpdb; $query = “SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE <code>comment_approved</code> = 1 AND <code>comment_post_ID</code> = $pid AND <code>user_id</code> = $uid AND <code>comment_parent</code> = 0”; $parents = $wpdb->get_row($query); return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)