-
Notifications
You must be signed in to change notification settings - Fork 8
User
The User location allows you to associate containers with WordPress users.
To add fields to users with the the Administration Interface, please follow these steps:
- If you are not on the "Add Container" screen already, locate the "Ultimate Fields" section in the administration area and click the "Add New" button on the top (next to the "Containers" title).
- Locate the "Locations" box.
- Click "User" from the bottom row.
- Adjust all other needed options. All of them are described further down this page.
The user location in Ultimate Fields is handled by the Ultimate_Fields\Location\User
class. In order to use it, you can either create the new location object manually or let the container do it for you.
The constructor of the class looks like this:
public function __construct( $args = array() ) {
$args
is an array, which allows you to set arguments without having to explicitly call the particular setter. For example, you can pass 'roles' => 'editor'
instead of calling ->set_roles( 'editor' )
Create a new location by using the new
keyword and assign it to the container through the add_location()
method.
use Ultimate_Fields\Container;
use Ultimate_Fields\Location\User;
$container = Container::create( 'addresses' );
// Create a new location and add definitions to it
$location = new User();
$location->set_roles( 'editor' );
// Once the location has been fully set up, add it to the container
$container->add_location( $location );
Do not forget to use the correct namespace for the location class!
You can also let the container create the location for you by providing the "user" string as the first parameter to add_location()
.
use Ultimate_Fields\Container;
Container::create( 'adresses' )
->add_location( 'user', array(
'roles' => 'editor'
));
This method allows you to use method chaining and shortens the syntax, in order to make the code more readable.
To retrieve the values of fields, associated with the User location, $type
parameter of all *_value
functions should have the "user_XX"
format with XX
representing the ID of the user.
Examples:
$country = get_value( 'country', 'user_3' );
There are a few options for the User location and all of them are listed below.
You can conditionally show fields in user profiles based on the role of the user, which is being edited.
uncheck "Show on all user roles" and you will see checkboxes, which allow you to toggle the roles that you need.
use the roles as the roles
argument in the $args
array or pass them to the set_roles
method.
You can add multiple values and/or exclude values by appending a minus sign in front of them.
use Ultimate_Fields\Location\User;
// Show only for the editor
$container->add_location( 'user', array(
'roles' => 'editor'
));
// Do not show on editors and authors
$location = new User();
$location->set_roles(array( '-editor', '-author' ));
$container->add_location( $location );
If registration is enabled in your site's settings, you can add additional fields to the registration form.
you will see a checkbox, which enables showing fields there.
you can use the registration_form
argument or the set_registration_form
method:
use Ultimate_Fields\Location\User;
$container->add_location( 'user', array(
'registration_form' => true;
));
// or
$location = new User();
$location->set_registration_form();
$container->add_location( $location );
Ultimate FIelds can display containers as sections in the Customizer for various locations and the User location is one of them.
Please read the Adding fields to the Customizer article in order to learn how to display user fields in the cutomizer and to use their values afterwards.
you need to go the "REST API" tab and select which fields you want to include. You can also select if those fields are editable or not.
Please read the REST API section section of the Container Settings article, as the REST functionality is directly controlled in containers.
The User location supports Administration Columns. Click the link to learn how to use them.
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials