xprofile_set_field_data(INT |串$字段int$ USER_ID混合美元的价值保龄球is_required美元=的)

一个简单的函数来设置简档数据用于为特定用户的特定字段。

描述

参数

$字段

int|字符串的)(必需)字段的ID,或者字段的$name。

$ USER_ID

int的)(必需)的用户的ID。

美元的价值

混合的)(必需)要为用户设置的字段的值。

is_required美元

保龄球的)(可选的)无论是否需要现场。

默认值:假

返回

(布尔)成功时真,失败时假。

文件:bp-xprofile / bp-xprofile-functions.php

功能xprofile_set_field_data($字段,$ USER_ID,$值,$ is_required =假){如果(is_numeric($场)){$ FIELD_ID = $字段;}否则{$ = FIELD_ID xprofile_get_field_id_from_name($字段);}如果(空($ FIELD_ID)){返回FALSE;} $字段= xprofile_get_field($ FIELD_ID);$ field_type = BP_XProfile_Field :: get_type($ FIELD_ID);$ field_type_obj = bp_xprofile_create_field_type($ field_type);/ ** *过滤原始提交的个人资料字段值。* *使用此过滤器做现场型专用验证之前*修改用户提交的值。* * @since BuddyPress的2.1.0 * * @参数混合$值值传递给xprofile_set_field_data()。* @参数BP_XProfile_Field $场Field对象。 * @param BP_XProfile_Field_Type $field_type_obj Field type object. */ $value = apply_filters( 'bp_xprofile_set_field_data_pre_validate', $value, $field, $field_type_obj ); // Special-case support for integer 0 for the number field type. if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) { return false; } /** * Certain types of fields (checkboxes, multiselects) may come through empty. * Save as empty array so this isn't overwritten by the default on next edit. * * Special-case support for integer 0 for the number field type */ if ( empty( $value ) && ! is_integer( $value ) && $value !== '0' && $field_type_obj->accepts_null_value ) { $value = array(); } // If the value is empty, then delete any field data that exists, unless the field is of a type // where null values are semantically meaningful. if ( empty( $value ) && ! is_integer( $value ) && $value !== '0' && ! $field_type_obj->accepts_null_value ) { xprofile_delete_field_data( $field_id, $user_id ); return true; } // For certain fields, only certain parameters are acceptable, so add them to the whitelist. if ( $field_type_obj->supports_options ) { $field_type_obj->set_whitelist_values( wp_list_pluck( $field->get_children(), 'name' ) ); } // Check the value is in an accepted format for this form field. if ( ! $field_type_obj->is_valid( $value ) ) { return false; } $field = new BP_XProfile_ProfileData(); $field->field_id = $field_id; $field->user_id = $user_id; // Gets un/reserialized via xprofile_sanitize_data_value_before_save() $field->value = maybe_serialize( $value ); return $field->save(); }

变更乐

变更乐
版本 描述
BuddyPress 1.0.0 介绍了。

问题?

我们总是与代码或者你可能有其他问题,乐于帮助!搜索我们开发文档联络支持,或与我们联系销售团队