In Wordpress admin media library page (upload.php) I'd like to do some checking on delete_attachment action.
I want my custom function to fire before attachment's being deleted.
In this function I want to check for it's relations with another objects in database. And delete it only if there are no relations at all.
I use this code (in functions.php) to see if my function is fired on delete_attachment:
<code>
add_action( 'delete_attachment', 'check_relations' );
function check_relations( $post_id ){
?>
<script>
function myFunction() {
alert("Hello! I am an alert box!");
}
</script>
<?php
}
</code>
but it seems that my function's not firing at all. And image attachment is being completely deleted. What's wrong in this code?