__( 'Ajax Thumbnail Rebuild', 'ajax-thumbnail-rebuild' ), 'input' => 'html', 'html' => $html ); return $fields; } function ManagementPage() { ?>

:


', ''); ?>

get_results( "SELECT meta_value, {$wpdb->posts}.post_title AS title FROM {$wpdb->postmeta}, {$wpdb->posts} WHERE meta_key = '_thumbnail_id' AND {$wpdb->postmeta}.post_id={$wpdb->posts}.ID ORDER BY post_date DESC"); foreach( $featured_images as $image ) { $res[] = array( 'id' => $image->meta_value, 'title' => $image->title ); } } else { $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null, // any parent 'output' => 'object', 'orderby' => 'post_date', 'order' => 'desc' ) ); foreach ( $attachments as $attachment ) { $res[] = array( 'id' => $attachment->ID, 'title' => $attachment->post_title ); } } die( json_encode( $res ) ); } else if ($action == "regen") { $id = $_POST["id"]; $fullsizepath = get_attached_file( $id ); if ( FALSE !== $fullsizepath && @file_exists( $fullsizepath ) ) { set_time_limit( 30 ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata_custom( $id, $fullsizepath, $thumbnails ) ); die( wp_get_attachment_thumb_url( $id )); } die( '-1' ); } } add_action( 'wp_ajax_ajax_thumbnail_rebuild', 'ajax_thumbnail_rebuild_ajax' ); add_action( 'plugins_loaded', function() { global $ajax_thumbnail_rebuild; $ajax_thumbnail_rebuild = new AjaxThumbnailRebuild(); }); function ajax_thumbnail_rebuild_get_sizes() { global $_wp_additional_image_sizes; foreach ( get_intermediate_image_sizes() as $s ) { $sizes[$s] = array( 'name' => '', 'width' => '', 'height' => '', 'crop' => FALSE ); /* Read theme added sizes or fall back to default sizes set in options... */ $sizes[$s]['name'] = $s; if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) { $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); } else { $sizes[$s]['width'] = get_option( "{$s}_size_w" ); } if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) { $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); } else { $sizes[$s]['height'] = get_option( "{$s}_size_h" ); } if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) { if( ! is_array( $sizes[$s]['crop'] ) ) { $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); } else { $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; } } else { $sizes[$s]['crop'] = get_option( "{$s}_crop" ); } } $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); return $sizes; } /** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = NULL ) { $attachment = get_post( $attachment_id ); $metadata = array(); if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) { $imagesize = getimagesize( $file ); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = sprintf( "height='%s' width='%s'", $uheight, $uwidth ); // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path( $file ); $sizes = ajax_thumbnail_rebuild_get_sizes(); foreach ( $sizes as $size => $size_data ) { if( isset( $thumbnails ) && ! in_array( $size, $thumbnails ) ) { $intermediate_size = image_get_intermediate_size( $attachment_id, $size_data['name'] ); } else { $intermediate_size = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] ); } if ( $intermediate_size ) { $metadata['sizes'][$size] = $intermediate_size; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata( $file ); if ( $image_meta ) { $metadata['image_meta'] = $image_meta; } } return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); } load_plugin_textdomain( 'ajax-thumbnail-rebuild', false, basename( dirname( __FILE__ ) ) . '/languages' );