edit pages
This commit is contained in:
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 292 B |
@ -0,0 +1,32 @@
|
||||
/* This is based on jQuery UI */
|
||||
#regenerate-thumbnails-app .ui-progressbar {
|
||||
height: 2em;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-progressbar .ui-progressbar-value {
|
||||
margin: -1px;
|
||||
height: 100%;
|
||||
transition-duration: 0.5s;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-widget.ui-widget-content {
|
||||
border: 1px solid #c5dbec;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-widget-content {
|
||||
border: 1px solid #a6c9e2;
|
||||
background: #fcfdfd url("images/ui-bg_inset-hard_100_fcfdfd_1x100.png") 50% bottom repeat-x;
|
||||
color: #222222;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-widget-header {
|
||||
border: 1px solid #4297d7;
|
||||
background: #5c9ccc url("images/ui-bg_gloss-wave_55_5c9ccc_500x100.png") 50% 50% repeat-x;
|
||||
color: #ffffff;
|
||||
font-weight: bold;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-corner-all {
|
||||
border-radius: 5px;
|
||||
}
|
||||
#regenerate-thumbnails-app .ui-corner-left {
|
||||
border-top-left-radius: 5px;
|
||||
border-bottom-left-radius: 5px;
|
||||
}
|
2
old/wp-content/plugins/regenerate-thumbnails/dist/build.js
vendored
Normal file
2
old/wp-content/plugins/regenerate-thumbnails/dist/build.js
vendored
Normal file
File diff suppressed because one or more lines are too long
5
old/wp-content/plugins/regenerate-thumbnails/dist/build.js.LICENSE.txt
vendored
Normal file
5
old/wp-content/plugins/regenerate-thumbnails/dist/build.js.LICENSE.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/*!
|
||||
* Vue.js v2.6.11
|
||||
* (c) 2014-2019 Evan You
|
||||
* Released under the MIT License.
|
||||
*/
|
@ -0,0 +1,710 @@
|
||||
<?php
|
||||
/**
|
||||
* Regenerate Thumbnails: Attachment regenerator class
|
||||
*
|
||||
* @package RegenerateThumbnails
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Regenerates the thumbnails for a given attachment.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class RegenerateThumbnails_Regenerator {
|
||||
|
||||
/**
|
||||
* The WP_Post object for the attachment that is being operated on.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @var WP_Post
|
||||
*/
|
||||
public $attachment;
|
||||
|
||||
/**
|
||||
* The full path to the original image so that it can be passed between methods.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $fullsizepath;
|
||||
|
||||
/**
|
||||
* An array of thumbnail size(s) that were skipped during regeneration due to already existing.
|
||||
* A class variable is used so that the data can later be used to merge the size(s) back in.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $skipped_thumbnails = array();
|
||||
|
||||
/**
|
||||
* The metadata for the attachment before the regeneration process starts.
|
||||
*
|
||||
* @since 3.1.6
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $old_metadata = array();
|
||||
|
||||
/**
|
||||
* Generates an instance of this class after doing some setup.
|
||||
*
|
||||
* MIME type is purposefully not validated in order to be more future proof and
|
||||
* to avoid duplicating a ton of logic that already exists in WordPress core.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param int $attachment_id Attachment ID to process.
|
||||
*
|
||||
* @return RegenerateThumbnails_Regenerator|WP_Error A new instance of RegenerateThumbnails_Regenerator on success, or WP_Error on error.
|
||||
*/
|
||||
public static function get_instance( $attachment_id ) {
|
||||
$attachment = get_post( $attachment_id );
|
||||
|
||||
if ( ! $attachment ) {
|
||||
return new WP_Error(
|
||||
'regenerate_thumbnails_regenerator_attachment_doesnt_exist',
|
||||
__( 'No attachment exists with that ID.', 'regenerate-thumbnails' ),
|
||||
array(
|
||||
'status' => 404,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// We can only regenerate thumbnails for attachments.
|
||||
if ( 'attachment' !== get_post_type( $attachment ) ) {
|
||||
return new WP_Error(
|
||||
'regenerate_thumbnails_regenerator_not_attachment',
|
||||
__( 'This item is not an attachment.', 'regenerate-thumbnails' ),
|
||||
array(
|
||||
'status' => 400,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Don't touch any attachments that are being used as a site icon. Their thumbnails are usually custom cropped.
|
||||
if ( self::is_site_icon( $attachment ) ) {
|
||||
return new WP_Error(
|
||||
'regenerate_thumbnails_regenerator_is_site_icon',
|
||||
__( "This attachment is a site icon and therefore the thumbnails shouldn't be touched.", 'regenerate-thumbnails' ),
|
||||
array(
|
||||
'status' => 415,
|
||||
'attachment' => $attachment,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return new RegenerateThumbnails_Regenerator( $attachment );
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor for this class. Don't call this directly, see get_instance() instead.
|
||||
* This is done so that WP_Error objects can be returned during class initiation.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_Post $attachment The WP_Post object for the attachment that is being operated on.
|
||||
*/
|
||||
private function __construct( WP_Post $attachment ) {
|
||||
$this->attachment = $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the attachment is or was a site icon.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_Post $attachment The WP_Post object for the attachment that is being operated on.
|
||||
*
|
||||
* @return bool Whether the attachment is or was a site icon.
|
||||
*/
|
||||
public static function is_site_icon( WP_Post $attachment ) {
|
||||
return ( 'site-icon' === get_post_meta( $attachment->ID, '_wp_attachment_context', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the fullsize attachment.
|
||||
*
|
||||
* @return string|WP_Error The path to the fullsize attachment, or a WP_Error object on error.
|
||||
*/
|
||||
public function get_fullsizepath() {
|
||||
if ( $this->fullsizepath ) {
|
||||
return $this->fullsizepath;
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_get_original_image_path' ) ) {
|
||||
$this->fullsizepath = wp_get_original_image_path( $this->attachment->ID );
|
||||
} else {
|
||||
$this->fullsizepath = get_attached_file( $this->attachment->ID );
|
||||
}
|
||||
|
||||
if ( false === $this->fullsizepath || ! file_exists( $this->fullsizepath ) ) {
|
||||
$error = new WP_Error(
|
||||
'regenerate_thumbnails_regenerator_file_not_found',
|
||||
sprintf(
|
||||
/* translators: The relative upload path to the attachment. */
|
||||
__( "The fullsize image file cannot be found in your uploads directory at <code>%s</code>. Without it, new thumbnail images can't be generated.", 'regenerate-thumbnails' ),
|
||||
_wp_relative_upload_path( $this->fullsizepath )
|
||||
),
|
||||
array(
|
||||
'status' => 404,
|
||||
'fullsizepath' => _wp_relative_upload_path( $this->fullsizepath ),
|
||||
'attachment' => $this->attachment,
|
||||
)
|
||||
);
|
||||
|
||||
$this->fullsizepath = $error;
|
||||
}
|
||||
|
||||
return $this->fullsizepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the thumbnails for this instance's attachment.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array|string $args {
|
||||
* Optional. Array or string of arguments for thumbnail regeneration.
|
||||
*
|
||||
* @type bool $only_regenerate_missing_thumbnails Skip regenerating existing thumbnail files. Default true.
|
||||
* @type bool $delete_unregistered_thumbnail_files Delete any thumbnail sizes that are no longer registered. Default false.
|
||||
* }
|
||||
*
|
||||
* @return mixed|WP_Error Metadata for attachment (see wp_generate_attachment_metadata()), or WP_Error on error.
|
||||
*/
|
||||
public function regenerate( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'only_regenerate_missing_thumbnails' => true,
|
||||
'delete_unregistered_thumbnail_files' => false,
|
||||
) );
|
||||
|
||||
$fullsizepath = $this->get_fullsizepath();
|
||||
if ( is_wp_error( $fullsizepath ) ) {
|
||||
$fullsizepath->add_data( array( 'attachment' => $this->attachment ) );
|
||||
|
||||
return $fullsizepath;
|
||||
}
|
||||
|
||||
$this->old_metadata = wp_get_attachment_metadata( $this->attachment->ID );
|
||||
|
||||
if ( $args['only_regenerate_missing_thumbnails'] ) {
|
||||
add_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_image_sizes_to_only_missing_thumbnails' ), 10, 2 );
|
||||
}
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
|
||||
$new_metadata = wp_generate_attachment_metadata( $this->attachment->ID, $fullsizepath );
|
||||
|
||||
if ( $args['only_regenerate_missing_thumbnails'] ) {
|
||||
// Thumbnail sizes that existed were removed and need to be added back to the metadata.
|
||||
foreach ( $this->skipped_thumbnails as $skipped_thumbnail ) {
|
||||
if ( ! empty( $this->old_metadata['sizes'][ $skipped_thumbnail ] ) ) {
|
||||
$new_metadata['sizes'][ $skipped_thumbnail ] = $this->old_metadata['sizes'][ $skipped_thumbnail ];
|
||||
}
|
||||
}
|
||||
$this->skipped_thumbnails = array();
|
||||
|
||||
remove_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_image_sizes_to_only_missing_thumbnails' ), 10 );
|
||||
}
|
||||
|
||||
$wp_upload_dir = dirname( $fullsizepath ) . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ( $args['delete_unregistered_thumbnail_files'] ) {
|
||||
// Delete old sizes that are still in the metadata.
|
||||
$intermediate_image_sizes = get_intermediate_image_sizes();
|
||||
foreach ( $this->old_metadata['sizes'] as $old_size => $old_size_data ) {
|
||||
if ( in_array( $old_size, $intermediate_image_sizes ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
wp_delete_file( $wp_upload_dir . $old_size_data['file'] );
|
||||
|
||||
unset( $new_metadata['sizes'][ $old_size ] );
|
||||
}
|
||||
|
||||
$relative_path = dirname( $new_metadata['file'] ) . DIRECTORY_SEPARATOR;
|
||||
|
||||
// It's possible to upload an image with a filename like image-123x456.jpg and it shouldn't be deleted.
|
||||
$whitelist = $wpdb->get_col( $wpdb->prepare( "
|
||||
SELECT
|
||||
meta_value
|
||||
FROM
|
||||
{$wpdb->postmeta}
|
||||
WHERE
|
||||
meta_key = '_wp_attached_file'
|
||||
AND meta_value REGEXP %s
|
||||
/* Regenerate Thumbnails */
|
||||
",
|
||||
'^' . preg_quote( $relative_path ) . '[^' . preg_quote( DIRECTORY_SEPARATOR ) . ']+-[0-9]+x[0-9]+\.'
|
||||
) );
|
||||
$whitelist = array_map( 'basename', $whitelist );
|
||||
|
||||
$filelist = array();
|
||||
foreach ( scandir( $wp_upload_dir ) as $file ) {
|
||||
if ( '.' == $file || '..' == $file || ! is_file( $wp_upload_dir . $file ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filelist[] = $file;
|
||||
}
|
||||
|
||||
$registered_thumbnails = array();
|
||||
foreach ( $new_metadata['sizes'] as $size ) {
|
||||
$registered_thumbnails[] = $size['file'];
|
||||
}
|
||||
|
||||
$fullsize_parts = pathinfo( $fullsizepath );
|
||||
|
||||
foreach ( $filelist as $file ) {
|
||||
if ( in_array( $file, $whitelist ) || in_array( $file, $registered_thumbnails ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! preg_match( '#^' . preg_quote( $fullsize_parts['filename'], '#' ) . '-[0-9]+x[0-9]+\.' . preg_quote( $fullsize_parts['extension'], '#' ) . '$#', $file ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
wp_delete_file( $wp_upload_dir . $file );
|
||||
}
|
||||
} elseif ( ! empty( $this->old_metadata ) && ! empty( $this->old_metadata['sizes'] ) && is_array( $this->old_metadata['sizes'] ) ) {
|
||||
// If not deleting, rename any size conflicts to avoid them being lost if the file still exists.
|
||||
foreach ( $this->old_metadata['sizes'] as $old_size => $old_size_data ) {
|
||||
if ( empty( $new_metadata['sizes'][ $old_size ] ) ) {
|
||||
$new_metadata['sizes'][ $old_size ] = $this->old_metadata['sizes'][ $old_size ];
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_size_data = $new_metadata['sizes'][ $old_size ];
|
||||
|
||||
if (
|
||||
$new_size_data['width'] !== $old_size_data['width']
|
||||
&& $new_size_data['height'] !== $old_size_data['height']
|
||||
&& file_exists( $wp_upload_dir . $old_size_data['file'] )
|
||||
) {
|
||||
$new_metadata['sizes'][ $old_size . '_old_' . $old_size_data['width'] . 'x' . $old_size_data['height'] ] = $old_size_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_update_attachment_metadata( $this->attachment->ID, $new_metadata );
|
||||
|
||||
return $new_metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list of thumbnail sizes to only include those which have missing files.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array $sizes An associative array of registered thumbnail image sizes.
|
||||
* @param array $fullsize_metadata An associative array of fullsize image metadata: width, height, file.
|
||||
*
|
||||
* @return array An associative array of image sizes.
|
||||
*/
|
||||
public function filter_image_sizes_to_only_missing_thumbnails( $sizes, $fullsize_metadata ) {
|
||||
if ( ! $sizes ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
$fullsizepath = $this->get_fullsizepath();
|
||||
if ( is_wp_error( $fullsizepath ) ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
$editor = wp_get_image_editor( $fullsizepath );
|
||||
if ( is_wp_error( $editor ) ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
$metadata = $this->old_metadata;
|
||||
|
||||
// This is based on WP_Image_Editor_GD::multi_resize() and others.
|
||||
foreach ( $sizes as $size => $size_data ) {
|
||||
if ( empty( $metadata['sizes'][ $size ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset( $size_data['width'] ) ) {
|
||||
$size_data['width'] = null;
|
||||
}
|
||||
if ( ! isset( $size_data['height'] ) ) {
|
||||
$size_data['height'] = null;
|
||||
}
|
||||
|
||||
if ( ! isset( $size_data['crop'] ) ) {
|
||||
$size_data['crop'] = false;
|
||||
}
|
||||
|
||||
$thumbnail = $this->get_thumbnail(
|
||||
$editor,
|
||||
$fullsize_metadata['width'],
|
||||
$fullsize_metadata['height'],
|
||||
$size_data['width'],
|
||||
$size_data['height'],
|
||||
$size_data['crop']
|
||||
);
|
||||
|
||||
|
||||
// The false check filters out thumbnails that would be larger than the fullsize image.
|
||||
// The size comparison makes sure that the size is also correct.
|
||||
if (
|
||||
false === $thumbnail
|
||||
|| (
|
||||
$thumbnail['width'] === $metadata['sizes'][ $size ]['width']
|
||||
&& $thumbnail['height'] === $metadata['sizes'][ $size ]['height']
|
||||
&& file_exists( $thumbnail['filename'] )
|
||||
)
|
||||
) {
|
||||
$this->skipped_thumbnails[] = $size;
|
||||
unset( $sizes[ $size ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list of missing thumbnail sizes if you want to add/remove any.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $sizes An associative array of image sizes that are missing.
|
||||
* @param array $fullsize_metadata An associative array of fullsize image metadata: width, height, file.
|
||||
* @param object $this The current instance of this class.
|
||||
*
|
||||
* @return array An associative array of image sizes.
|
||||
*/
|
||||
return apply_filters( 'regenerate_thumbnails_missing_thumbnails', $sizes, $fullsize_metadata, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the thumbnail filename and dimensions for a given set of constraint dimensions.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_Image_Editor|WP_Error $editor An instance of WP_Image_Editor, as returned by wp_get_image_editor().
|
||||
* @param int $fullsize_width The width of the fullsize image.
|
||||
* @param int $fullsize_height The height of the fullsize image.
|
||||
* @param int $thumbnail_width The width of the thumbnail.
|
||||
* @param int $thumbnail_height The height of the thumbnail.
|
||||
* @param bool $crop Whether to crop or not.
|
||||
*
|
||||
* @return array|false An array of the filename, thumbnail width, and thumbnail height,
|
||||
* or false on failure to resize such as the thumbnail being larger than the fullsize image.
|
||||
*/
|
||||
public function get_thumbnail( $editor, $fullsize_width, $fullsize_height, $thumbnail_width, $thumbnail_height, $crop ) {
|
||||
$dims = image_resize_dimensions( $fullsize_width, $fullsize_height, $thumbnail_width, $thumbnail_height, $crop );
|
||||
|
||||
if ( ! $dims ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
list( , , , , $dst_w, $dst_h ) = $dims;
|
||||
|
||||
$suffix = "{$dst_w}x{$dst_h}";
|
||||
$file_ext = strtolower( pathinfo( $this->get_fullsizepath(), PATHINFO_EXTENSION ) );
|
||||
|
||||
return array(
|
||||
'filename' => $editor->generate_filename( $suffix, null, $file_ext ),
|
||||
'width' => $dst_w,
|
||||
'height' => $dst_h,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the post content of any public post types (posts and pages by default)
|
||||
* that make use of this attachment.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array|string $args {
|
||||
* Optional. Array or string of arguments for controlling the updating.
|
||||
*
|
||||
* @type array $post_type The post types to update. Defaults to public post types (posts and pages by default).
|
||||
* @type array $post_ids Specific post IDs to update as opposed to any that uses the attachment.
|
||||
* @type int $posts_per_loop How many posts to query at a time to keep memory usage down. You shouldn't need to modify this.
|
||||
* }
|
||||
*
|
||||
* @return array|WP_Error List of post IDs that were modified. The key is the post ID and the value is either the post ID again or a WP_Error object if wp_update_post() failed.
|
||||
*/
|
||||
public function update_usages_in_posts( $args = array() ) {
|
||||
// Temporarily disabled until it can be even better tested for edge cases
|
||||
return array();
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'post_type' => array(),
|
||||
'post_ids' => array(),
|
||||
'posts_per_loop' => 10,
|
||||
) );
|
||||
|
||||
if ( empty( $args['post_type'] ) ) {
|
||||
$args['post_type'] = array_values( get_post_types( array( 'public' => true ) ) );
|
||||
unset( $args['post_type']['attachment'] );
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
$posts_updated = array();
|
||||
|
||||
while ( true ) {
|
||||
$posts = get_posts( array(
|
||||
'numberposts' => $args['posts_per_loop'],
|
||||
'offset' => $offset,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
'include' => $args['post_ids'],
|
||||
'post_type' => $args['post_type'],
|
||||
's' => 'wp-image-' . $this->attachment->ID,
|
||||
|
||||
// For faster queries.
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
) );
|
||||
|
||||
if ( ! $posts ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$offset += $args['posts_per_loop'];
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$content = $post->post_content;
|
||||
$search = array();
|
||||
$replace = array();
|
||||
|
||||
// Find all <img> tags for this attachment and update them.
|
||||
preg_match_all(
|
||||
'#<img [^>]+wp-image-' . $this->attachment->ID . '[^>]+/>#i',
|
||||
$content,
|
||||
$matches,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
if ( $matches ) {
|
||||
foreach ( $matches as $img_tag ) {
|
||||
preg_match( '# class="([^"]+)?size-([^" ]+)#i', $img_tag[0], $thumbnail_size );
|
||||
|
||||
if ( $thumbnail_size ) {
|
||||
$thumbnail = image_downsize( $this->attachment->ID, $thumbnail_size[2] );
|
||||
|
||||
if ( ! $thumbnail ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$search[] = $img_tag[0];
|
||||
|
||||
$img_tag[0] = preg_replace( '# src="[^"]+"#i', ' src="' . esc_url( $thumbnail[0] ) . '"', $img_tag[0] );
|
||||
$img_tag[0] = preg_replace(
|
||||
'# width="[^"]+" height="[^"]+"#i',
|
||||
' width="' . esc_attr( $thumbnail[1] ) . '" height="' . esc_attr( $thumbnail[2] ) . '"',
|
||||
$img_tag[0]
|
||||
);
|
||||
|
||||
$replace[] = $img_tag[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
$content = str_replace( $search, $replace, $content );
|
||||
$search = array();
|
||||
$replace = array();
|
||||
|
||||
// Update the width in any [caption] shortcodes.
|
||||
preg_match_all(
|
||||
'#\[caption id="attachment_' . $this->attachment->ID . '"([^\]]+)? width="[^"]+"\]([^\[]+)size-([^" ]+)([^\[]+)\[\/caption\]#i',
|
||||
$content,
|
||||
$matches,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
if ( $matches ) {
|
||||
foreach ( $matches as $match ) {
|
||||
$thumbnail = image_downsize( $this->attachment->ID, $match[3] );
|
||||
|
||||
if ( ! $thumbnail ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$search[] = $match[0];
|
||||
$replace[] = '[caption id="attachment_' . $this->attachment->ID . '"' . $match[1] . ' width="' . esc_attr( $thumbnail[1] ) . '"]' . $match[2] . 'size-' . $match[3] . $match[4] . '[/caption]';
|
||||
}
|
||||
}
|
||||
$content = str_replace( $search, $replace, $content );
|
||||
|
||||
$updated_post_object = (object) array(
|
||||
'ID' => $post->ID,
|
||||
'post_content' => $content,
|
||||
);
|
||||
|
||||
$posts_updated[ $post->ID ] = wp_update_post( $updated_post_object, true );
|
||||
}
|
||||
}
|
||||
|
||||
return $posts_updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the current attachment for use in the REST API.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return array|WP_Error The attachment name, fullsize URL, registered thumbnail size status, and any unregistered sizes, or WP_Error on error.
|
||||
*/
|
||||
public function get_attachment_info() {
|
||||
$fullsizepath = $this->get_fullsizepath();
|
||||
if ( is_wp_error( $fullsizepath ) ) {
|
||||
$fullsizepath->add_data( array( 'attachment' => $this->attachment ) );
|
||||
|
||||
return $fullsizepath;
|
||||
}
|
||||
|
||||
$editor = wp_get_image_editor( $fullsizepath );
|
||||
if ( is_wp_error( $editor ) ) {
|
||||
// Display a more helpful error message.
|
||||
if ( 'image_no_editor' === $editor->get_error_code() ) {
|
||||
$editor = new WP_Error( 'image_no_editor', __( 'The current image editor cannot process this file type.', 'regenerate-thumbnails' ) );
|
||||
}
|
||||
|
||||
$editor->add_data( array(
|
||||
'attachment' => $this->attachment,
|
||||
'status' => 415,
|
||||
) );
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
$metadata = wp_get_attachment_metadata( $this->attachment->ID );
|
||||
|
||||
if ( false === $metadata || ! is_array( $metadata ) ) {
|
||||
return new WP_Error(
|
||||
'regenerate_thumbnails_regenerator_no_metadata',
|
||||
__( 'Unable to load the metadata for this attachment.', 'regenerate-thumbnails' ),
|
||||
array(
|
||||
'status' => 404,
|
||||
'attachment' => $this->attachment,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $metadata['sizes'] ) ) {
|
||||
$metadata['sizes'] = array();
|
||||
}
|
||||
|
||||
// PDFs don't have width/height set.
|
||||
$width = ( isset( $metadata['width'] ) ) ? $metadata['width'] : null;
|
||||
$height = ( isset( $metadata['height'] ) ) ? $metadata['height'] : null;
|
||||
|
||||
require_once( ABSPATH . '/wp-admin/includes/image.php' );
|
||||
|
||||
$preview = false;
|
||||
if ( file_is_displayable_image( $fullsizepath ) ) {
|
||||
$preview = wp_get_attachment_url( $this->attachment->ID );
|
||||
} elseif (
|
||||
is_array( $metadata['sizes'] ) &&
|
||||
is_array( $metadata['sizes']['full'] ) &&
|
||||
! empty( $metadata['sizes']['full']['file'] )
|
||||
) {
|
||||
$preview = str_replace(
|
||||
wp_basename( $fullsizepath ),
|
||||
$metadata['sizes']['full']['file'],
|
||||
wp_get_attachment_url( $this->attachment->ID )
|
||||
);
|
||||
|
||||
if ( ! file_exists( $preview ) ) {
|
||||
$preview = false;
|
||||
}
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'name' => ( $this->attachment->post_title ) ? $this->attachment->post_title : sprintf( __( 'Attachment %d', 'regenerate-thumbnails' ), $this->attachment->ID ),
|
||||
'preview' => $preview,
|
||||
'relative_path' => _wp_get_attachment_relative_path( $fullsizepath ) . DIRECTORY_SEPARATOR . wp_basename( $fullsizepath ),
|
||||
'edit_url' => get_edit_post_link( $this->attachment->ID, 'raw' ),
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'registered_sizes' => array(),
|
||||
'unregistered_sizes' => array(),
|
||||
);
|
||||
|
||||
$wp_upload_dir = dirname( $fullsizepath ) . DIRECTORY_SEPARATOR;
|
||||
|
||||
$registered_sizes = RegenerateThumbnails()->get_thumbnail_sizes();
|
||||
|
||||
if ( 'application/pdf' === get_post_mime_type( $this->attachment ) ) {
|
||||
$registered_sizes = array_intersect_key(
|
||||
$registered_sizes,
|
||||
array(
|
||||
'thumbnail' => true,
|
||||
'medium' => true,
|
||||
'large' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Check the status of all currently registered sizes.
|
||||
foreach ( $registered_sizes as $size ) {
|
||||
// Width and height are needed to generate the thumbnail filename.
|
||||
if ( $width && $height ) {
|
||||
$thumbnail = $this->get_thumbnail( $editor, $width, $height, $size['width'], $size['height'], $size['crop'] );
|
||||
|
||||
if ( $thumbnail ) {
|
||||
$size['filename'] = wp_basename( $thumbnail['filename'] );
|
||||
$size['fileexists'] = file_exists( $thumbnail['filename'] );
|
||||
} else {
|
||||
$size['filename'] = false;
|
||||
$size['fileexists'] = false;
|
||||
}
|
||||
} elseif ( ! empty( $metadata['sizes'][ $size['label'] ]['file'] ) ) {
|
||||
$size['filename'] = wp_basename( $metadata['sizes'][ $size['label'] ]['file'] );
|
||||
$size['fileexists'] = file_exists( $wp_upload_dir . $metadata['sizes'][ $size['label'] ]['file'] );
|
||||
} else {
|
||||
$size['filename'] = false;
|
||||
$size['fileexists'] = false;
|
||||
}
|
||||
|
||||
$response['registered_sizes'][] = $size;
|
||||
}
|
||||
|
||||
if ( ! $width && ! $height && is_array( $metadata['sizes']['full'] ) ) {
|
||||
$response['registered_sizes'][] = array(
|
||||
'label' => 'full',
|
||||
'width' => $metadata['sizes']['full']['width'],
|
||||
'height' => $metadata['sizes']['full']['height'],
|
||||
'filename' => $metadata['sizes']['full']['file'],
|
||||
'fileexists' => file_exists( $wp_upload_dir . $metadata['sizes']['full']['file'] ),
|
||||
);
|
||||
}
|
||||
|
||||
// Look at the attachment metadata and see if we have any extra files from sizes that are no longer registered.
|
||||
foreach ( $metadata['sizes'] as $label => $size ) {
|
||||
if ( ! file_exists( $wp_upload_dir . $size['file'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// An unregistered size could match a registered size's dimensions. Ignore these.
|
||||
foreach ( $response['registered_sizes'] as $registered_size ) {
|
||||
if ( $size['file'] === $registered_size['filename'] ) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $registered_sizes[ $label ] ) ) {
|
||||
/* translators: Used for listing old sizes of currently registered thumbnails */
|
||||
$label = sprintf( __( '%s (old)', 'regenerate-thumbnails' ), $label );
|
||||
}
|
||||
|
||||
$response['unregistered_sizes'][] = array(
|
||||
'label' => $label,
|
||||
'width' => $size['width'],
|
||||
'height' => $size['height'],
|
||||
'filename' => $size['file'],
|
||||
'fileexists' => true,
|
||||
);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -0,0 +1,324 @@
|
||||
<?php
|
||||
/**
|
||||
* Regenerate Thumbnails: REST API controller class
|
||||
*
|
||||
* @package RegenerateThumbnails
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers new REST API endpoints.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class RegenerateThumbnails_REST_Controller extends WP_REST_Controller {
|
||||
/**
|
||||
* The namespace for the REST API routes.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = 'regenerate-thumbnails/v1';
|
||||
|
||||
/**
|
||||
* Register the new routes and endpoints.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/regenerate/(?P<id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::ALLMETHODS,
|
||||
'callback' => array( $this, 'regenerate_item' ),
|
||||
'permission_callback' => array( $this, 'permissions_check' ),
|
||||
'args' => array(
|
||||
'only_regenerate_missing_thumbnails' => array(
|
||||
'description' => __( "Whether to only regenerate missing thumbnails. It's faster with this enabled.", 'regenerate-thumbnails' ),
|
||||
'type' => 'boolean',
|
||||
'default' => true,
|
||||
),
|
||||
'delete_unregistered_thumbnail_files' => array(
|
||||
'description' => __( 'Whether to delete any old, now unregistered thumbnail files.', 'regenerate-thumbnails' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
),
|
||||
'update_usages_in_posts' => array(
|
||||
'description' => __( 'Whether to update the image tags in any posts that make use of this attachment.', 'regenerate-thumbnails' ),
|
||||
'type' => 'boolean',
|
||||
'default' => true,
|
||||
),
|
||||
'update_usages_in_posts_post_type' => array(
|
||||
'description' => __( 'The types of posts to update. Defaults to all public post types.', 'regenerate-thumbnails' ),
|
||||
'type' => 'array',
|
||||
'default' => array(),
|
||||
'validate_callback' => array( $this, 'is_array' ),
|
||||
),
|
||||
'update_usages_in_posts_post_ids' => array(
|
||||
'description' => __( 'Specific post IDs to update rather than any posts that use this attachment.', 'regenerate-thumbnails' ),
|
||||
'type' => 'array',
|
||||
'default' => array(),
|
||||
'validate_callback' => array( $this, 'is_array' ),
|
||||
),
|
||||
'update_usages_in_posts_posts_per_loop' => array(
|
||||
'description' => __( "Posts to process per loop. This is to control memory usage and you likely don't need to adjust this.", 'regenerate-thumbnails' ),
|
||||
'type' => 'integer',
|
||||
'default' => 10,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
),
|
||||
),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/attachmentinfo/(?P<id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'attachment_info' ),
|
||||
'permission_callback' => array( $this, 'permissions_check' ),
|
||||
),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/featuredimages', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'featured_images' ),
|
||||
'permission_callback' => array( $this, 'permissions_check' ),
|
||||
'args' => $this->get_paging_collection_params(),
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a filter to allow excluding site icons via a query parameter.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function register_filters() {
|
||||
add_filter( 'rest_attachment_query', array( $this, 'maybe_filter_out_site_icons' ), 10, 2 );
|
||||
add_filter( 'rest_attachment_query', array( $this, 'maybe_filter_mimes_types' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the exclude_site_icons parameter is set on a media (attachment) request,
|
||||
* filter out any attachments that are or were being used as a site icon.
|
||||
*
|
||||
* @param array $args Key value array of query var to query value.
|
||||
* @param WP_REST_Request $request The request used.
|
||||
*
|
||||
* @return array Key value array of query var to query value.
|
||||
*/
|
||||
public function maybe_filter_out_site_icons( $args, $request ) {
|
||||
if ( empty( $request['exclude_site_icons'] ) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
if ( ! isset( $args['meta_query'] ) ) {
|
||||
$args['meta_query'] = array();
|
||||
}
|
||||
|
||||
$args['meta_query'][] = array(
|
||||
'key' => '_wp_attachment_context',
|
||||
'value' => 'site-icon',
|
||||
'compare' => 'NOT EXISTS',
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the is_regeneratable parameter is set on a media (attachment) request,
|
||||
* filter results to only include images and PDFs.
|
||||
*
|
||||
* @param array $args Key value array of query var to query value.
|
||||
* @param WP_REST_Request $request The request used.
|
||||
*
|
||||
* @return array Key value array of query var to query value.
|
||||
*/
|
||||
public function maybe_filter_mimes_types( $args, $request ) {
|
||||
if ( empty( $request['is_regeneratable'] ) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$args['post_mime_type'] = array();
|
||||
foreach ( get_allowed_mime_types() as $mime_type ) {
|
||||
if ( 'image/svg+xml' === $mime_type ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'application/pdf' == $mime_type || 'image/' == substr( $mime_type, 0, 6 ) ) {
|
||||
$args['post_mime_type'][] = $mime_type;
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the paging query params for the collections.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return array Query parameters for the collection.
|
||||
*/
|
||||
public function get_paging_collection_params() {
|
||||
return array_intersect_key(
|
||||
parent::get_collection_params(),
|
||||
array_flip( array( 'page', 'per_page' ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the thumbnails for a specific media item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*
|
||||
* @return true|WP_Error True on success, otherwise a WP_Error object.
|
||||
*/
|
||||
public function regenerate_item( $request ) {
|
||||
$regenerator = RegenerateThumbnails_Regenerator::get_instance( $request->get_param( 'id' ) );
|
||||
|
||||
if ( is_wp_error( $regenerator ) ) {
|
||||
return $regenerator;
|
||||
}
|
||||
|
||||
$result = $regenerator->regenerate( array(
|
||||
'only_regenerate_missing_thumbnails' => $request->get_param( 'only_regenerate_missing_thumbnails' ),
|
||||
'delete_unregistered_thumbnail_files' => $request->get_param( 'delete_unregistered_thumbnail_files' ),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $request->get_param( 'update_usages_in_posts' ) ) {
|
||||
$posts_updated = $regenerator->update_usages_in_posts( array(
|
||||
'post_type' => $request->get_param( 'update_usages_in_posts_post_type' ),
|
||||
'post_ids' => $request->get_param( 'update_usages_in_posts_post_ids' ),
|
||||
'posts_per_loop' => $request->get_param( 'update_usages_in_posts_posts_per_loop' ),
|
||||
) );
|
||||
|
||||
// If wp_update_post() failed for any posts, return that error.
|
||||
foreach ( $posts_updated as $post_updated_result ) {
|
||||
if ( is_wp_error( $post_updated_result ) ) {
|
||||
return $post_updated_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->attachment_info( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bunch of information about the current attachment for use in the UI
|
||||
* including details about the thumbnails.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*
|
||||
* @return array|WP_Error The data array or a WP_Error object on error.
|
||||
*/
|
||||
public function attachment_info( $request ) {
|
||||
$regenerator = RegenerateThumbnails_Regenerator::get_instance( $request->get_param( 'id' ) );
|
||||
|
||||
if ( is_wp_error( $regenerator ) ) {
|
||||
return $regenerator;
|
||||
}
|
||||
|
||||
return $regenerator->get_attachment_info();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return attachment IDs that are being used as featured images.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*
|
||||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function featured_images( $request ) {
|
||||
global $wpdb;
|
||||
|
||||
$page = $request->get_param( 'page' );
|
||||
$per_page = $request->get_param( 'per_page' );
|
||||
|
||||
if ( 0 == $per_page ) {
|
||||
$per_page = 10;
|
||||
}
|
||||
|
||||
$featured_image_ids = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT SQL_CALC_FOUND_ROWS meta_value AS id FROM {$wpdb->postmeta} WHERE meta_key = '_thumbnail_id' GROUP BY meta_value ORDER BY MIN(meta_id) LIMIT %d OFFSET %d",
|
||||
$per_page,
|
||||
( $per_page * $page ) - $per_page
|
||||
) );
|
||||
|
||||
$total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
|
||||
$max_pages = ceil( $total / $per_page );
|
||||
|
||||
if ( $page > $max_pages && $total > 0 ) {
|
||||
return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $featured_image_ids );
|
||||
|
||||
$response->header( 'X-WP-Total', (int) $total );
|
||||
$response->header( 'X-WP-TotalPages', (int) $max_pages );
|
||||
|
||||
$request_params = $request->get_query_params();
|
||||
$base = add_query_arg( $request_params, rest_url( $this->namespace . '/featuredimages' ) );
|
||||
|
||||
if ( $page > 1 ) {
|
||||
$prev_page = $page - 1;
|
||||
|
||||
if ( $prev_page > $max_pages ) {
|
||||
$prev_page = $max_pages;
|
||||
}
|
||||
|
||||
$prev_link = add_query_arg( 'page', $prev_page, $base );
|
||||
$response->link_header( 'prev', $prev_link );
|
||||
}
|
||||
|
||||
if ( $max_pages > $page ) {
|
||||
$next_page = $page + 1;
|
||||
$next_link = add_query_arg( 'page', $next_page, $base );
|
||||
|
||||
$response->link_header( 'next', $next_link );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the current user is allowed to use this endpoint.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*
|
||||
* @return bool Whether the current user has permission to regenerate thumbnails.
|
||||
*/
|
||||
public function permissions_check( $request ) {
|
||||
return current_user_can( RegenerateThumbnails()->capability );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a variable is an array or not. This is needed because 3 arguments are
|
||||
* passed to validation callbacks but is_array() only accepts one argument.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @see https://core.trac.wordpress.org/ticket/34659
|
||||
*
|
||||
* @param mixed $param The parameter value to validate.
|
||||
* @param WP_REST_Request $request The REST request.
|
||||
* @param string $key The parameter name.
|
||||
*
|
||||
* @return bool Whether the parameter is an array or not.
|
||||
*/
|
||||
public function is_array( $param, $request, $key ) {
|
||||
return is_array( $param );
|
||||
}
|
||||
}
|
1
old/wp-content/plugins/regenerate-thumbnails/js/api-request.min.js
vendored
Normal file
1
old/wp-content/plugins/regenerate-thumbnails/js/api-request.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(a){function b(a){return a=b.buildAjaxOptions(a),b.transport(a)}var c=window.wpApiSettings;b.buildAjaxOptions=function(b){var d,e,f,g,h,i=b.url,j=b.path;if("string"==typeof b.namespace&&"string"==typeof b.endpoint&&(d=b.namespace.replace(/^\/|\/$/g,""),e=b.endpoint.replace(/^\//,""),j=e?d+"/"+e:d),"string"==typeof j&&(i=c.root+j.replace(/^\//,"")),g=!(b.data&&b.data._wpnonce),f=b.headers||{},g)for(h in f)if(f.hasOwnProperty(h)&&"x-wp-nonce"===h.toLowerCase()){g=!1;break}return g&&(f=a.extend({"X-WP-Nonce":c.nonce},f)),b=a.extend({},b,{headers:f,url:i}),delete b.path,delete b.namespace,delete b.endpoint,b},b.transport=a.ajax,window.wp=window.wp||{},window.wp.apiRequest=b}(jQuery);
|
205
old/wp-content/plugins/regenerate-thumbnails/readme.txt
Normal file
205
old/wp-content/plugins/regenerate-thumbnails/readme.txt
Normal file
@ -0,0 +1,205 @@
|
||||
=== Regenerate Thumbnails ===
|
||||
Contributors: Viper007Bond
|
||||
Tags: thumbnail, thumbnails, post thumbnail, post thumbnails
|
||||
Requires at least: 4.7
|
||||
Tested up to: 6.3
|
||||
Requires PHP: 5.2.4
|
||||
Stable tag: 3.1.6
|
||||
License: GPLv2 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Regenerate the thumbnails for one or more of your image uploads. Useful when changing their sizes or your theme.
|
||||
|
||||
== Description ==
|
||||
|
||||
Regenerate Thumbnails allows you to regenerate all thumbnail sizes for one or more images that have been uploaded to your Media Library.
|
||||
|
||||
This is useful for situations such as:
|
||||
|
||||
* A new thumbnail size has been added and you want past uploads to have a thumbnail in that size.
|
||||
* You've changed the dimensions of an existing thumbnail size, for example via Settings â Media.
|
||||
* You've switched to a new WordPress theme that uses featured images of a different size.
|
||||
|
||||
It also offers the ability to delete old, unused thumbnails in order to free up server space.
|
||||
|
||||
= In Memory of Alex Mills =
|
||||
|
||||
In February 2019 Alex Mills, the author of this plugin, [passed away](https://alex.blog/2019/02/27/from-alexs-family/). He leaves behind a number of plugins which will be maintained by Automattic and members of the WordPress community. If this plugin is useful to you please consider donating to the Oregon Health and Science University. You can find more information [here](https://alex.blog/2019/03/13/in-memory-of-alex-donation-link-update/).
|
||||
|
||||
= Alternatives =
|
||||
|
||||
**WP-CLI**
|
||||
|
||||
If you have command line access to your server, I highly recommend using [WP-CLI](https://wp-cli.org/) instead of this plugin as it's faster (no HTTP requests overhead) and can be run inside of a `screen` for those with many thumbnails. For details, see the documentation of its [`media regenerate` command](https://developer.wordpress.org/cli/commands/media/regenerate/).
|
||||
|
||||
**Jetpack's Photon Module**
|
||||
|
||||
[Jetpack](https://jetpack.com/) is a plugin by Automattic, makers of WordPress.com. It gives your self-hosted WordPress site some of the functionality that is available to WordPress.com-hosted sites.
|
||||
|
||||
[The Photon module](https://jetpack.com/support/photon/) makes the images on your site be served from WordPress.com's global content delivery network (CDN) which should speed up the loading of images. Importantly though it can create thumbnails on the fly which means you'll never need to use this plugin.
|
||||
|
||||
I personally use Photon on my own website.
|
||||
|
||||
*Disclaimer: I work for Automattic but I would recommend Photon even if I didn't.*
|
||||
|
||||
= Need Help? Found A Bug? Want To Contribute Code? =
|
||||
|
||||
Support for this plugin is provided via the [WordPress.org forums](https://wordpress.org/support/plugin/regenerate-thumbnails).
|
||||
|
||||
The source code for this plugin is available on [GitHub](https://github.com/automattic/regenerate-thumbnails).
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Go to your admin area and select Plugins â Add New from the menu.
|
||||
2. Search for "Regenerate Thumbnails".
|
||||
3. Click install.
|
||||
4. Click activate.
|
||||
5. Navigate to Tools â Regenerate Thumbnails.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Is this plugin [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) compliant? =
|
||||
|
||||
This plugin does not log nor transmit any user data. Infact it doesn't even do anything on the user-facing part of your website, only in the admin area. This means it should be compliant but I'm not a lawyer.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. The main plugin interface.
|
||||
2. Regenerating in progress.
|
||||
3. Interface for regenerating a single attachment.
|
||||
4. Individual images can be regenerated from the media library in list view.
|
||||
5. They can also be regenerated from the edit attachment screen.
|
||||
|
||||
== ChangeLog ==
|
||||
|
||||
= Version 3.1.6 =
|
||||
|
||||
* Fix: Respect "Skip regenerating existing correctly sized thumbnails" setting.
|
||||
* Fix: Don't delete all thumbnails when deleting old unregistered thumbnails size.
|
||||
|
||||
= Version 3.1.5 =
|
||||
|
||||
* Fix: Don't overwrite 'All X Attachment' button label with featured images count.
|
||||
* Tested successfully with PHP 8.1.
|
||||
* Tested successfully with PHP 8.2.
|
||||
|
||||
= Version 3.1.4 =
|
||||
|
||||
* Fix: Don't attempt to regenerate SVG's.
|
||||
* Bump tested version.
|
||||
* Update dependencies.
|
||||
|
||||
= Version 3.1.3 =
|
||||
|
||||
* Update plugin dependencies to the latest version.
|
||||
|
||||
= Version 3.1.2 =
|
||||
* Use wp_get_original_image_path() in WordPress 5.3
|
||||
|
||||
= Version 3.1.1 =
|
||||
|
||||
* Minor fix to avoid a divide by zero error when displaying thumbnail filenames.
|
||||
|
||||
= Version 3.1.0 =
|
||||
|
||||
* Bring back the ability to delete old, unregistered thumbnail sizes. Support for updating post contents is still disabled (too buggy).
|
||||
* Various code improvements including string localization disambiguation.
|
||||
|
||||
= Version 3.0.2 =
|
||||
|
||||
* Fix slowdown in certain cases in the media library.
|
||||
* Fix not being able to regenerate existing thumbnails for single images. Props @idofri.
|
||||
* Fix JavaScript error that could occur if the REST API response was unexpected (empty or PHP error).
|
||||
* Fix bug related to multibyte filenames.
|
||||
* If an image is used as the featured image on multiple posts, only regenerate it once instead of once per post.
|
||||
|
||||
= Version 3.0.1 =
|
||||
|
||||
* Temporarily disable the update post functionality. I tested it a lot but it seems there's still some bugs.
|
||||
* Temporarily disable the delete old thumbnails functionality. It seems to work fine but without the update post functionality, it's not as useful.
|
||||
* Try to more gracefully handle cases where there's missing metadata for attachments.
|
||||
* Wait until `init` to initialize the plugin so themes can filter the plugin's capability. `plugins_loaded` is too early.
|
||||
* Fix a JavaScript error that would cause the whole regeneration process to stop if an individual image returned non-JSON, such as a 500 error code.
|
||||
* Accept GET requests for the regenerate REST API endpoint instead of just POSTs. For some reasons some people's sites are using GET despite the code saying use POST.
|
||||
* Make the attachment ID clickable in error messages.
|
||||
* Fetch 25 attachments at a time instead of 5. I was using 5 for testing.
|
||||
* PHP notice fixes.
|
||||
|
||||
= Version 3.0.0 =
|
||||
|
||||
* Complete rewrite from scratch using Vue.js and the WordPress REST API.
|
||||
|
||||
= Version 2.2.4 =
|
||||
|
||||
* Better AJAX response error handling in the JavaScript. This should fix a long-standing bug in this plugin. Props Hew Sutton.
|
||||
|
||||
= Version 2.2.3 =
|
||||
|
||||
* Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
|
||||
|
||||
= Version 2.2.2 =
|
||||
|
||||
* Don't check the nonce until we're sure that the action called was for this plugin. Fixes lots of "Are you sure you want to do this?" error messages.
|
||||
|
||||
= Version 2.2.1 =
|
||||
|
||||
* Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
|
||||
|
||||
= Version 2.2.0 =
|
||||
|
||||
* Changes to the Bulk Action functionality were made shortly before the release of WordPress 3.1 which broke the way I implemented the specific multiple image regeneration feature. This version adds to the Bulk Action menu using Javascript as that's the only way to do it currently.
|
||||
|
||||
= Version 2.1.3 =
|
||||
|
||||
* Move the `error_reporting()` call in the AJAX handler to the beginning so that we're more sure that no PHP errors are outputted. Some hosts disable usage of `set_time_limit()` and calling it was causing a PHP warning to be outputted.
|
||||
|
||||
= Version 2.1.2 =
|
||||
|
||||
* When regenerating all images, newest images are done first rather than the oldest.
|
||||
* Fixed a bug with regeneration error reporting in some browsers. Thanks to pete-sch for reporting the error.
|
||||
* Supress PHP errors in the AJAX handler to avoid sending an invalid JSON response. Thanks to pete-sch for reporting the error.
|
||||
* Better and more detailed error reporting for when `wp_generate_attachment_metadata()` fails.
|
||||
|
||||
= Version 2.1.1 =
|
||||
|
||||
* Clean up the wording a bit to better match the new features and just be easier to understand.
|
||||
* Updated screenshots.
|
||||
|
||||
= Version 2.1.0 =
|
||||
|
||||
Lots of new features!
|
||||
|
||||
* Thanks to a lot of jQuery help from [Boris Schapira](http://borisschapira.com/), a failed image regeneration will no longer stop the whole process.
|
||||
* The results of each image regeneration is now outputted. You can easily see which images were successfully regenerated and which failed. Was inspired by a concept by Boris.
|
||||
* There is now a button on the regeneration page that will allow you to abort resizing images for any reason. Based on code by Boris.
|
||||
* You can now regenerate single images from the Media page. The link to do so will show up in the actions list when you hover over the row.
|
||||
* You can now bulk regenerate multiple from the Media page. Check the boxes and then select "Regenerate Thumbnails" form the "Bulk Actions" dropdown. WordPress 3.1+ only.
|
||||
* The total time that the regeneration process took is now displayed in the final status message.
|
||||
* jQuery UI Progressbar version upgraded.
|
||||
|
||||
= Version 2.0.3 =
|
||||
|
||||
* Switch out deprecated function call.
|
||||
|
||||
= Version 2.0.2 =
|
||||
|
||||
* Directly query the database to only fetch what the plugin needs (the attachment ID). This will reduce the memory required as it's not storing the whole row for each attachment.
|
||||
|
||||
= Version 2.0.1 =
|
||||
|
||||
* I accidentally left a `check_admin_referer()` (nonce check) commented out.
|
||||
|
||||
= Version 2.0.0 =
|
||||
|
||||
* Recoded from scratch. Now uses an AJAX request per attachment to do the resizing. No more PHP maximum execution time errors or anything like that. Also features a pretty progress bar to let the user know how it's going.
|
||||
|
||||
= Version 1.1.0 =
|
||||
|
||||
* WordPress 2.7 updates -- code + UI. Thanks to jdub and Patrick F.
|
||||
|
||||
= Version 1.0.0 =
|
||||
|
||||
* Initial release.
|
||||
|
||||
= Upgrade Notice =
|
||||
Support for WordPress 5.3
|
@ -0,0 +1,570 @@
|
||||
<?php /*
|
||||
|
||||
**************************************************************************
|
||||
|
||||
Plugin Name: Regenerate Thumbnails
|
||||
Description: Regenerate the thumbnails for one or more of your image uploads. Useful when changing their sizes or your theme.
|
||||
Plugin URI: https://alex.blog/wordpress-plugins/regenerate-thumbnails/
|
||||
Version: 3.1.6
|
||||
Author: Alex Mills (Viper007Bond)
|
||||
Author URI: https://alex.blog/
|
||||
Text Domain: regenerate-thumbnails
|
||||
License: GPL2
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
**************************************************************************
|
||||
|
||||
Regenerate Thumbnails is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
any later version.
|
||||
|
||||
Regenerate Thumbnails is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Regenerate Thumbnails. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* Main plugin class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class RegenerateThumbnails {
|
||||
/**
|
||||
* This plugin's version number. Used for busting caches.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $version = '3.1.6';
|
||||
|
||||
/**
|
||||
* The menu ID of this plugin, as returned by add_management_page().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $menu_id;
|
||||
|
||||
/**
|
||||
* The capability required to use this plugin.
|
||||
* Please don't change this directly. Use the "regenerate_thumbs_cap" filter instead.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $capability = 'manage_options';
|
||||
|
||||
/**
|
||||
* The instance of the REST API controller class used to extend the REST API.
|
||||
*
|
||||
* @var RegenerateThumbnails_REST_Controller
|
||||
*/
|
||||
public $rest_api;
|
||||
|
||||
/**
|
||||
* The single instance of this plugin.
|
||||
*
|
||||
* @see RegenerateThumbnails()
|
||||
*
|
||||
* @access private
|
||||
* @var RegenerateThumbnails
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Constructor. Doesn't actually do anything as instance() creates the class instance.
|
||||
*/
|
||||
private function __construct() {}
|
||||
|
||||
/**
|
||||
* Prevents the class from being cloned.
|
||||
*/
|
||||
public function __clone() {
|
||||
wp_die( "Please don't clone RegenerateThumbnails" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the class from being unserialized and woken up.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
wp_die( "Please don't unserialize/wakeup RegenerateThumbnails" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this class if one hasn't already been made
|
||||
* and then returns the single instance of this class.
|
||||
*
|
||||
* @return RegenerateThumbnails
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new RegenerateThumbnails;
|
||||
self::$instance->setup();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the needed hooks and actions.
|
||||
*/
|
||||
public function setup() {
|
||||
// Prevent fatals on old versions of WordPress
|
||||
if ( ! class_exists( 'WP_REST_Controller' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
require dirname( __FILE__ ) . '/includes/class-regeneratethumbnails-regenerator.php';
|
||||
require dirname( __FILE__ ) . '/includes/class-regeneratethumbnails-rest-controller.php';
|
||||
|
||||
// Allow people to change what capability is required to use this plugin.
|
||||
$this->capability = apply_filters( 'regenerate_thumbs_cap', $this->capability );
|
||||
|
||||
// Initialize the REST API routes.
|
||||
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
|
||||
|
||||
// Add a new item to the Tools menu in the admin menu.
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
|
||||
// Load the required JavaScript and CSS.
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueues' ) );
|
||||
|
||||
// For the bulk action dropdowns.
|
||||
add_action( 'admin_head-upload.php', array( $this, 'add_bulk_actions_via_javascript' ) );
|
||||
add_action( 'admin_action_bulk_regenerate_thumbnails', array( $this, 'bulk_action_handler' ) ); // Top drowndown.
|
||||
add_action( 'admin_action_-1', array( $this, 'bulk_action_handler' ) ); // Bottom dropdown.
|
||||
|
||||
// Add a regenerate button to the non-modal edit media page.
|
||||
add_action( 'attachment_submitbox_misc_actions', array( $this, 'add_button_to_media_edit_page' ), 99 );
|
||||
|
||||
// Add a regenerate button to the list of fields in the edit media modal.
|
||||
// Ideally this would with the action links but I'm not good enough with JavaScript to do it.
|
||||
add_filter( 'attachment_fields_to_edit', array( $this, 'add_button_to_edit_media_modal_fields_area' ), 99, 2 );
|
||||
|
||||
// Add a regenerate link to actions list in the media list view.
|
||||
add_filter( 'media_row_actions', array( $this, 'add_regenerate_link_to_media_list_view' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the REST API routes.
|
||||
*/
|
||||
public function rest_api_init() {
|
||||
$this->rest_api = new RegenerateThumbnails_REST_Controller();
|
||||
$this->rest_api->register_routes();
|
||||
$this->rest_api->register_filters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a the new item to the admin menu.
|
||||
*/
|
||||
public function add_admin_menu() {
|
||||
$this->menu_id = add_management_page(
|
||||
_x( 'Regenerate Thumbnails', 'admin page title', 'regenerate-thumbnails' ),
|
||||
_x( 'Regenerate Thumbnails', 'admin menu entry title', 'regenerate-thumbnails' ),
|
||||
$this->capability,
|
||||
'regenerate-thumbnails',
|
||||
array( $this, 'regenerate_interface' )
|
||||
);
|
||||
|
||||
add_action( 'admin_head-' . $this->menu_id, array( $this, 'add_admin_notice_if_resizing_not_supported' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues the requires JavaScript file and stylesheet on the plugin's admin page.
|
||||
*
|
||||
* @param string $hook_suffix The current page's hook suffix as provided by admin-header.php.
|
||||
*/
|
||||
public function admin_enqueues( $hook_suffix ) {
|
||||
if ( $hook_suffix != $this->menu_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pre-4.9 compatibility.
|
||||
if ( ! wp_script_is( 'wp-api-request', 'registered' ) ) {
|
||||
wp_register_script(
|
||||
'wp-api-request',
|
||||
plugins_url( 'js/api-request.min.js', __FILE__ ),
|
||||
array( 'jquery' ),
|
||||
'4.9',
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script( 'wp-api-request', 'wpApiSettings', array(
|
||||
'root' => esc_url_raw( get_rest_url() ),
|
||||
'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
|
||||
'versionString' => 'wp/v2/',
|
||||
) );
|
||||
}
|
||||
|
||||
wp_enqueue_script(
|
||||
'regenerate-thumbnails',
|
||||
plugins_url( 'dist/build.js', __FILE__ ),
|
||||
array( 'wp-api-request' ),
|
||||
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? filemtime( dirname( __FILE__ ) . '/dist/build.js' ) : $this->version,
|
||||
true
|
||||
);
|
||||
|
||||
// phpcs:disable WordPress.Arrays.MultipleStatementAlignment
|
||||
$script_data = array(
|
||||
'data' => array(
|
||||
'thumbnailSizes' => $this->get_thumbnail_sizes(),
|
||||
'genericEditURL' => admin_url( 'post.php?action=edit&post=' ),
|
||||
),
|
||||
'options' => array(
|
||||
'onlyMissingThumbnails' => apply_filters( 'regenerate_thumbnails_options_onlymissingthumbnails', true ),
|
||||
'updatePostContents' => apply_filters( 'regenerate_thumbnails_options_updatepostcontents', false ),
|
||||
'deleteOldThumbnails' => apply_filters( 'regenerate_thumbnails_options_deleteoldthumbnails', false ),
|
||||
),
|
||||
'l10n' => array(
|
||||
'common' => array(
|
||||
'loading' => __( 'Loading…', 'regenerate-thumbnails' ),
|
||||
'onlyRegenerateMissingThumbnails' => __( 'Skip regenerating existing correctly sized thumbnails (faster).', 'regenerate-thumbnails' ),
|
||||
'deleteOldThumbnails' => __( "Delete thumbnail files for old unregistered sizes in order to free up server space. This may result in broken images in your posts and pages.", 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeItemWithCropMethodNoFilename' => __( '<strong>{label}:</strong> {width}×{height} pixels ({cropMethod})', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeItemWithCropMethod' => __( '<strong>{label}:</strong> {width}×{height} pixels ({cropMethod}) <code>{filename}</code>', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeItemWithoutCropMethod' => __( '<strong>{label}:</strong> {width}×{height} pixels <code>{filename}</code>', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeBiggerThanOriginal' => __( '<strong>{label}:</strong> {width}×{height} pixels (thumbnail would be larger than original)', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeItemIsCropped' => __( 'cropped to fit', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizeItemIsProportional' => __( 'proportionally resized to fit inside dimensions', 'regenerate-thumbnails' ),
|
||||
),
|
||||
'Home' => array(
|
||||
'intro1' => sprintf(
|
||||
/* translators: %s: Media options URL */
|
||||
__( 'When you change WordPress themes or change the sizes of your thumbnails at <a href="%s">Settings → Media</a>, images that you have previously uploaded to you media library will be missing thumbnail files for those new image sizes. This tool will allow you to create those missing thumbnail files for all images.', 'regenerate-thumbnails' ),
|
||||
esc_url( admin_url( 'options-media.php' ) )
|
||||
),
|
||||
'intro2' => sprintf(
|
||||
/* translators: %s: Media library URL */
|
||||
__( 'To process a specific image, visit your media library and click the "Regenerate Thumbnails" link or button. To process multiple specific images, make sure you\'re in the <a href="%s">list view</a> and then use the Bulk Actions dropdown after selecting one or more images.', 'regenerate-thumbnails' ),
|
||||
esc_url( admin_url( 'upload.php?mode=list' ) )
|
||||
),
|
||||
'updatePostContents' => __( 'Update the content of posts to use the new sizes.', 'regenerate-thumbnails' ),
|
||||
'RegenerateThumbnailsForAllAttachments' => __( 'Regenerate Thumbnails For All Attachments', 'regenerate-thumbnails' ),
|
||||
'RegenerateThumbnailsForAllXAttachments' => __( 'Regenerate Thumbnails For All {attachmentCount} Attachments', 'regenerate-thumbnails' ),
|
||||
'RegenerateThumbnailsForFeaturedImagesOnly' => __( 'Regenerate Thumbnails For Featured Images Only', 'regenerate-thumbnails' ),
|
||||
'RegenerateThumbnailsForXFeaturedImagesOnly' => __( 'Regenerate Thumbnails For The {attachmentCount} Featured Images Only', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizes' => __( 'Thumbnail Sizes', 'regenerate-thumbnails' ),
|
||||
'thumbnailSizesDescription' => __( 'These are all of the thumbnail sizes that are currently registered:', 'regenerate-thumbnails' ),
|
||||
'alternatives' => __( 'Alternatives', 'regenerate-thumbnails' ),
|
||||
'alternativesText1' => __( 'If you have <a href="{url-cli}">command-line</a> access to your site\'s server, consider using <a href="{url-wpcli}">WP-CLI</a> instead of this tool. It has a built-in <a href="{url-wpcli-regenerate}">regenerate command</a> that works similarly to this tool but should be significantly faster since it has the advantage of being a command-line tool.', 'regenerate-thumbnails' ),
|
||||
'alternativesText2' => __( 'Another alternative is to use the <a href="{url-photon}">Photon</a> functionality that comes with the <a href="{url-jetpack}">Jetpack</a> plugin. It generates thumbnails on-demand using WordPress.com\'s infrastructure. <em>Disclaimer: The author of this plugin, Regenerate Thumbnails, is an employee of the company behind WordPress.com and Jetpack but I would recommend it even if I wasn\'t.</em>', 'regenerate-thumbnails' ),
|
||||
),
|
||||
'RegenerateSingle' => array(
|
||||
'regenerateThumbnails' => _x( 'Regenerate Thumbnails', 'action for a single image', 'regenerate-thumbnails' ),
|
||||
/* translators: single image sdmin page title */
|
||||
'title' => __( 'Regenerate Thumbnails: {name} — WordPress', 'regenerate-thumbnails' ),
|
||||
'errorWithMessage' => __( '<strong>ERROR:</strong> {error}', 'regenerate-thumbnails' ),
|
||||
'filenameAndDimensions' => __( '<code>{filename}</code> {width}×{height} pixels', 'regenerate-thumbnails' ),
|
||||
'preview' => __( 'Preview', 'regenerate-thumbnails' ),
|
||||
'updatePostContents' => __( 'Update the content of posts that use this attachment to use the new sizes.', 'regenerate-thumbnails' ),
|
||||
'regenerating' => __( 'Regenerating…', 'regenerate-thumbnails' ),
|
||||
'done' => __( 'Done! Click here to go back.', 'regenerate-thumbnails' ),
|
||||
'errorRegenerating' => __( 'Error Regenerating', 'regenerate-thumbnails' ),
|
||||
'errorRegeneratingMessage' => __( 'There was an error regenerating this attachment. The error was: <em>{message}</em>', 'regenerate-thumbnails' ),
|
||||
'registeredSizes' => __( 'These are the currently registered thumbnail sizes, whether they exist for this attachment, and their filenames:', 'regenerate-thumbnails' ),
|
||||
'unregisteredSizes' => __( 'The attachment says it also has these thumbnail sizes but they are no longer in use by WordPress. You can probably safely have this plugin delete them, especially if you have this plugin update any posts that make use of this attachment.', 'regenerate-thumbnails' ),
|
||||
),
|
||||
'RegenerateMultiple' => array(
|
||||
'errorsEncountered' => __( 'Errors Encountered', 'regenerate-thumbnails' ),
|
||||
'regenerationLog' => __( 'Regeneration Log', 'regenerate-thumbnails' ),
|
||||
'pause' => __( 'Pause', 'regenerate-thumbnails' ),
|
||||
'resume' => __( 'Resume', 'regenerate-thumbnails' ),
|
||||
'logRegeneratedItem' => __( 'Regenerated {name}', 'regenerate-thumbnails' ),
|
||||
'logSkippedItem' => __( 'Skipped Attachment ID {id} ({name}): {reason}', 'regenerate-thumbnails' ),
|
||||
'logSkippedItemNoName' => __( 'Skipped Attachment ID {id}: {reason}', 'regenerate-thumbnails' ),
|
||||
'duration' => __( 'All done in {duration}.', 'regenerate-thumbnails' ),
|
||||
'hours' => __( '{count} hours', 'regenerate-thumbnails' ),
|
||||
'minutes' => __( '{count} minutes', 'regenerate-thumbnails' ),
|
||||
'seconds' => __( '{count} seconds', 'regenerate-thumbnails' ),
|
||||
'error' => __( "Unable to fetch a list of attachment IDs to process from the WordPress REST API. You can check your browser's console for details.", 'regenerate-thumbnails' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
// phpcs:enable
|
||||
|
||||
// Bulk regeneration
|
||||
// phpcs:disable WordPress.Security.NonceVerification
|
||||
if ( ! empty( $_GET['ids'] ) ) {
|
||||
$script_data['data']['thumbnailIDs'] = array_map( 'intval', explode( ',', $_GET['ids'] ) );
|
||||
|
||||
$script_data['l10n']['Home']['RegenerateThumbnailsForXAttachments'] = sprintf(
|
||||
__( 'Regenerate Thumbnails For The %d Selected Attachments', 'regenerate-thumbnails' ),
|
||||
count( $script_data['data']['thumbnailIDs'] )
|
||||
);
|
||||
}
|
||||
// phpcs:enable
|
||||
|
||||
wp_localize_script( 'regenerate-thumbnails', 'regenerateThumbnails', $script_data );
|
||||
|
||||
wp_enqueue_style(
|
||||
'regenerate-thumbnails-progressbar',
|
||||
plugins_url( 'css/progressbar.css', __FILE__ ),
|
||||
array(),
|
||||
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? filemtime( dirname( __FILE__ ) . '/css/progressbar.css' ) : $this->version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main Regenerate Thumbnails interface, as displayed at Tools → Regenerate Thumbnails.
|
||||
*/
|
||||
public function regenerate_interface() {
|
||||
global $wp_version;
|
||||
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>' . esc_html_x( 'Regenerate Thumbnails', 'admin page title', 'regenerate-thumbnails' ) . '</h1>';
|
||||
|
||||
if ( version_compare( $wp_version, '4.7', '<' ) ) {
|
||||
echo '<p>' . sprintf(
|
||||
__( 'This plugin requires WordPress 4.7 or newer. You are on version %1$s. Please <a href="%2$s">upgrade</a>.', 'regenerate-thumbnails' ),
|
||||
esc_html( $wp_version ),
|
||||
esc_url( admin_url( 'update-core.php' ) )
|
||||
) . '</p>';
|
||||
} else {
|
||||
|
||||
?>
|
||||
|
||||
<div id="regenerate-thumbnails-app">
|
||||
<div class="notice notice-error hide-if-js">
|
||||
<p><strong><?php esc_html_e( 'This tool requires that JavaScript be enabled to work.', 'regenerate-thumbnails' ); ?></strong></p>
|
||||
</div>
|
||||
|
||||
<router-view><p class="hide-if-no-js"><?php esc_html_e( 'Loading…', 'regenerate-thumbnails' ); ?></p></router-view>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
} // version_compare()
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* If the image editor doesn't support image resizing (thumbnailing), then add an admin notice
|
||||
* warning the user of this.
|
||||
*/
|
||||
public function add_admin_notice_if_resizing_not_supported() {
|
||||
if ( ! wp_image_editor_supports( array( 'methods' => array( 'resize' ) ) ) ) {
|
||||
add_action( 'admin_notices', array( $this, 'admin_notices_resizing_not_supported' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs an admin notice stating that image resizing (thumbnailing) is not supported.
|
||||
*/
|
||||
public function admin_notices_resizing_not_supported() {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p><strong><?php esc_html_e( "This tool won't be able to do anything because your server doesn't support image editing which means that WordPress can't create thumbnail images. Please ask your host to install the Imagick or GD PHP extensions.", 'regenerate-thumbnails' ); ?></strong></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a URL to regenerate a single image.
|
||||
*
|
||||
* @param int $id The attachment ID that should be regenerated.
|
||||
*
|
||||
* @return string The URL to the admin page.
|
||||
*/
|
||||
public function create_page_url( $id ) {
|
||||
return add_query_arg( 'page', 'regenerate-thumbnails', admin_url( 'tools.php' ) ) . '#/regenerate/' . $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an attachment can have its thumbnails regenerated.
|
||||
*
|
||||
* This includes checking to see if non-images, such as PDFs, are supported
|
||||
* by the current image editor.
|
||||
*
|
||||
* @param WP_Post $post An attachment's post object.
|
||||
*
|
||||
* @return bool Whether the given attachment can have its thumbnails regenerated.
|
||||
*/
|
||||
public function is_regeneratable( $post ) {
|
||||
if ( 'site-icon' === get_post_meta( $post->ID, '_wp_attachment_context', true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wp_attachment_is_image( $post ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_get_original_image_path' ) ) {
|
||||
$fullsize = wp_get_original_image_path( $post->ID );
|
||||
} else {
|
||||
$fullsize = get_attached_file( $post->ID );
|
||||
}
|
||||
|
||||
if ( ! $fullsize || ! file_exists( $fullsize ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$image_editor_args = array(
|
||||
'path' => $fullsize,
|
||||
'methods' => array( 'resize' )
|
||||
);
|
||||
|
||||
$file_info = wp_check_filetype( $image_editor_args['path'] );
|
||||
// If $file_info['type'] is false, then we let the editor attempt to
|
||||
// figure out the file type, rather than forcing a failure based on extension.
|
||||
if ( isset( $file_info ) && $file_info['type'] ) {
|
||||
$image_editor_args['mime_type'] = $file_info['type'];
|
||||
}
|
||||
|
||||
return (bool) _wp_image_editor_choose( $image_editor_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "Regenerate Thumbnails" below each image in the media library list view.
|
||||
*
|
||||
* @param array $actions An array of current actions.
|
||||
* @param WP_Post $post The current attachment's post object.
|
||||
*
|
||||
* @return array The new list of actions.
|
||||
*/
|
||||
public function add_regenerate_link_to_media_list_view( $actions, $post ) {
|
||||
if ( ! current_user_can( $this->capability ) || ! $this->is_regeneratable( $post ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$actions['regenerate_thumbnails'] = '<a href="' . esc_url( $this->create_page_url( $post->ID ) ) . '" title="' . esc_attr( __( 'Regenerate the thumbnails for this single image', 'regenerate-thumbnails' ) ) . '">' . _x( 'Regenerate Thumbnails', 'action for a single image', 'regenerate-thumbnails' ) . '</a>';
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "Regenerate Thumbnails" button to the submit box on the non-modal "Edit Media" screen for an image attachment.
|
||||
*/
|
||||
public function add_button_to_media_edit_page() {
|
||||
global $post;
|
||||
|
||||
if ( ! current_user_can( $this->capability ) || ! $this->is_regeneratable( $post ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="misc-pub-section misc-pub-regenerate-thumbnails">';
|
||||
echo '<a href="' . esc_url( $this->create_page_url( $post->ID ) ) . '" class="button-secondary button-large" title="' . esc_attr( __( 'Regenerate the thumbnails for this single image', 'regenerate-thumbnails' ) ) . '">' . _x( 'Regenerate Thumbnails', 'action for a single image', 'regenerate-thumbnails' ) . '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a "Regenerate Thumbnails" button to the edit media modal view.
|
||||
*
|
||||
* Ideally it would be down with the actions but I'm not good enough at JavaScript
|
||||
* in order to be able to do it, so instead I'm adding it to the bottom of the list
|
||||
* of media fields. Pull requests to improve this are welcome!
|
||||
*
|
||||
* @param array $form_fields An array of existing form fields.
|
||||
* @param WP_Post $post The current media item, as a post object.
|
||||
*
|
||||
* @return array The new array of form fields.
|
||||
*/
|
||||
public function add_button_to_edit_media_modal_fields_area( $form_fields, $post ) {
|
||||
if ( ! current_user_can( $this->capability ) || ! $this->is_regeneratable( $post ) ) {
|
||||
return $form_fields;
|
||||
}
|
||||
|
||||
$form_fields['regenerate_thumbnails'] = array(
|
||||
'label' => '',
|
||||
'input' => 'html',
|
||||
'html' => '<a href="' . esc_url( $this->create_page_url( $post->ID ) ) . '" class="button-secondary button-large" title="' . esc_attr( __( 'Regenerate the thumbnails for this single image', 'regenerate-thumbnails' ) ) . '">' . _x( 'Regenerate Thumbnails', 'action for a single image', 'regenerate-thumbnails' ) . '</a>',
|
||||
'show_in_modal' => true,
|
||||
'show_in_edit' => false,
|
||||
);
|
||||
|
||||
return $form_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Regenerate Thumbnails" to the bulk actions dropdown on the media list using Javascript.
|
||||
*/
|
||||
public function add_bulk_actions_via_javascript() {
|
||||
if ( ! current_user_can( $this->capability ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$('select[name^="action"] option:last-child').before(
|
||||
$('<option/>')
|
||||
.attr('value', 'bulk_regenerate_thumbnails')
|
||||
.text('<?php echo esc_js( _x( 'Regenerate Thumbnails', 'bulk actions dropdown', 'regenerate-thumbnails' ) ); ?>')
|
||||
);
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the submission of the new bulk actions entry and redirects to the admin page with the selected attachment IDs.
|
||||
*/
|
||||
public function bulk_action_handler() {
|
||||
if (
|
||||
empty( $_REQUEST['action'] ) ||
|
||||
empty( $_REQUEST['action2'] ) ||
|
||||
( 'bulk_regenerate_thumbnails' != $_REQUEST['action'] && 'bulk_regenerate_thumbnails' != $_REQUEST['action2'] ) ||
|
||||
empty( $_REQUEST['media'] ) ||
|
||||
! is_array( $_REQUEST['media'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_admin_referer( 'bulk-media' );
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => 'regenerate-thumbnails',
|
||||
'ids' => rawurlencode( implode( ',', array_map( 'intval', $_REQUEST['media'] ) ) ),
|
||||
),
|
||||
admin_url( 'tools.php' )
|
||||
)
|
||||
);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all thumbnail sizes, including their label, size, and crop setting.
|
||||
*
|
||||
* @return array An array, with the thumbnail label as the key and an array of thumbnail properties (width, height, crop).
|
||||
*/
|
||||
public function get_thumbnail_sizes() {
|
||||
global $_wp_additional_image_sizes;
|
||||
|
||||
$thumbnail_sizes = array();
|
||||
|
||||
foreach ( get_intermediate_image_sizes() as $size ) {
|
||||
$thumbnail_sizes[ $size ]['label'] = $size;
|
||||
if ( in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
|
||||
$thumbnail_sizes[ $size ]['width'] = (int) get_option( $size . '_size_w' );
|
||||
$thumbnail_sizes[ $size ]['height'] = (int) get_option( $size . '_size_h' );
|
||||
$thumbnail_sizes[ $size ]['crop'] = ( 'thumbnail' == $size ) ? (bool) get_option( 'thumbnail_crop' ) : false;
|
||||
} elseif ( ! empty( $_wp_additional_image_sizes ) && ! empty( $_wp_additional_image_sizes[ $size ] ) ) {
|
||||
$thumbnail_sizes[ $size ]['width'] = (int) $_wp_additional_image_sizes[ $size ]['width'];
|
||||
$thumbnail_sizes[ $size ]['height'] = (int) $_wp_additional_image_sizes[ $size ]['height'];
|
||||
$thumbnail_sizes[ $size ]['crop'] = (bool) $_wp_additional_image_sizes[ $size ]['crop'];
|
||||
}
|
||||
}
|
||||
|
||||
return $thumbnail_sizes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the single instance of this plugin, creating one if needed.
|
||||
*
|
||||
* @return RegenerateThumbnails
|
||||
*/
|
||||
function RegenerateThumbnails() {
|
||||
return RegenerateThumbnails::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this plugin once all other plugins have finished loading.
|
||||
*/
|
||||
add_action( 'init', 'RegenerateThumbnails' );
|
Reference in New Issue
Block a user