无法在另一个表单/页面中显示来自 Ultimate Member 的选择框。我想出了一个解决方案......但它仍然不够好,它没有更新选择框......
//fields that you want to display... meta_keys
function custom_feild_meta(){
return $feild_meta = array("first_name", 'last_name', "GrandFather_Name", "Brach_Name", "Family_Name", "Family_Name_41", "mobile_number_38", "user_email", "mobile_number", "Secondary_System", "mobile_number_38_37_37", "mobile_number_38_37", "mobile_number_38_37_37_37", "Guardian_Name", "phone_number", "country", "City_26_27_29_30_31_32_33_34_35_36", "City_26", "City", "City_26_27_29", "City_26_27", "City_26_27_29_30_31", "City_26_27_29_30_31_32", "City_26_27_29_30", "City_26_27_29_30_31_32_33", "City_26_27_29_30_31_32_33_34", "City_26_27_29_30_31_32_33_34_35", "City_26_27_28", "City_26_27_29_30_31_32_33_34_35_36_37", "Note_42"); //feilds feilds meta name to display
}
//display fields
function showUMExtraFields()
{
print('<h3>Extra profile information</h3>');
ob_start();
$id = um_user('ID');
// $id = UM()->user()->target_id;
$output = '<div class="um-field">';
$tame;
$names = custom_feild_meta();
$fields = array();
foreach ($names as $name) {
$fields[$name] = UM()->builtin()->get_specific_field($name);
}
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach ($fields as $key => $data) {
//if it is a select box
if($data['type'] == 'select'){
$select_value = get_user_meta( $id, $key)[0];
$select_title = $data['title'];
$select_meta_key = $data['metakey'];
$output .= "<div id='um_field__$key' class='um-field um-field-select um-field-$key um-field-select um-field-type_select' data-key='$key'> <div class='um-field-label'> <label for='$key'>$select_title</label> <div class='um-clear'></div> </div> <div class='um-field-area '> <select data-default='$value' name='$select_meta_key' id='$key' data-validate='' data-key='$key' class='um-form-field valid um-s1 ' style='width: 100%'>";
foreach($data['options'] as $option){
$output .= "<option value='$option' ($option == $select_value ? 'selected' : '')>$option</option>";
}
$output .= "</select> </div> </div>";
}else{
//if not a select box (the default way)
$output .= UM()->fields()->edit_field($key, $data);
}
}
$output .= '</div>';
$output .= ob_get_contents();
ob_end_clean();
echo $output;
echo $tame;
}
//update/save field date, works only for default fields not select boxes
function getUMFormData($user_id)
{
if (!current_user_can('edit_user', $user_id))
return false;
$meta_number = 0;
$custom_meta_fields = custom_feild_meta();
foreach ($custom_meta_fields as $meta_field_name) {
$meta_number++;
update_user_meta($user_id, $meta_field_name, $_POST[$meta_field_name]);
}
}
add_action('show_user_profile', 'showUMExtraFields');
add_action('edit_user_profile', 'showUMExtraFields');
add_action('edit_user_profile_update', 'getUMFormData');
add_action('personal_options_update', 'getUMFormData');
如果我做错了什么,请告诉我。提前致谢。