Created
October 21, 2020 22:03
-
-
Save tripflex/d4ad477ee21e795bb8d87404cb85a2ce to your computer and use it in GitHub Desktop.
Require minimum file uploads when using WP Job Manager Field Editor
This file contains 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 | |
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