Fieldmanager_Context_Term
class Fieldmanager_Context_Term extends Fieldmanager_Context_Storable (View source)
Use fieldmanager to create meta boxes on the new/edit term screens and save data primarily to term meta.
Properties
Fieldmanager_Field | $fm | Base field |
|
string | $uniqid | Unique ID of the form. Used for forms that are not built into WordPress. |
from Fieldmanager_Context |
array | $save_keys | Store the meta keys this field saves to, to catch naming conflicts. |
from Fieldmanager_Context |
array | $taxonomies_to_save | Taxonomies to save to. |
from Fieldmanager_Context_Storable |
string | $title | Title of field to display in standard term form field location. |
|
array | $taxonomies | What taxonomies to render these fields. |
|
bool | $show_on_add | Whether or not to show the fields on the term add form. |
|
bool | $show_on_edit | Whether or not to show the fields on the term edit form. |
|
int | $parent | Only show this field on child terms of this parent. |
|
array | $reserved_fields | Field names reserved for WordPress on the term add/edit forms. |
|
bool | $use_fm_meta | Use FM term meta or WordPress core term meta. The default is a bit confusing: technically, it's to use core's term meta, but if the class is instantiated using the now-deprecated separated arguments, this gets set to true for backwards-compatibility purposes. |
|
protected array|null | $inserting_term_data | Store data for inserted terms to ensure, as much as possible, that FM only stores data to the term being created and not any other term created as a side effect. |
Methods
Instantiate this context. You can either pass an array of all args (preferred), or pass them individually (deprecated).
Include a fresh nonce for this field in a response with refreshed nonces.
Check if the nonce is valid. Returns false if the nonce is missing and throws an exception if it's invalid. If all goes well, returns true.
Prepare the data for saving.
Walk group children to save when serialize_data => false.
Walk group children to load when serialize_data => false.
Meta and options are always stored as strings, so it's best to ensure
that scalar values get cast as strings to ensure that update_metadata()
and update_option()
are able to correctly compare the current value
against the previous value.
Callback to get term meta for the given term ID and current taxonomy.
Callback to add term meta for the given term ID and current taxonomy.
Callback to update term meta for the given term ID and current taxonomy.
Callback to delete term meta for the given term ID and current taxonomy.
Creates the HTML template for wrapping fields on the add term form and prints the field.
Creates the HTML template for wrapping fields on the edit term form and prints the field.
Generates HTML for the term field.
Saves custom term fields.
Verify that the term being inserted is the term that Fieldmanager data should be added to.
Helper to save an array of data to term meta.
Saves custom fields for the sport taxonomy.
Details
__construct(array|string $args, string|array $taxonomies = array(), bool $show_on_add = true, bool $show_on_edit = true, string $parent = '', Fieldmanager_Field $fm = null)
Instantiate this context. You can either pass an array of all args (preferred), or pass them individually (deprecated).
protected string
nonce_key()
Get the nonce key for this field.
array
refresh_nonce(array $response)
Include a fresh nonce for this field in a response with refreshed nonces.
protected bool
is_valid_nonce()
Check if the nonce is valid. Returns false if the nonce is missing and throws an exception if it's invalid. If all goes well, returns true.
protected mixed
prepare_data(mixed $old_value = null, mixed $new_value = null, object $fm = null)
Prepare the data for saving.
protected string
render_field(array $args = array())
Render the field.
protected
save(mixed $data = null)
Handle saving data for any context.
protected
save_field(object $field, mixed $data)
Save a single field.
protected
save_walk_children(object $field, mixed $data)
Walk group children to save when serialize_data => false.
protected mixed
load()
Handle loading data for any context.
protected mixed
load_field(object $field)
Load a single field.
protected mixed
load_walk_children(object $field)
Walk group children to load when serialize_data => false.
static string|array
sanitize_scalar_value(mixed $value)
Meta and options are always stored as strings, so it's best to ensure
that scalar values get cast as strings to ensure that update_metadata()
and update_option()
are able to correctly compare the current value
against the previous value.
protected string|array
get_data(int $term_id, string $meta_key, bool $single = false)
Callback to get term meta for the given term ID and current taxonomy.
protected bool|int
add_data(int $term_id, string $meta_key, string $meta_value, bool $unique = false)
Callback to add term meta for the given term ID and current taxonomy.
protected mixed
update_data(int $term_id, string $meta_key, string $meta_value, bool $meta_prev_value = '')
Callback to update term meta for the given term ID and current taxonomy.
protected bool
delete_data(int $term_id, string $meta_key, string $meta_value = '')
Callback to delete term meta for the given term ID and current taxonomy.
add_term_fields(string $taxonomy)
Creates the HTML template for wrapping fields on the add term form and prints the field.
edit_term_fields(WP_Term $term, string $taxonomy)
Creates the HTML template for wrapping fields on the edit term form and prints the field.
string
term_fields(string $html_template, string $taxonomy, WP_Term $term = null)
Generates HTML for the term field.
save_term_fields(int $term_id, int $tt_id, string $taxonomy)
Saves custom term fields.
array
verify_term_data_on_insert(array $data, string $taxonomy, array $args)
Verify that the term being inserted is the term that Fieldmanager data should be added to.
This method serves to protect against a plugin or theme creating one or
more additional terms as a side effect of a term created from the form.
In order to protect against that, it's necessary to check the inserting
term's [name, taxonomy, parent], as WordPress requires the combination of
these fields to be unique. In order to guard against a plugin or theme
changing this data, it is recorded immediately prior to the term being
insert, and then checked in save_term_fields()
.
save_to_term_meta(int $term_id, string $taxonomy, array $data = null)
Helper to save an array of data to term meta.
delete_term_fields(int $term_id, int $tt_id, string $taxonomy, WP_term $deleted_term)
deprecated
deprecated
Saves custom fields for the sport taxonomy.