Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_empty() method to validate numeric pick values #5776

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions classes/fields/pick.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,34 @@ public function schema( $options = null ) {

}

/**
JoryHogeveen marked this conversation as resolved.
Show resolved Hide resolved
* @todo 2.8 Centralize the usage of this method. See PR #5540.
* {@inheritdoc}
*/
public function is_empty( $value = null ) {

$is_empty = false;

if ( is_array( $value ) ) {
foreach ( $value as $key => $val ) {
if ( $this->is_empty( $val ) ) {
unset( $value[ $key ] );
}
}
}

/**
* @todo Find a way to check for relationship type before comparing to `0` as this is still empty for posts/terms/users etc.
* Currently not possible since this method doesn't get any options passed as parameters.
*/
if ( empty( $value ) && '0' !== (string) $value ) {
$is_empty = true;
}

return $is_empty;

}

/**
* {@inheritdoc}
*/
Expand Down