WordPress hack: Insert comments programatically

The following code can be pasted anywhere on your theme files.
Once this code is executed, it will add a new comment into WordPress database. The returned value is the comment ID, or 0 if a problem happenned.

$data = array(
	'comment_post_ID' => 1,
	'comment_author' => 'admin',
	'comment_author_email' => 'admin@admin.com',
	'comment_author_url' => 'http://www.catswhocode.com',
	'comment_content' => 'Lorem ipsum dolor sit amet...',
	'comment_author_IP' => '127.0.0.1',
	'comment_agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3',
	'comment_date' => date('Y-m-d H:i:s'),
	'comment_date_gmt' => date('Y-m-d H:i:s'),
	'comment_approved' => 1,
);

$comment_id = wp_insert_comment($data);

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

Read the Complete Article

Daily Email Newsletters

Weekly Email Newsletters

Subscribe to receive the latest design and creative business news, tutorials, and resources delivered to you via email—either daily (below) or weekly, to your computer, tablet, or mobile phone.

IMPORTANT NOTE: The newsletters and subscription confirmation email will be sent from the address briefing@iampariah.com. Please be sure to whitelist that address in your anti-spam filters. Check your Junk Mail or Spam folder if you miss an email prior to whitelisting briefing@iampariah.com.

Privacy and CAN-SPAM Compliance

All Pariah Burke newsletters comply with the U.S. CAN-SPAM Act. The newsletter even uses a third-party ESP to audit and ensure its compliance with CAN-SPAM. And your privacy is assured: your email address and other information will never be sold or given away.