Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only first declared size for each aspect ratio is supported #11

Open
kadamwhite opened this issue Jun 25, 2018 · 1 comment
Open

Only first declared size for each aspect ratio is supported #11

kadamwhite opened this issue Jun 25, 2018 · 1 comment

Comments

@kadamwhite
Copy link

The doc block for get_image_sizes_by_ratio() specifies that the method "Gets the first size defined for each dimension." This makes some sense if all sizes are cropped alike for a given aspect ratio, but it does mean that passing any declared image size other than the first in the image_ratio_map list causes an error because of these lines:

if ( empty( $_REQUEST['size'] ) || ! in_array( $_REQUEST['size'], $this->get_image_sizes_by_ratio() ) )
	wp_die( sprintf( __( 'Invalid %s parameter.', 'wpcom-thumbnail-editor' ), '<code>size</code>' ) );

If this is expected behavior, the documentation should be improved to explain that regardless of the size in an aspect ratio that we want to edit, we have to pass the first declared image size in $this->image_ratio_map[$ratio].

If you should be able to pass another image size name that is present in $this->image_ratio_map[$ratio] other than $this->image_ratio_map[$ratio][0], then the get_image_sizes_by_ratio method should be amended to return a more comprehensive list, or else the $_REQUEST['size'] check should be changed to validate against the full list of supported names for a given ratio.

@kadamwhite
Copy link
Author

Forgot steps to reproduce:

Expected

When declaring multiple image sizes for a given ratio:

add_filter( 'wpcom_thumbnail_editor_args', function( array $args ) {
	$args['image_ratio_map'] = array(
		'Landscape' => array(
			'vipclient-landscape-small',
			'vipclient-landscape-medium',
		),
	);
	return $args;
} );

then passing any one of the declared sizes for the Landscape ratio should be valid, e.g.

vipsite.local/wp-admin/?action=wpcom_thumbnail_edit&id=497&size=vipsite-landscape-medium&ratio=Landscape

(where vipsite.local is any environment on which this plugin is active).

Actual

Passing vipsite-landscape-small works, but vipsite-landscape-medium shows the error
invalid size parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant