Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  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. +?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement