From 21a4f221c6635f676d991bc5d180c2eda4a09248 Mon Sep 17 00:00:00 2001 From: Test Valley School Date: Wed, 27 Jul 2016 10:21:32 +0100 Subject: [PATCH] `$value` in `slug_update_spaceship` not set if it evalues to false If you check for `! $value` in the validation in the example callback method `slug_update_spaceship`, a string value of `'0'` (or anything else that PHP evaluates to false) will be ignored and that post meta field will not be updated. Since `'0'` might be a desired post meta value, I propose changing the validation on this line to instead check `isset` and ensure the string's length is >0. --- extending/modifying/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extending/modifying/index.md b/extending/modifying/index.md index b9160d3..269f1a0 100644 --- a/extending/modifying/index.md +++ b/extending/modifying/index.md @@ -128,7 +128,7 @@ function slug_get_spaceship( $object, $field_name, $request ) { * @return bool|int */ function slug_update_spaceship( $value, $object, $field_name ) { - if ( ! $value || ! is_string( $value ) ) { + if ( ! isset( $value ) || ! is_string( $value ) || strlen( $value ) < 1 ) { return; }