I'm pretty new to plugins and trying to run a function when deleting a comment. This entails hooking into "delete_comment" if I'm not mistaken.
http://hitchhackerguide.com/2011/02/12/wp_delete_comment/
Theoretically, this should work as a plugin, so when you delete a comment, it emails me. But when I install and activate it, nothing happens when I delete a comment. I hard coded the email function into ajax-actions.php and it works, but I think the idea is to have all the functions in the plugin file if possible. What am I missing here? Am I missing a do_action somewhere?
add_action( 'delete_comment', 'do_something', 10 ,1);
function do_something($comment_id) {
mail("me@domain.com", "$comment_id","$comment_id");
}
Note: If I require() the plugin file and call do_something() from /wp-admin/includes/ajax-actions.php, it works...
function wp_ajax_delete_comment() {
...
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
if ( 'trash' == $status )
wp_die( time() );
// BEGIN INSERT
require_once( plugin-file.php' );
do_something($comment->comment_ID); // THIS WORKS FINE
// END INSERT
$r = wp_trash_comment( $comment->comment_ID );
}
comment_to_post($comment->comment_ID);
...
}
Is wp-admin/includes/ajax-actions.php NOT a part of the regular WP install and not in the scope that you can hook into?
mail()function is working on your server in the first place? Try doing something else inside that function, likeupdate_option( 'test_option', $comment_id );– EAMann♦ Oct 23 '12 at 19:34wp_mail()instead. Try running a simple test onwp_mailfirst to see if you receive any email. You want to determine its actually working. If not, you may need to specify your mail server settings in the php.ini file. But I suspect the latter is not your problem. – userabuser Oct 23 '12 at 19:46wp-admin/admin-ajax.php. Your own AJAX file doesn’t run in a WordPress context probably. – toscho♦ Oct 23 '12 at 20:21