Demo Plugin – Fixed Size
Here’s one suggestion as a demo plugin (PHP 5.4+):
<?php
/* Plugin Name: Custom Playlist Thumb Size */
namespace WPSE238646\PlaylistThumbSize;
add_shortcode( 'playlist', function( $atts = [], $content="" )
{
add_filter( 'wp_get_attachment_image_src', __NAMESPACE__ . '\\src' , 10, 3 );
$out = wp_playlist_shortcode( $atts, $content );
remove_filter( 'wp_get_attachment_image_src', __NAMESPACE__ . '\\src' );
return $out;
} );
function src( $image, $id, $size )
{
add_filter( 'image_downsize', __NAMESPACE__ . '\\size', 10, 3 );
return $image;
}
function size( $downsize, $id, $size )
{
remove_filter( current_filter(), __FUNCTION__ );
if( 'thumbnail' !== $size )
return $downsize;
return image_downsize( $id, $size="large" ); // <-- Adjust size here!
}
Here we change the thumb size from 'thumbnail'
to 'large'
.
First we override the playlist shortcode callback, to better scope our filters and only target the playlist shortcodes.
Then we hook into the image_downsize
filter to our needs, to call the image_downsize()
function with the wanted thumb size. But we must remember to remove our filter callback right away to avoid an infinite recursive loop.
Demo Plugin – Various Sizes
But it would be more flexible if we could write the thumb size as a shortcode attribute:
Here we prefix our _size
attribute with an underscore, just in case it gets supported by core in the future.
Here’s a modification of our first demo plugin to support that (in a compact form):
<?php
/* Plugin Name: Playlist With _size Attribute */
namespace WPSE238646\PlaylistThumbSize;
add_shortcode( 'playlist', [ (new Playlist), 'shortcode' ] );
class Playlist
{
protected $_size;
public function shortcode( $atts = [], $content="" )
{
$allowed_sizes = (array) get_intermediate_image_sizes(); // <-- Allowed sizes
$this->_size="thumbnail"; // <-- Default size
if( ! empty( $atts['_size' ] ) && in_array( $atts['_size' ], $allowed_sizes ) )
$this->_size = $atts['_size' ];
add_filter( 'wp_get_attachment_image_src', [ $this, 'src' ] , 10, 3 );
$out = wp_playlist_shortcode( $atts, $content ); // <-- Native playlist
remove_filter( 'wp_get_attachment_image_src', [ $this, 'src' ] );
return $out;
}
public function src( $image, $id, $size )
{
add_filter( 'image_downsize', [ $this, 'size' ], 10, 3 );
return $image;
}
public function size( $downsize, $id, $size )
{
remove_filter( current_filter(), [ $this, 'size' ] );
if( 'thumbnail' !== $size )
return $downsize;
return image_downsize( $id, $this->_size ); // <--Apply new size
}
} // end class
Here we restrict the allowed sizes to get_intermediate_image_sizes()
.
Hopefully you can test this further and adjust to your needs!