2013-11-01 22 views
0

OK,所以我用這一個小時的苦苦掙扎,並不能得到它的工作,但感覺像有一個向前的海峽簡單而優雅的解決方案。所有我想要做的就是當一個成員正在編輯的信息來驗證定製xprofile電子郵件字段的值。試圖模仿xprofile_screen_edit_profile()如何與保存前返回錯誤,我試圖ADD_ACTION /的add_filter/do_action/apply_filter到xprofile_updated_profile,xprofile_screen_edit_profile,bp_actions,bp_screens,xprofile_data_value_before_save多,但我每次都失敗可能是因爲我不知道如何正確使用它們。所有我想要做的是簡單的:驗證定製xprofile編輯個人資料頁上的場BuddyPress的

function my_validate_email() { 
    if (!empty($field_id->value) && !is_email($field_id->value)) 
bp_core_add_message(__('That email address is invalid. Check the formatting and try again.', 'buddypress'), 'error'); 
//and redirect back to editing, same like for the required fields 
} 
add_action('bp_hook_here', 'my_validate_email'); 

請這樣做的正確的方式幫助,可能無需使用額外的插件 非常感謝

回答

0

這是一個額外的電子郵件字段? 而不是用戶的電子郵件註冊相關? 如果它不是一個額外的電子郵件字段,然後使用WP掛鉤。 如果是這樣,看看BP-xprofile類,功能保存(),〜行1032

而且這樣做(未經測試):

function my_validate_email ($this) { 
    // figure out if $this is an array or object and adjust accordingly... 

if ($this['field_id'] == $the_id_of_your_email_field) { 
    if (!empty($this['value']) && !is_email($this['value'])) { 
     $this['field_id'] = 0; 
     bp_core_add_message(__('That email address is invalid. Check the formatting and try again.', 'buddypress'), 'error'); 
    } 
    } 

    return $this; 

} 
add_action('xprofile_data_before_save', 'my_validate_email', 1, 1); 
+1

是的,這是一個額外的自定義電子郵件字段這與用戶的註冊無關。我試過你的函數,但var_dump($ this)不會用這個鉤子返回任何東西。 – pankipan4e

相關問題