class Fieldmanager_Datasource_User extends Fieldmanager_Datasource (View source)

Datasource to populate autocomplete and option fields with WordPress Users.

Properties

array $options

The datasource options.

from  Fieldmanager_Datasource
string $options_callback

Options callback.

from  Fieldmanager_Datasource
bool $use_ajax

Allow Ajax. If set to false, Autocomplete will pre-load get_items() with no fragment, so False could cause performance problems.

bool $allow_optgroups

Allow option groups.

from  Fieldmanager_Datasource
string $ajax_action

The Ajax action.

from  Fieldmanager_Datasource
static int $counter

Counter to create uniquely named Ajax actions.

from  Fieldmanager_Datasource
bool $grouped

If true, group elements.

from  Fieldmanager_Datasource
callable $query_callback

Supply a function which returns a list of users; takes one argument, a possible fragment.

array $query_args

Arguments to get_users(), which uses WP's defaults.

string $display_property

Display property. Defaults to display_name, but can also be 'user_login', 'user_email', or 'user_nicename'.

protected array $allowed_display_properties

Allowed display properties for validation.

string $store_property

Store property. Defaults to ID, but can also be 'user_login', 'user_email', or 'user_nicename'.

protected array $allowed_store_properties

Allowed store properties for validation.

string $capability

Capability required to refer to a user via this datasource.

string $reciprocal

If not empty, set this object's ID as a value on the user. This is used to establish two-way relationships.

Methods

__construct(array $options = array())

Constructor. Used for validation.

string
get_value(int $value)

Get a user by the specified field.

array
get_items(string $fragment = null)

Get users which match this datasource, optionally filtered by a search fragment, e.g. for Autocomplete.

string
get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

autocomplete_search()

Ajax callback to find posts.

string
presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

Delete reciprocal user metadata prior to saving (presave will re-add).

array
preload_alter_values(Fieldmanager_Field $field, mixed $values)

Modify values before rendering editor.

string
presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Handle reciprocal usermeta.

string
get_view_link(mixed $value)

Get view link for a user.

string
get_edit_link(int|string $value)

Get edit link for a user.

mixed
sanitize_value(mixed $value)

Sanitize the value based on store_property.

Details

__construct(array $options = array())

Constructor. Used for validation.

Parameters

array $options

The datasource options.

Exceptions

FM_Developer_Exception

string get_value(int $value)

Get a user by the specified field.

Parameters

int $value

Post ID.

Return Value

string

The value.

array get_items(string $fragment = null)

Get users which match this datasource, optionally filtered by a search fragment, e.g. for Autocomplete.

Parameters

string $fragment

Optional fragment to filter by.

Return Value

array

The key => value of available options.

string get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

Return Value

string

Ajax action.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

Parameters

string|null $fragment

Search string.

Ajax callback to find posts.

string presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

Delete reciprocal user metadata prior to saving (presave will re-add).

Reciprocal relationships are not possible if we are not storing by ID.

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New value.

mixed $current_values

Current value.

Return Value

string

$values Cleaned value.

array preload_alter_values(Fieldmanager_Field $field, mixed $values)

Modify values before rendering editor.

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New values.

Return Value

array

$values Loaded up, if applicable.

string presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Handle reciprocal usermeta.

Reciprocal relationships are not possible if we are not storing by ID.

Parameters

Fieldmanager_Field $field

Base field.

mixed $value

New value.

mixed $current_value

Current value.

Return Value

string

$values Cleaned value.

Get view link for a user.

Parameters

mixed $value

The current value.

Return Value

string

HTML string.

Get edit link for a user.

Parameters

int|string $value

The current value.

Return Value

string

HTML string.

protected mixed sanitize_value(mixed $value)

Sanitize the value based on store_property.

Parameters

mixed $value

The current value.

Return Value

mixed

$value The sanitized value.