I'm trying to run a function when deleting a comment. This entails hooking into "delete_comment" if I'm not mistaken.
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("[email protected]", "$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 );
wp_mail()
instead. Try running a simple test onwp_mail
first 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.wp-admin/admin-ajax.php
. Your own AJAX file doesn’t run in a WordPress context probably.