Menu Close Menu
Menu
  • 0
    • Number of items in cart: 0

      • Your cart is empty.
      • Total: $0.00
      • Checkout
  • Pricing
    • Purchase Options
    • Individual Extensions
  • Support
    • Documentation
    • Log a Support Ticket
  • Your Account
    • Register
  • Blog

Creating Custom User Fields

Creating Custom User Fields

Adding custom fields to the user profile screen for customers and agents

Using the user profile hooks WordPress already has, KB Support provides additional hooks that ensure all custom user fields created by any KB Support extension are grouped together under a user profile page header section called KB Support.

There are two hooks of interest here;

The kbs_user_profile_fields filter is used to determine which custom user profile fields are registered within KBS and it is important to do this so that KBS knows whether or not to print out the KB Support profile page header section. It also ensures the hook required to display the profile fields is run.

Simply, if there are no custom fields registered within KBS, the KB Support profile page header section will not be displayed, and the kbs_display_user_profile_fields hook which displays custom KBS user fields will not run either.

/**
 * @param	array	$fields	Array of registed KBS custom user profile fields
 * @return	array	Filtered array of registed KBS custom user profile fields
 */
function mh_custom_profile_fields( $fields )	{

	$mh_fields = array( 'company_name' );
	$fields    = array_merge( $mh_fields, $fields );

	return $fields;

}
add_filter( 'kbs_user_profile_fields', 'mh_custom_profile_fields' );

In the above example, we’re registering the field name company_name.

Next up, we need to hook into the kbs_display_user_profile_fields action to display our field.

/**
 * @param	object	$user	The WP_User object
 * @return	void	Any output must be echo'd as `add_action` does not return a value
 */
function mh_company_name_profile_field( $user )	{

	ob_start();
	?>
	<tr>
		<th><label for="company_name"><?php _e( 'Company Name', 'kb-support' ); ?></label></th>

		<td><input type="text" name="company_name" id="company_name" class="regular-text" value="<?php echo esc_attr( get_the_author_meta( 'company_name', $user->ID ) ); ?>">

			<p class="description"><?php _e( 'Enter your company name here.', 'kb-support' ); ?></p>

		</td>
	</tr>
	<?php
	echo ob_get_clean();

}
add_action( 'show_user_profile', 'mh_company_name_profile_field' );
add_action( 'edit_user_profile', 'mh_company_name_profile_field' );

The above code will result in the following output:

Company Name

Remember, you’ll still need to hook into personal_options_update and edit_user_profile_update to save the value of your field(s) when the user saves changes.


Was this article helpful?

We're working hard to ensure we provide you with useful and relevant documentation to help you get the most out of KB Support.

Please take a moment to let us know if you found this article helpful.

Developer Docs Hooks Agent Customer Last updated: 03/03/2017

Published by Cristian Raiber

Posts by Cristian Raiber

Post navigation

Previous

Configuring Custom Ticket Status

Next

Template Tags

Contact Details

  • Follow us on Twitter
  • Like us on Facebook
  • Fork us on GitHub

Developer Resources

Plugin Boilerplate

Trello Board

GitHub Repository

Ratings & Satisfaction Docs

  • Configuring Ratings and Satisfaction
  • Advanced Settings

Email Support Docs

  • Plugin Requirements
  • Configuring Email Support
  • Creating New Tickets
  • Replying to Closed Tickets
  • Anonymous Replies in Email Support
  • HTML Emails Tags
  • Email Commands
  • Defining IMAP Flags

KBS REST API Docs

  • Using the REST API
  • Tickets REST API Route
  • Replies REST API Route
  • Articles REST API Route
  • Agents REST API Route
  • Customers REST API Route
  • Companies REST API Route
  • Forms REST API Route
  • Form Fields REST API Route
  • Ticket Categories REST API Route
  • Ticket Departments REST API Route
  • Ticket Source REST API Route

Article Categories

  • Configuration
    • Advanced
    • Getting Started
  • Developer Docs
    • Constants
    • Hooks
  • Extensions
  • FAQs
© 2023 KB Support. All rights reserved.
  • Blog
  • Shop
  • Support
  • Privacy Policy
  • Discount Code