Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 2nd, 2012  |  syntax: PHP  |  size: 2.32 KB  |  views: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Index: regenerate-thumbnails.php
  2. ===================================================================
  3. --- regenerate-thumbnails.php   (revision 49478)
  4. +++ regenerate-thumbnails.php   (revision 49749)
  5. @@ -164,7 +164,18 @@
  6.                                 // Directly querying the database is normally frowned upon, but all
  7.                                 // of the API functions will return the full post objects which will
  8.                                 // suck up lots of memory. This is best, just not as future proof.
  9. -                               if ( ! $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC" ) ) {
  10. +
  11. +                               // If a month was selected, let's validate it and plug it into query.
  12. +                               // The month date should be in format YYYY/MM
  13. +                               if ( ! empty( $_POST['regenerate-thumbnails-date'] ) ) {
  14. +                                       if ( preg_match( '/(\d{4})\/(\d{2})/', $_POST['regenerate-thumbnails-date'], $date_parts ) ) {
  15. +                                               $month = $date_parts[1] . '/' . $date_parts[2];
  16. +                                       }
  17. +                               }
  18. +                               // Next, build the SQL to inject into query
  19. +                               $where_date = !empty( $month ) ? "AND DATE_FORMAT(post_date, '%Y/%m') = '$month'" : "";
  20. +
  21. +                               if ( ! $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' $where_date ORDER BY ID DESC" ) ) {
  22.                                         echo '  <p>' . sprintf( __( "Unable to find any images. Are you sure <a href='%s'>some exist</a>?", 'regenerate-thumbnails' ), admin_url( 'upload.php?post_mime_type=image' ) ) . "</p></div>";
  23.                                         return;
  24.                                 }
  25. @@ -327,6 +338,10 @@
  26.  
  27.         <p><?php _e( 'To begin, just press the button below.', 'regenerate-thumbnails '); ?></p>
  28.  
  29. +       <p>
  30. +               <?php _e( 'Month to regenerate, in format YYYY/MM (leave blank to include all images)', 'regenerate-thumbnails' ); ?>
  31. +               <input type="textfield" class="hide-if-no-js" name="regenerate-thumbnails-date" id="regenerate-thumbnails-date" value="<?php print date('Y/m'); ?>" />
  32. +       </p>
  33.         <p><input type="submit" class="button hide-if-no-js" name="regenerate-thumbnails" id="regenerate-thumbnails" value="<?php _e( 'Regenerate All Thumbnails', 'regenerate-thumbnails' ) ?>" /></p>
  34.  
  35.         <noscript><p><em><?php _e( 'You must enable Javascript in order to proceed!', 'regenerate-thumbnails' ) ?></em></p></noscript>
  36. @@ -396,4 +411,4 @@
  37.         $RegenerateThumbnails = new RegenerateThumbnails();
  38.  }
  39.  
  40. -?>
  41. \ No newline at end of file
  42. +?>