Skip to content

Commit

Permalink
Merge pull request #88 from Automattic/master
Browse files Browse the repository at this point in the history
Merging versions 3.1.1 and 3.1.2. Thanks Boro for the help!
  • Loading branch information
donnchawp authored Dec 3, 2019
2 parents 736df85 + 26d35e2 commit cc1a5c5
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The latest release can be [downloaded from WordPress.org](https://wordpress.org/

2. Clone this repository inside your `plugins` directory:
```
$ git clone https://github.com/Viper007Bond/regenerate-thumbnails.git
$ git clone https://github.com/automattic/regenerate-thumbnails.git
$ cd regenerate-thumbnails
```

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "viper007bond/regenerate-thumbnails",
"name": "automattic/regenerate-thumbnails",
"description": "Regenerate the thumbnails for one or more of your image uploads. Useful when changing their sizes or your theme.",
"homepage": "https://alex.blog/wordpress-plugins/regenerate-thumbnails/",
"type": "wordpress-plugin",
Expand All @@ -12,7 +12,7 @@
}
],
"support": {
"issues": "https://github.com/Viper007Bond/regenerate-thumbnails/issues"
"issues": "https://github.com/automattic/regenerate-thumbnails/issues"
},
"require": {
"php": ">=5.2.4",
Expand Down
6 changes: 5 additions & 1 deletion includes/class-regeneratethumbnails-regenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ public function get_fullsizepath() {
return $this->fullsizepath;
}

$this->fullsizepath = get_attached_file( $this->attachment->ID );
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(
Expand Down
4 changes: 4 additions & 0 deletions includes/class-regeneratethumbnails-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public function featured_images( $request ) {
$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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"license": "GPL-2.0+",
"repository": {
"type": "git",
"url": "git+https://github.com/Viper007Bond/regenerate-thumbnails.git"
"url": "git+https://github.com/automattic/regenerate-thumbnails.git"
},
"bugs": {
"url": "https://github.com/Viper007Bond/regenerate-thumbnails/issues"
"url": "https://github.com/automattic/regenerate-thumbnails/issues"
},
"scripts": {
"build": "yarn install-if-deps-outdated && cross-env NODE_ENV=development webpack --progress --hide-modules",
Expand Down
20 changes: 17 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: Viper007Bond
Tags: thumbnail, thumbnails, post thumbnail, post thumbnails
Requires at least: 4.7
Tested up to: 5.0
Tested up to: 5.3
Requires PHP: 5.2.4
Stable tag: trunk
Stable tag: 3.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -22,6 +22,10 @@ This is useful for situations such as:

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**
Expand All @@ -42,7 +46,7 @@ I personally use Photon on my own website.

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/Viper007Bond/regenerate-thumbnails).
The source code for this plugin is available on [GitHub](https://github.com/automattic/regenerate-thumbnails).

== Installation ==

Expand All @@ -68,6 +72,13 @@ This plugin does not log nor transmit any user data. Infact it doesn't even do a

== ChangeLog ==

= 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).
Expand Down Expand Up @@ -168,3 +179,6 @@ Lots of new features!
= Version 1.0.0 =

* Initial release.

= Upgrade Notice =
Support for WordPress 5.3
8 changes: 6 additions & 2 deletions regenerate-thumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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.0
Version: 3.1.2
Author: Alex Mills (Viper007Bond)
Author URI: https://alex.blog/
Text Domain: regenerate-thumbnails
Expand Down Expand Up @@ -392,7 +392,11 @@ public function is_regeneratable( $post ) {
return true;
}

$fullsize = get_attached_file( $post->ID );
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;
Expand Down
60 changes: 49 additions & 11 deletions tests/test-regenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public function test_not_attachment() {
public function test_missing_original_file() {
$this->attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );

unlink( get_attached_file( $this->attachment_id ) );
if ( function_exists( 'wp_get_original_image_path' ) ) {
unlink( wp_get_original_image_path( $this->attachment_id ) );
} else {
unlink( get_attached_file( $this->attachment_id ) );
}

$regenerator = RegenerateThumbnails_Regenerator::get_instance( $this->attachment_id );
$result = $regenerator->regenerate();
Expand All @@ -126,7 +130,11 @@ public function test_regenerate_thumbnails_to_new_sizes() {
$this->attachment_id = $this->helper_create_attachment();
$old_metadata = wp_get_attachment_metadata( $this->attachment_id );

$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
if ( function_exists( 'wp_get_original_image_path' ) ) {
$upload_dir = dirname( wp_get_original_image_path( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
} else {
$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
}

$expected_default_thumbnail_sizes = array(
'thumbnail' => array( 150, 150 ),
Expand Down Expand Up @@ -184,7 +192,11 @@ public function test_regenerate_thumbnails_for_pdf() {
$this->attachment_id = self::factory()->attachment->create_upload_object( $test_pdf );
$old_metadata = wp_get_attachment_metadata( $this->attachment_id );

$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
if ( function_exists( 'wp_get_original_image_path' ) ) {
$upload_dir = dirname( wp_get_original_image_path( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
} else {
$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
}

$expected_default_thumbnail_sizes = array(
'thumbnail' => array( 116, 150 ),
Expand Down Expand Up @@ -254,7 +266,11 @@ public function helper_regenerate_thumbnails_skipping_existing_thumbnails( $only
'large' => '33772-1024x576.jpg',
);

$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
if ( function_exists( 'wp_get_original_image_path' ) ) {
$upload_dir = dirname( wp_get_original_image_path( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
} else {
$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
}
$filemtimes = $this->helper_get_filemtimes( $upload_dir, $thumbnails );

// Delete some of the thumbnail files
Expand Down Expand Up @@ -310,9 +326,15 @@ public function helper_delete_unregistered_thumbnail_files( $delete_unregistered
$this->assertArrayHasKey( 'regenerate-thumbnails-test-inmeta', $old_metadata['sizes'] );
$this->assertArrayHasKey( 'regenerate-thumbnails-test-notinmeta', $old_metadata['sizes'] );

$thumbnail_file_inmeta = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR . $old_metadata['sizes']['regenerate-thumbnails-test-inmeta']['file'];
$thumbnail_file_notinmeta = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR . $old_metadata['sizes']['regenerate-thumbnails-test-notinmeta']['file'];
$thumbnail_file_to_keep = get_attached_file( $attachment_to_keep_id );
if ( function_exists( 'wp_get_original_image_path' ) ) {
$thumbnail_file_to_keep = wp_get_original_image_path( $attachment_to_keep_id );
$fullsize_image = wp_get_original_image_path( $this->attachment_id );
} else {
$thumbnail_file_to_keep = get_attached_file( $attachment_to_keep_id );
$fullsize_image = get_attached_file( $this->attachment_id );
}
$thumbnail_file_inmeta = dirname( $fullsize_image ) . DIRECTORY_SEPARATOR . $old_metadata['sizes']['regenerate-thumbnails-test-inmeta']['file'];
$thumbnail_file_notinmeta = dirname( $fullsize_image ) . DIRECTORY_SEPARATOR . $old_metadata['sizes']['regenerate-thumbnails-test-notinmeta']['file'];

$this->assertFileExists( $thumbnail_file_inmeta );
$this->assertFileExists( $thumbnail_file_notinmeta );
Expand All @@ -322,7 +344,11 @@ public function helper_delete_unregistered_thumbnail_files( $delete_unregistered

// After this, "inmeta" will be in the meta and "notinmeta" will exist but not be in the meta
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
$step2_metadata = wp_generate_attachment_metadata( $this->attachment_id, get_attached_file( $this->attachment_id ) );
if ( function_exists( 'wp_get_original_image_path' ) ) {
$step2_metadata = wp_generate_attachment_metadata( $this->attachment_id, wp_get_original_image_path( $this->attachment_id ) );
} else {
$step2_metadata = wp_generate_attachment_metadata( $this->attachment_id, get_attached_file( $this->attachment_id ) );
}
wp_update_attachment_metadata( $this->attachment_id, $step2_metadata );

$step2_metadata = wp_get_attachment_metadata( $this->attachment_id );
Expand Down Expand Up @@ -384,7 +410,11 @@ public function test_verify_that_site_icons_are_not_regenerated() {
$thumbnails[ $size ] = $size_data['file'];
}

$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
if ( function_exists( 'wp_get_original_image_path' ) ) {
$upload_dir = dirname( wp_get_original_image_path( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
} else {
$upload_dir = dirname( get_attached_file( $this->attachment_id ) ) . DIRECTORY_SEPARATOR;
}

$filemtimes = $this->helper_get_filemtimes( $upload_dir, $thumbnails );

Expand Down Expand Up @@ -465,7 +495,11 @@ public function test_update_usages_in_posts() {

public function helper_get_current_thumbnail_statuses() {
$attachment = get_post( $this->attachment_id );
$fullsizepath = get_attached_file( $this->attachment_id );
if ( function_exists( 'wp_get_original_image_path' ) ) {
$fullsizepath = wp_get_original_image_path( $this->attachment_id );
} else {
$fullsizepath = get_attached_file( $this->attachment_id );
}

return array(
'name' => $attachment->post_title,
Expand Down Expand Up @@ -574,7 +608,11 @@ public function test_get_current_thumbnail_statuses_utf8_filename() {

$this->attachment_id = $this->helper_create_upload_object_utf8( $test_file_path );

$fullsizepath = get_attached_file( $this->attachment_id );
if ( function_exists( 'wp_get_original_image_path' ) ) {
$fullsizepath = wp_get_original_image_path( $this->attachment_id );
} else {
$fullsizepath = get_attached_file( $this->attachment_id );
}

$regenerator = RegenerateThumbnails_Regenerator::get_instance( $this->attachment_id );
$statuses = $regenerator->get_attachment_info();
Expand Down

0 comments on commit cc1a5c5

Please sign in to comment.