I think ‘bp_init’ is the wrong hook.. Try using ‘bp_core_signup_user’
function save_wc_address() {
if ( wp_verify_nonce( $_POST['bp_settings_general'] ) ){
$user_id = sanitize_text_field( $_POST['user_id'] );
//sanitize input data
$billing_phone = sanitize_text_field( $_POST['billing_phone'] );
//update user meta
update_user_meta( $user_id, 'billing_phone', $billing_phone);
}
}
add_action( 'bp_core_signup_user', 'save_wc_address');
source:
http://wordpress.stackexchange.com/questions/160475/how-to-increase-password-requirements-for-registration
or simply the ‘user_register’ action hook should work? let me know if that works for you
modifying the general.php template
There is no such template in a standard BP install, afaik.
But there is an easier way to add a field…
Why not add a profile field in the proscribed manner?
In wp-admin, go to Users > Profile Fields and add your field to whichever Group you want.
All fields in the Base Group will appear on the Registration page.
Hi shanebpb, what ure referring to is the edit profile tab under the Profile nav menu. What i’m trying to do is add custom field to the General tab under the Settings nav menu. The template I’m talking about is at /buddypress/members/single/settings/ folder of the template folder. Sorry if i wasn’t being clear enough before this.
That said, having the field displayed is not the issue I’m having, saving th custom field is my issue here. The nonce i was talking about is there in the general.php file and it’s within the <form></form> section, so i figure it can be used somehow to save the field.
I’ll try what coffeywebdev suggested by using different action hook instead of the ‘init’ hook I’m using now.
So, after more reading, I’ve managed to solved this (90% solved I would say) by changing the line if ( wp_verify_nonce( $_POST['bp_settings_general'] ) )
that i wrote in the first post to if ( isset($_POST['submit']) && check_admin_referer('bp_settings_general') )
. And now my field is saved!
I would like to say sorry for not studying enough about using wp_verify_nonce() in processing form.
However, there still a bit of an issue left. I still got ‘No changes were made to your account.’ notification warning in a red box under the cover banner image even though my input is saved. Would anybody point me to what function or hook to use to tell the notification that something has been saved? Thanks!
You were clear enough about it being settings – I misread your posts.
You should use this hook: do_action( 'bp_core_general_settings_after_save' );
Found in: buddypress\bp-settings\bp-settings-actions.php
Changing the feedback message is more difficult.
You could change the content of the message by using this hook:
apply_filters( 'bp_core_render_message_content', $bp->template_message, $type );
Found in: buddypress\bp-core\bp-core-functions.php
But I don’t see how you can change the type of message from error to success.
So what I would do is – create a new tab on the Settings panel and handle everything separate from the General tab functionality.
There is lots of documentation about that task, this will get you started…
function had_setup_biz_phone_navigation() {
bp_core_new_subnav_item( array(
'name' => 'Billing Phone',
'slug' => 'bphone',
'parent_url' => bp_loggedin_user_domain() . 'settings/',
'parent_slug' => 'settings',
'screen_function' => 'name of the function to create the content',
'show_for_displayed_user' => false
) );
}
add_action( 'bp_setup_nav', 'had_setup_biz_phone_navigation' );
Ah, I guess i should open up a new tab then to solve the notification issue. Thanks for the help anyway.
After diving more into the filters mentioned by shanebp, I managed to manipulate the notification message. For those interested, I just add bp_core_add_message( $message, $type );
function into the form process function with $message as the message when updated and $type as ‘success’ to give it a green color success notification.
However, I’m most probably gonna move those fields to their own tab anyway.