Plugin Directory

Changeset 408875


Ignore:
Timestamp:
07/12/2011 07:06:17 PM (14 years ago)
Author:
junkcoder
Message:

Add option to only rebuild post thumbnails (featured image)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ajax-thumbnail-rebuild/trunk/ajax-thumbnail-rebuild.php

    r407551 r408875  
    5757            }
    5858
     59            var onlypostthumbs = jQuery("#onlypostthumbs").attr('checked') ? 1 : 0;
     60
    5961            jQuery.ajax({
    6062                url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
    6163                type: "POST",
    62                 data: "action=ajax_thumbnail_rebuild&do=getlist",
     64                data: "action=ajax_thumbnail_rebuild&do=getlist&onlypostthumbs="+onlypostthumbs,
    6365                success: function(result) {
    6466                    var list = eval(result);
     
    130132            <?php endforeach;?>
    131133            </p>
     134            <p>
     135                <input type="checkbox" id="onlypostthumbs" name="onlypostthumbs" />
     136                <label>Only rebuild post thumbnails</label>
     137            </p>
     138
    132139            <input type="button" onClick="javascript:regenerate();" class="button"
    133140                   name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild"
     
    150157
    151158function ajax_thumbnail_rebuild_ajax() {
     159    global $wpdb;
     160
    152161    $action = $_POST["do"];
    153162    $thumbnails = isset( $_POST['thumbnails'] )? $_POST['thumbnails'] : NULL;
     163    $onlypostthumbs = isset( $_POST['onlypostthumbs'] ) ? $_POST['onlypostthumbs'] : 0;
    154164
    155165    if ($action == "getlist") {
    156         $attachments =& get_children( array(
    157             'post_type' => 'attachment',
    158             'post_mime_type' => 'image',
    159             'numberposts' => -1,
    160             'post_status' => null,
    161             'post_parent' => null, // any parent
    162             'output' => 'object',
    163         ) );
     166
     167        if ($onlypostthumbs) {
     168            /* Get all featured images */
     169            $featured_images = $wpdb->get_results( "SELECT meta_value FROM {$wpdb->postmeta}
     170                                                WHERE meta_key = '_thumbnail_id'" );
     171
     172            $thumbs = array();
     173            foreach($featured_images as $image) {
     174                array_push($thumbs, $image->meta_value);
     175            }
     176            $attachments =& get_children( array(
     177                'post_type' => 'attachment',
     178                'post_mime_type' => 'image',
     179                'numberposts' => -1,
     180                'post_status' => null,
     181                'post_in' => $thumbs,
     182                'output' => 'object',
     183            ) );
     184
     185        } else {
     186            $attachments =& get_children( array(
     187                'post_type' => 'attachment',
     188                'post_mime_type' => 'image',
     189                'numberposts' => -1,
     190                'post_status' => null,
     191                'post_parent' => null, // any parent
     192                'output' => 'object',
     193            ) );
     194        }
    164195
    165196        foreach ( $attachments as $attachment ) {
Note: See TracChangeset for help on using the changeset viewer.