Advertisement
Guest User

Untitled

a guest
Nov 7th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. add_action('admin_init', 'redirect_after_media_save');
  2. function redirect_after_media_save() {
  3.  
  4.     global $pagenow;
  5.  
  6.     // when visiting the upload screen, we save the number of attachments
  7.     if ( $pagenow == 'media-new.php' ) {
  8.         $attachments_before = array_sum((array)wp_count_attachments());
  9.         update_option('count_attach_before', $attachments_before);
  10.     }
  11.  
  12.     if ( $pagenow == 'upload.php' ) { // we are on media library page
  13.  
  14.         // get attachments count before and after upload
  15.         $attachments_before = get_option('count_attach_before');
  16.         $attachments_after = array_sum((array)wp_count_attachments());
  17.  
  18.         if (
  19.             // there are new files uploaded
  20.             ( wp_get_referer() == admin_url('media-new.php') && $attachments_after > $attachments_before )
  21.         ) {
  22.                 // send admin email
  23.                 wp_mail( $to, $subject, $message, $headers, $attachments );
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement