• Hi,

    I am trying to exclude some images and using this filter but it doesn’t work (exclude image which has width < 500).

    Please help!

    /**
    	 * This filter allows to programatically prevent watermarking certain
    	 * attachment if <code>false</code> returned from attached function.
    	 *
    	 * @param boolean   $should_apply       Whether the image should be watermarked. Return false to prevent watermarking.
    	 * @param Watermark $watermark          Watermark object.
    	 * @param integer   $attachment_id      Attachment ID.
    	 * @param WP_Post   $attachment         Attachment post.
    	 * @param array     $meta               Attachment metadata.
    	 * @param array     $applied_watermarks Array containing all watermarks applied to this attaachment.
    	 * 	
    	 */
    
    add_filter( 'easy-watermark/should-apply-watermark','dont_watermark', 10, 6 );
    function dont_watermark ($is_watermark, $watermark, $attachment_id, $attachment, $meta, $applied_watermarks)
    	{	
    		//$meta = wp_get_attachment_metadata($attachment_id);
    		//echo 'tada';
    		//$title 		= 'Image Debug';
    		$width 	= $meta['width'];
    		// $message 	= '300px';
    		// //$parent 	= 1; // This might be the ID of a payment post type item we want this log item connected to
    		// //$type 		= 'event';
    
    		// //WP_Logging::add( $title, $message, $parent, $type );
    		// WP_Logging::add( $title, $message );
    
    		if( $meta['width'] < 500 ) {
    			$is_watermark = false;//no WM
    		} else {
    			$is_watermark = true;
    		}
    		return $is_watermark;
    
    	}
    • This topic was modified 3 years, 11 months ago by Giang Le.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi, it looks good, but there’s a couple of things to check:

    – does it ever execute this filter?
    – what’s in the $meta var exactly, can you confirm you get the values expected?

    Thread Starter Giang Le

    (@gianghl1983)

    @kubitomakita Thanks for your reply! No it does not execute the filter (code did not run). I am not so sure what $meta is (your code….) but I suppose it has value with $meta = wp_get_attachment_metadata($attachment_id); –> $meta[‘width’]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude image with low width?’ is closed to new replies.