Are there events pub/sub for external application to subscribe to file/pdf uploads by wordpress admin
-
22-04-2021 - |
Вопрос
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.
Решение
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.
});
Не связан с wordpress.stackexchange