Created
November 12, 2015 01:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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