Hi john i used your code but wordpress returned an error i fixed in by using
if ((!is_array($value)) || (!count($value))) {
instead of if (!is_array($value)) || !count($value)) {
in your code …problem was caused due parantheses … and thank you for your code it saved my time and life 🙂