Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created November 12, 2015 01:38
Show Gist options
  • Save lgedeon/c4ae9f39548e6e6f10cf to your computer and use it in GitHub Desktop.
Save lgedeon/c4ae9f39548e6e6f10cf to your computer and use it in GitHub Desktop.
Sample code for filtering an ACF (Advanced Custom Field plugin) field on update.
<?php
function filter__acf_update_value( $value, $post_id, $field ) {
$post_type = get_post_type( $post_id );
$meta = wp_get_attachment_metadata($value);
if ( intval( $meta['width'] ) < 300 || intval( $meta['height'] ) < 300 ) {
$value = null;
do_action( 'simple_admin_notice', "Selected image (.../{$meta['file']}) was less than 300 x 300. Please select a different image.", 'error' );
}
return $value;
}
add_filter('acf/update_value/name=image', 'filter__acf_update_value', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment