I created a plugin that creates a new image size and turns it B&W.
I need the script to throw an notice if the user upload an image smaller then 1000x1000.
I tried this, but Wordpress is ignoring it, it just gives me a general HTTP error.
GENERATE IMAGE SIZE
function register_watermarked_size() {
add_image_size( 'watermarked', 1000, 1000 );
}
add_action( 'init', 'register_watermarked_size' );
GENERATE IMAGE Here I check the image size.
function generate_watermarked_image( $meta ) {
if ( $meta['width'] < 1000 && $meta['height'] < 1000 ) {
add_action( 'admin_notices', array( $this, 'watermark_error') );
}
else {
// do some stuff...
return $meta;
}
}
add_filter( 'wp_generate_attachment_metadata', 'generate_watermarked_image' );
ERROR MESSAGE METHOD
function watermark_error() {
$class = 'notice notice-error';
$message = "Sorry, this image cannot be uploaded. \nEach side must be longer than 1000px.";
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}