2016-04-05 66 views
0

我有安裝BuddyPress的有3個小組。當用戶在前臺編輯自己的個人資料,我想,如果當他們點擊保存,它會自動前進到下一個字段組。BuddyPress的編輯個人資料順序

因此,舉例來說,我編輯我的場1組配置文件,點擊保存,就帶我到現場組2,所以我可以編輯,而無需點擊導航標籤領域。

因爲這是與方法的形式=「POST」我假定這將是作爲檢查後值一樣簡單。問題是當我編輯配置文件,並保存沒有發佈數據。即時通訊使用這只是用於故障排除(注意,這些空車返回我節省後):

//Next step progression 
//Check the field group 
echo bp_get_current_profile_group_id(); 
if(bp_get_current_profile_group_id() == 1) { 
    echo '<pre>'; 
    print_r($_GET); 
    echo '</pre>'; 
    echo '<pre>'; 
    print_r($_POST); 
    echo '</pre>'; 
    if(isset($_POST['_wpnonce'])){ ?> 
     <script> 
     jQuery(document).ready(function($){ 
      alert('Saved'); 
     }); 
     </script> 
    <?php } 
} elseif(bp_get_current_profile_group_id() == 2) { 

} 

挖得更深一些,我看到表單動作是在此之後:<?php bp_the_profile_group_edit_form_action(); ?>它調用函數<?php bp_get_the_profile_group_edit_form_action(); ?>

我看到我可以添加從how this function is documented過濾器/行動,但我似乎無法得到它的工作。

回答

1

嘗試使用這個鉤子:

do_action('xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values); 

發現在buddypress\bp-xprofile\bp-xprofile-screens.php

你需要編寫自己的反饋消息,並檢查$posted_field_ids弄清楚用戶是哪個組編輯。

+0

這無疑讓我給我的答案。非常感謝! – Derek

0

感謝shanebp我能夠找到合適的掛鉤,並得到這樣一個有效的解決方案:

在BuddyPress的/件/單/資料/ edit.php我加入這個表單標籤內:

<input type="hidden" name="group_id" id="groupd_id" value="<?php echo bp_get_current_profile_group_id(); ?>" /> 

然後在我的功能,我沒有這個心不是哪個最有活力的,但讓我在那裏,我需要的情況下,其他人去發現這樣的:

function update_xprofile_group_progressions($user_id) { 
    if (!empty($user_id)) { 
     if(isset($_POST['group_id']) && $_POST['group_id'] == 1){ 
      $url = home_url() . '/all-members/' . bp_core_get_username($user_id) . '/profile/edit/group/2/'; 
      wp_redirect($url); 
      exit; 

     } elseif(isset($_POST['group_id']) && $_POST['group_id'] == 2){ 
      $url = home_url() . '/all-members/' . bp_core_get_username($user_id) . '/profile/edit/group/4/'; 
      wp_redirect($url); 
      exit; 

     } 
    } 
} 
add_action('xprofile_updated_profile', 'update_xprofile_group_progressions', 0, 1); 
+0

你一定要重定向之前檢查錯誤。你可以使用bp_core_redirect()而不是wp_redirect--有一些優點。 – shanebp

相關問題