In this article, we will learn how to add custom fields on the buddy boss edit profile page.
Step 1 – Use ‘bp_after_profile_field_content’ action for add custom fields.
add_action( 'bp_after_profile_field_content','action_bp_custom_profile_edit_fields'); function action_bp_custom_profile_edit_fields() { global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); $word = "profile/edit/group"; // Test if string contains the word if(strpos($current_url, $word) !== false){ ?> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Company name</legend> <input type="text" name="_company_name" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_name',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Company Information</legend> <input type="text" name="_company_information" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_information',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Company Size</legend> <input type="text" name="_company_size" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_size',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Field of Operations</legend> <input type="text" name="_field_of_operations" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_field_of_operations',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Website</legend> <input type="text" name="_company_website" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_website',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Tagline</legend> <input type="text" name="_company_tagline" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_tagline',true); ?>" /> </fieldset> </div> <div class="editfield field_preferred-name field_order_0 required-field visibility-public field_type_textbox"> <fieldset> <legend id="">Twitter username</legend> <input type="text" name="_company_twitter" id="signup_profile_field_ids" value="<?php echo get_user_meta(get_current_user_id(),'_company_twitter',true); ?>" /> </fieldset> </div> <?php } }
Step 2 – Use the ‘xprofile_data_before_save’ action to add your custom fields values.
add_action( 'xprofile_data_before_save','action_xprofile_data_before_save', 10, 1 ); function action_xprofile_data_before_save( $array ) { if (isset($_POST['_company_name'])) { update_user_meta(get_current_user_id(),'_company_name',$_POST['_company_name']); } if (isset($_POST['_company_information'])) { update_user_meta(get_current_user_id(),'_company_information',$_POST['_company_information']); } if (isset($_POST['_field_of_operations'])) { update_user_meta(get_current_user_id(),'_field_of_operations',$_POST['_field_of_operations']); } if (isset($_POST['_company_size'])) { update_user_meta(get_current_user_id(),'_company_size',$_POST['_company_size']); } if (isset($_POST['_company_website'])) { update_user_meta(get_current_user_id(),'_company_website',$_POST['_company_website']); } if (isset($_POST['_company_tagline'])) { update_user_meta(get_current_user_id(),'_company_tagline',$_POST['_company_tagline']); } if (isset($_POST['_company_twitter'])) { update_user_meta(get_current_user_id(),'_company_twitter',$_POST['_company_twitter']); } }
Here is the result.