wmguru_max_pixels() ) ) { return null; } // Never watermark the watermark image itself. foreach ( (array) $profile['layers'] as $layer ) { if ( isset( $layer['attachment_id'] ) && (int) $layer['attachment_id'] === (int) $attachment_id ) { return null; } } $memo[ $memo_key ] = $profile; return $profile; } /** * "Do not watermark" checkbox on the attachment edit screen and media modal. * * @param array $fields Fields. * @param WP_Post $post Attachment. * @return array */ function wmguru_attachment_fields( $fields, $post ) { if ( ! wp_attachment_is_image( $post ) ) { return $fields; } $checked = get_post_meta( $post->ID, '_wmguru_exclude', true ) ? ' checked="checked"' : ''; $fields['wmguru_exclude'] = array( 'label' => __( 'Watermark', 'filigrane' ), 'input' => 'html', 'html' => '', ); return $fields; } add_filter( 'attachment_fields_to_edit', 'wmguru_attachment_fields', 10, 2 ); /** * @param array $post Post data. * @param array $attachment Submitted fields. * @return array */ function wmguru_attachment_fields_save( $post, $attachment ) { if ( current_user_can( 'edit_post', $post['ID'] ) ) { if ( ! empty( $attachment['wmguru_exclude'] ) ) { update_post_meta( $post['ID'], '_wmguru_exclude', 1 ); } else { delete_post_meta( $post['ID'], '_wmguru_exclude' ); } } return $post; } add_filter( 'attachment_fields_to_save', 'wmguru_attachment_fields_save', 10, 2 ); /** * Cached copies go stale when the source file changes (regenerated thumbnails, * edited/replaced images) or the attachment is deleted. * * @param array $data Attachment metadata. * @param int $attachment_id Attachment id. * @return array */ function wmguru_purge_on_metadata_update( $data, $attachment_id ) { wmguru_purge_attachment( $attachment_id, $data ); return $data; } add_filter( 'wp_update_attachment_metadata', 'wmguru_purge_on_metadata_update', 10, 2 ); add_action( 'delete_attachment', 'wmguru_purge_attachment' );