Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created October 21, 2020 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/d4ad477ee21e795bb8d87404cb85a2ce to your computer and use it in GitHub Desktop.
Save tripflex/d4ad477ee21e795bb8d87404cb85a2ce to your computer and use it in GitHub Desktop.
Require minimum file uploads when using WP Job Manager Field Editor
<?php
add_filter( 'submit_job_form_validate_fields', 'smyles_check_min_upload_files', 9999, 3 );
/**
* Check Min Uploaded Files
*
* @param $no_errors
* @param $fields
* @param $values
*
* @return \WP_Error|true
* @since @@version
*
*/
function smyles_check_min_upload_files( $no_errors, $fields, $values ){
$min_uploads = 4;
$error_message = sprintf( __( 'The minimum files is %1$s for %2$s' ), $min_uploads, __( 'Gallery Images' ) );
if( ! isset( $values['job'], $values['job']['gallery_images'] ) ){
return new WP_Error( 'validation-error', $error_message );
}
if( count( $values['job']['gallery_images'] ) < $min_uploads ){
return new WP_Error( 'validation-error', $error_message );
}
return $no_errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment