Require minimum dimensions for featured image on CRED form

Use the cred_form_validate filter to specify featured image size requirements on a CRED form.

function validate_featured_image_size( $field_data, $form_data ){

	$form_id = array( 183 ); // add IDs of CRED forms

	$min_width = 300; // Edit
	$min_height = 200; // Edit

	if ( in_array( $form_data['id'], $form_id ) ) {

	    // Split field data into field values and errors
	    list( $fields,$errors ) = $field_data;

	    $check = getimagesize( $fields['_featured_image']['value'] );

	    if ( $check !== false ) {

	    	$width = $check[0];
	    	$height = $check[1];

	    	if ( $width < $min_width || $height < $min_height ) {
	    		$errors['_featured_image'] = "Image is too small";
	    	}
	    }

	    $field_data = array($fields,$errors);
	}

	return $field_data;
}
add_action( 'cred_form_validate', 'validate_featured_image_size', 10, 2 );

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments