xprofile_admin_manage_field (intgroup_id美元int |零field_id美元

处理用户配置文件字段数据的添加或编辑。

描述

参数

group_id美元

int(必需)组ID。

field_id美元

int|(可选)被管理字段的ID。

默认值:空

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

函数xprofile_admin_manage_field($group_id, $field_id = null) {global $wpdb, $message, $groups;英国石油美元= buddypress ();if (is_null($field_id)) {$field = new BP_XProfile_Field();新的美元= true;} else {$field = xprofile_get_field($field_id);新的美元= false;} $field->group_id = $group_id;if (isset($_POST['saveField']){//检查nonce check_admin_referer('bp_xprofile_admin_field', 'bp_xprofile_admin_field');if (BP_XProfile_Field::admin_validate()) {$field->is_required = $_POST['required'];场- > type = $ _POST [' fieldtype ']; $field->name = $_POST['title']; if ( 'socialnetworks' === $field->type ) { if ( true === $new ) { $disabled_social_networks = false; $exists_social_networks = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}bp_xprofile_fields a WHERE parent_id = 0 AND type = 'socialnetworks' " ); if ( $exists_social_networks > 0 ) { $disabled_social_networks = true; } if ( true === $disabled_social_networks ) { $message = __( 'You can only have one instance of the "Social Network" profile field.','buddyboss' ); $type = 'error'; $field->render_admin_form( $message, $type ); return false; } } } if ( ! empty( $_POST['description'] ) ) { $field->description = $_POST['description']; } else { $field->description = ''; } if ( ! empty( $_POST["sort_order_{$field->type}"] ) ) { $field->order_by = $_POST["sort_order_{$field->type}"]; } $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) ); if ( ! is_numeric( $field->field_order ) || is_wp_error( $field->field_order ) ) { //cloned fields should not be considered when determining the max order of fields in given group $cloned_field_ids = $wpdb->get_col( $wpdb->prepare( "SELECT f.id FROM {$bp->profile->table_name_fields} AS f JOIN {$bp->profile->table_name_meta} AS fm ON f.id = fm.object_id " . " WHERE f.group_id = %d AND fm.meta_key = '_is_repeater_clone' AND fm.meta_value = 1 ", $group_id ) ); if ( !empty( $cloned_field_ids ) ) { $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND id NOT IN ( ". implode( ',', $cloned_field_ids ) ." )", $group_id ) ); } else { $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) ); } $field->field_order++; } // For new profile fields, set the $field_id. For existing profile // fields, this will overwrite $field_id with the same value. $field_id = $field->save(); if ( empty( $field_id ) ) { $message = __( 'There was an error saving the field. Please try again.', 'buddyboss' ); $type = 'error'; } else { $message = __( 'The field was saved successfully.', 'buddyboss' ); $type = 'updated'; // Set profile types. if ( isset( $_POST['has-member-types'] ) ) { $member_types = array(); if ( isset( $_POST['member-types'] ) ) { $member_types = stripslashes_deep( $_POST['member-types'] ); } $field->set_member_types( $member_types ); } // Validate default visibility. if ( ! empty( $_POST['default-visibility'] ) && in_array( $_POST['default-visibility'], wp_list_pluck( bp_xprofile_get_visibility_levels(), 'id' ) ) ) { bp_xprofile_update_field_meta( $field_id, 'default_visibility', $_POST['default-visibility'] ); } // Validate custom visibility. if ( ! empty( $_POST['allow-custom-visibility'] ) && in_array( $_POST['allow-custom-visibility'], array( 'allowed', 'disabled' ) ) ) { bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility'] ); } // Update alternate name. $alternate_name = isset( $_POST['title_secondary'] ) ? $_POST['title_secondary'] : ''; bp_xprofile_update_field_meta( $field_id, 'alternate_name', $alternate_name ); // Validate signup. if ( ! empty( $_POST['signup-position'] ) ) { bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] ); } else { bp_xprofile_delete_meta( $field_id, 'field', 'signup_position' ); } if ( $field->type_obj->do_settings_section() ) { $settings = isset( $_POST['field-settings'] ) ? wp_unslash( $_POST['field-settings'] ) : array(); $field->admin_save_settings( $settings ); } /** * Fires at the end of the process to save a field for a user, if successful. * * @since BuddyPress 1.0.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field object. */ do_action( 'xprofile_fields_saved_field', $field ); $groups = bp_xprofile_get_groups(); } $field->render_admin_form( $message, $type ); // Users Admin URL $users_url = bp_get_admin_url( 'admin.php' ); $redirect = add_query_arg( array( 'page' => 'bp-profile-setup', 'mode' => 'edit_field', 'group_id' => (int) $group_id, 'type' => $type, 'field_id' => (int) $field_id ), $users_url ); wp_safe_redirect( $redirect ); exit(); } else { $field->render_admin_form( $message ); } } else { $field->render_admin_form(); } }

更新日志

更新日志
版本 描述
BuddyPress 1.0.0 BuddyPress 1.0.0
BuddyBoss 1.0.0更新以继续显示字段编辑表单,在字段保存/更新后。更新为在确定新字段的field_order时排除中继字段id。 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队