验证配置文件字段

Validate a profile field

在 buddypress 中,我在配置文件中添加了一个名为 zip code 的字段,类型为 number

我需要在将数据保存到数据库之前validate/cleanup这个字段,buddypress支持这样做吗?是否有任何 buddypress action/filter 让我们 运行 我对此字段的自定义验证?

function myvalidator($retval, $field){
    // $field->field_id <- from wp_bp_xprofile_fields table 
    //                     find id for your field
    // $field->value    <- this is the value you need to validate
    //                     (make sure $field->field_id is correct
    // $field->user_id

    if (/* valid */){
        return true;
    } else {
        return false;
    }

    // for other field_ids return $retval
}


add_filter( 'xprofile_data_is_valid_field', 'myvalidator', 10, 2 )