![](/img/trans.png)
[英]Wordpress Ultimate Member Plugin – Set User Status to Awaiting Admin Approval
[英]how can I display ultimate member plugin's input meta fields on WordPress admin panel edit account page for editing by the admin?
我正在為 WordPress 使用插件“終極會員”,它工作正常......我想要一些額外的功能,管理員可以從管理面板更改某些數據(如性別,職業,國家等)(編輯用戶頁面)。 在一些博客文章的幫助下,我整理了一些代碼,這些代碼能夠在編輯帳戶頁面上顯示相關/目標用戶的編輯字段。
問題是某些字段(如性別和國家/地區)未顯示其當前值,並且單擊“用戶按鈕”時沒有任何字段更新。
這是我在./wp-content/themes/twentytwentyone/functions.php 上使用的代碼:
add_action('edit_user_profile', 'showUMExtraFields', 100);
function showUMExtraFields()
{
ob_start();
$id = um_user('ID');
$output = '<div class="um-field">';
$names = array("user_login", 'birth_date', "gender", "country", "user_url", "cool_input"); // the meta names of the feilds I want to display
$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) {
$output .= UM()->fields()->edit_field($key, $data);
}
$output .= '</div>';
$output .= ob_get_contents();
ob_end_clean();
echo $output;
}
add_action('edit_user_profile_update', 'getUMFormData');
function getUMFormData()
{
$id = um_user('ID');
$names = array("user_login", 'birth_date', "gender", "country", "user_url", "cool_input"); // the meta names of the feilds I want to display
foreach ($names as $name) {
if (!empty($secure_fields)) {
update_user_meta($id, $name, $_POST[$name]);
}
}
}
有人可以幫我弄清楚我做錯了什么嗎?
無法在其他表單/頁面中顯示來自 Ultimate Member 的 select 箱子。 我想出了一個解決方案......但它仍然不夠好,它沒有更新 select 盒子......
//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');
如果我做錯了什么,請告訴我。 提前致謝。
我不確定這是否正確。 我擴展了你的代碼以用於復選框,看起來沒問題
//display fields
function showUMExtraFields()
{
ob_start();
//Only reading $disable = "disabled", else leave just ""
$disable = "disabled";
$id = um_user('ID');
// $id = UM()->user()->target_id;
$output = '<table class="form-table">';
$output = $output.'<tr><th><label>Extra profile information</label></th>';
$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 .=
"<td>
<span class='um-field um-field-select um-field-$key um-field-select um-field-type_select' data-key='$key'>$select_title:</span>
<div class='um-field-label'>
<label for='$key'></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>
</td>";
//if it is a checkbox
}elseif($data['type'] == 'checkbox') {
$check_value = get_user_meta( $id, $key)[0];
$check_title = $data['title'];
$check_meta_key = $data['metakey'];
$output .=
"
<td>
<span class='usergroup-category-name'>$check_title</span><br/>";
foreach($data['options'] as $option){
$output .="<input name='$key"."[]' id='$key"."-$option' type='checkbox' value='$option'";
if (in_array($option, $check_value)){
$output .='checked="checked"';}
$output .= $disable."/> <label>$option </label><br/>";
}
$output .= "</td>";
}else{
//if not a select box (the default way)
$output .= UM()->fields()->edit_field($key, $data);
}
}
$output .= '<tr></table>';
$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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.