Are there events pub/sub for external application to subscribe to file/pdf uploads by wordpress admin

I have a scenario where a wp admin wants an external application to listen and detect when a pdf has been uploaded to a directory within wordpress.

Ex: a new terms and condition (T&C) document is created and the WP. The site admin upload this file to the sites T&C directory.

When the admin uploads this pdf is there any event emitted that an external application could have a webhook listening to pick up the addition/upload of the new file.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use the action add_attachment, and look at the MIME type, then do whatever you need:

add_action( 'add_attachment', function( $post_id ) {
    
    if ( 'application/pdf' !== get_post_mime_type( $post_id ) ) {
        return;
    }
    
    // Here you can update a static file, send a HTTP 
    // request to the other site or send an email.
});


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x