Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('admin_init', 'redirect_after_media_save');
- function redirect_after_media_save() {
- global $pagenow;
- // when visiting the upload screen, we save the number of attachments
- if ( $pagenow == 'media-new.php' ) {
- $attachments_before = array_sum((array)wp_count_attachments());
- update_option('count_attach_before', $attachments_before);
- }
- if ( $pagenow == 'upload.php' ) { // we are on media library page
- // get attachments count before and after upload
- $attachments_before = get_option('count_attach_before');
- $attachments_after = array_sum((array)wp_count_attachments());
- if (
- // there are new files uploaded
- ( wp_get_referer() == admin_url('media-new.php') && $attachments_after > $attachments_before )
- ) {
- // send admin email
- wp_mail( $to, $subject, $message, $headers, $attachments );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement