class Fieldmanager_Datasource_Term extends Fieldmanager_Datasource (View source)

Datasource to populate autocomplete and option fields with WordPress terms.

Properties

array $options

The datasource options.

from  Fieldmanager_Datasource
string $options_callback

Options callback.

from  Fieldmanager_Datasource
bool $use_ajax

Build this datasource using Ajax.

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
string|array $taxonomy

Taxonomy name or array of taxonomy names.

array $taxonomy_args

Helper for taxonomy-based option sets; arguments to find terms.

bool $taxonomy_hierarchical

Sort taxonomy hierarchically and indent child categories with dashes?

int $taxonomy_hierarchical_depth

How far to descend into taxonomy hierarchy (0 for no limit).

bool $append_taxonomy

Pass $append = true to wp_set_object_terms?

string $taxonomy_save_to_terms

If true, additionally save taxonomy terms to WP's terms tables.

string $only_save_to_taxonomy

If true, only save this field to the taxonomy tables, and do not serialize in the FM array.

bool $store_term_taxonomy_id

If true, store the term_taxonomy_id instead of the term_id.

Methods

__construct(array $options = array())

Constructor.

string
get_value(mixed $value)

Translate term id to title, e.g. for autocomplete.

array
get_items(string $fragment = null)

Get taxonomy data per $this->taxonomy_args.

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)

Presave hook to set taxonomy data.

array
preload_alter_values(Fieldmanager_Field $field, mixed $values)

Unique among FM types, the taxonomy datasource can store data outside FM's array.

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

Sanitize a value.

string
get_view_link(mixed $value)

Get link to view a term.

string
get_edit_link(int|string $value)

Get link to edit a term.

array
get_taxonomies()

Get taxonomies; normalizes $this->taxonomy to an array.

bool
sort_terms(WP_Term $term_a, WP_Term $term_b) deprecated

Sort function for get_the_terms result set.

pre_save_taxonomy(mixed $tax_values, Fieldmanager_Field $field)

Save taxonomy data.

array
build_hierarchical_term_data(array $parent_terms, array $tax_args, int $depth, array $stack = array(), string $pattern = '')

Helper to support recursive building of a hierarchical taxonomy list.

Details

__construct(array $options = array())

Constructor.

Parameters

array $options

The datasource options.

string get_value(mixed $value)

Translate term id to title, e.g. for autocomplete.

Parameters

mixed $value

The term ID.

Return Value

string

The value.

array get_items(string $fragment = null)

Get taxonomy data per $this->taxonomy_args.

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)

Presave hook to set taxonomy data.

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)

Unique among FM types, the taxonomy datasource can store data outside FM's array.

This is how we add it back into the array for editing.

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)

Sanitize a value.

Parameters

Fieldmanager_Field $field

Base field.

mixed $value

New value.

mixed $current_value

Current value.

Return Value

string

$values Cleaned value.

Get link to view a term.

Parameters

mixed $value

The current value.

Return Value

string

HTML string.

Get link to edit a term.

Parameters

int|string $value

The current value.

Return Value

string

HTML string.

array get_taxonomies()

Get taxonomies; normalizes $this->taxonomy to an array.

Return Value

array Taxonomies.

bool sort_terms(WP_Term $term_a, WP_Term $term_b) deprecated

deprecated 1.2.2 Handled with get_terms() in Fieldmanager_Datasource_Term::preload_alter_values().

Sort function for get_the_terms result set.

Parameters

WP_Term $term_a

First term.

WP_Term $term_b

Second term.

Return Value

bool

Whether or not it is in order.

pre_save_taxonomy(mixed $tax_values, Fieldmanager_Field $field)

Save taxonomy data.

Parameters

mixed $tax_values

The taxonomies.

Fieldmanager_Field $field

The base field.

protected array build_hierarchical_term_data(array $parent_terms, array $tax_args, int $depth, array $stack = array(), string $pattern = '')

Helper to support recursive building of a hierarchical taxonomy list.

Parameters

array $parent_terms

The parent terms.

array $tax_args

As used in top-level get_terms() call.

int $depth

Current recursive depth level.

array $stack

Current stack.

string $pattern

Optional matching pattern.

Return Value

array

$stack Stack of terms or false if no children found.