Fieldmanager_Context_QuickEdit
class Fieldmanager_Context_QuickEdit extends Fieldmanager_Context_Storable (View source)
Use fieldmanager to add fields to the "quick edit" (post list inline editing) and save data primarily to post 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 QuickEdit box; also used for the column title unless $column_title is specified. |
|
string | $column_title | Override $title for the column in the list of posts. |
|
callable | $column_display_callback | QuickEdit fields are tied to custom columns in the list of posts. This callback should return a value to display in a custom column. |
|
string | $post_types | What post types to render this Quickedit form. |
Methods
Add a context to a fieldmanager.
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.
Get post meta.
Add post meta.
Update post meta.
Delete post meta.
Callback for manage_{$post_type}_posts_columns, as QuickEdit boxes only work on custom columns.
The manage_posts_custom_column callback.
The quick_edit_custom_box callback. Renders the QuickEdit box.
Callback for wp_ajax_fm_quickedit_render.
Takes $_POST data and saves it to, calling save_to_post_meta() once validation is passed When using Fieldmanager as an API, do not call this function directly, call save_to_post_meta().
Helper to save an array of data to post meta.
Details
__construct(string $title, mixed $post_types, callable $column_display_callback, callable $column_title = '', Fieldmanager_Field $fm = null)
Add a context to a fieldmanager.
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 $post_id, string $meta_key, bool $single = false)
Get post meta.
protected bool|int
add_data(int $post_id, string $meta_key, mixed $meta_value, bool $unique = false)
Add post meta.
protected mixed
update_data(int $post_id, string $meta_key, mixed $meta_value, mixed $data_prev_value = '')
Update post meta.
protected bool
delete_data(int $post_id, string $meta_key, mixed $meta_value = '')
Delete post meta.
array
add_custom_columns(array $columns)
Callback for manage_{$post_type}_posts_columns, as QuickEdit boxes only work on custom columns.
manage_custom_columns(string $column_name, int $post_id)
The manage_posts_custom_column callback.
add_quickedit_box(string $column_name, string $post_type, array $values = array())
The quick_edit_custom_box callback. Renders the QuickEdit box.
Renders with blank values here since QuickEdit boxes cannot access to the WP post_id. The values will be populated by an ajax-fetched form later (see $this->render_ajax_form() ).
render_ajax_form()
Callback for wp_ajax_fm_quickedit_render.
Renders a form with pre-filled values to replace the one generated by $this->add_quickedit_box().
save_fields_for_quickedit(int $post_id)
Takes $_POST data and saves it to, calling save_to_post_meta() once validation is passed When using Fieldmanager as an API, do not call this function directly, call save_to_post_meta().
save_to_post_meta(int $post_id, array $data = null)
Helper to save an array of data to post meta.