Resetting comment count

Try this code: WARNING: THIS IS JUST PSEUDOCODE! $entries = $wpdb->get_results(“SELECT * FROM wp_posts WHERE post_type IN (‘post’, ‘page’)”); foreach($entries as $entry) { $post_id = $entry->ID; $comment_count = $wpdb->get_var(“SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = ‘$post_id’ AND comment_approved = ‘1’”); $wpdb->query(“UPDATE wp_posts SET comment_count=”$comment_count” WHERE ID = ‘$post_id'”); } Or you might want … Read more

Experiences with adding Nonces to the comment form

I haven’t done this personally, but it would be pretty easy. If you are building your comment form manually, just before the end of the </form> put: <?php wp_nonce_field( ‘comment_nonce’ ) ?> Then, just hook into the pre_comment_on_post action which fires when you submit a comment: add_action( ‘pre_comment_on_post’, ‘my_verify_comment_nonce’ ); function my_verify_comment_nonce() { check_admin_referer( ‘comment_nonce’ … Read more

Comment Walker vs. Comment Callback

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’ => new Walker_Comment, ‘callback’ => ‘bootstrap_comment_callback’, )); The Walker_Comment::start_el() method is just a wrapper for one of these protected methods: … Read more

Enable Submit Comment Without Page Reload (Using Ajax)?

Save the following javascrip file wpse54189-ajax-comments.js inside your plug-in folder – say plugins/plug-in-name/js (or if this must go your theme, in your theme folder). /* * jQuery autoResize (textarea auto-resizer) * @copyright James Padolsey http://james.padolsey.com * @version 1.04 */ (function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter(‘textarea’).each(function(){var c=a(this).css({resize:’none’,’overflow-y’:’hidden’}),k=c.height(),f=(function(){var l=[‘height’,’width’,’lineHeight’,’textDecoration’,’letterSpacing’],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr(‘id’).removeAttr(‘name’).css({position:’absolute’,top:0,left:-9999}).css(h).attr(‘tabIndex’,’-1′).insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css(‘overflow-y’,”);return}b.onResize.call(this);b.animate&&c.css(‘display’)===’block’?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind(‘.dynSiz’).bind(‘keyup.dynSiz’,g).bind(‘keydown.dynSiz’,g).bind(‘change.dynSiz’,g)});return this}})(jQuery); /* * Source: wp-comment-master WordPress Plugin * URL: http://wordpress.org/extend/plugins/wp-comment-master/ … Read more

Using WordPress’ WYSIWYG for comments

Give this a shot: <?php /* Add WYSISYG editor to comment form. */ add_filter( ‘comment_form_field_comment’, ‘wpse_64243_comment_editor’ ); function wpse_64243_comment_editor( $field ) { if (!is_single()) return $field; //only on single post pages. global $post; ob_start(); wp_editor( ”, ‘comment’, array( ‘textarea_rows’ => 15 ) ); $editor = ob_get_contents(); ob_end_clean(); //make sure comment media is attached to parent … Read more

How to enable comments for pending and draft posts?

The following enables the default meta box for draft and pending posts (in the portfolio post_type): add_action( ‘admin_init’, ‘wpse_74018_enable_draft_comments’ ); /** * Add Comments Meta Box if CPT is ‘draft’ or ‘pending’ */ function wpse_74018_enable_draft_comments() { if( isset( $_GET[‘post’] ) ) { $post_id = absint( $_GET[‘post’] ); $post = get_post( $post_id ); if ( ‘draft’ … Read more

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