Home › Forums › Backend Issues (wp-admin) › PHP Unrequire Field › Reply To: PHP Unrequire Field
So the validation is run on admin-ajax.php
which invalidate the $pagenow
. Maybe there’s a better way to do this but I just made 2 arrays to check against both the global and the referrer.
Open to way to make the below and above better
/**
* Ensure our particular fields pass validation
*
* @param Boolean $valid
*
* @return Boolean $valid
*/
function theme_acf_nonrequired_fields_validate( $valid ) {
global $pagenow;
$acceptable_pagenows = array( 'user-new.php', 'user-edit.php', 'profile.php' );
$acceptable_referers = array( '/wp-admin/user-new.php', '/wp-admin/user-edit.php', '/wp-admin/profile.php' );
if( ! is_admin() || ! current_user_can( 'edit_posts' ) ) {
return $valid;
}
if( ! ( in_array( $pagenow, $acceptable_pagenows ) ||
( isset( $_REQUEST, $_REQUEST['_wp_http_referer'] ) && in_array( $_REQUEST['_wp_http_referer'], $acceptable_referers ) ) )
) {
return $valid;
}
return true;
}
add_filter( 'acf/validate_value/name=cust_name', 'theme_acf_nonrequired_fields_validate' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.