0

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:

add_action( 'delete_attachment', 'check_relations' );
function check_relations( $post_id ){
    ?>  
    <script>
        function myFunction() {
            alert("Hello! I am an alert box!");
        }
    </script>
    <?php
}

but it seems that my function's not firing at all. And image attachment is being completely deleted. What's wrong in this code?

2

Have you seen this ? https://stackoverflow.com/a/28429009/3967385

Actually you can't fire JavaScript with php simply like that.

  • Actually it looks like the same question and as it is accepted over there at stackoverflow I think she saw this. Never the less, good to have a reference to the answer of this cross post. Therefore +1. – David Aug 19 '15 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.