Fieldmanager_Context_Post
class Fieldmanager_Context_Post extends Fieldmanager_Context_Storable (View source)
Use fieldmanager to create meta boxes on the new/edit post screen and save data primarily to post meta.
Properties
Fieldmanager_Group | $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 meta box. |
|
array | $post_types | What post types to render this meta box. |
|
string | $context | Context (normal, advanced, or side). |
|
priority | $priority | Priority (high, core, default, or low). |
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.
Registers render_meta_box() via admin_init callback to add meta boxes to content types.
Helper to attach element_markup() to add_meta_box(). Prints markup for post editor.
Helper to remove all built-in meta boxes for all specified taxonomies on a post type.
Handles saving Fieldmanager data when the custom meta boxes are used on an attachment.
Action handler to delegate to appropriate methods when a post is saved.
Takes $_POST data and saves it to, calling save_to_post_meta() once validation is passed.
Process fields during a cron request, without saving data since the data isn't changing.
Helper to save an array of data to post meta.
Helper for fieldmanager internals to save a post without worrying about infinite loops.
Details
__construct(string $title, mixed $post_types, string $context = 'normal', string $priority = 'default', 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.
meta_box_render_callback()
Registers render_meta_box() via admin_init callback to add meta boxes to content types.
render_meta_box(WP_Post $post, null $form_struct = null)
Helper to attach element_markup() to add_meta_box(). Prints markup for post editor.
remove_meta_boxes()
Helper to remove all built-in meta boxes for all specified taxonomies on a post type.
array
save_fields_for_attachment(array $post, array $attachment)
Handles saving Fieldmanager data when the custom meta boxes are used on an attachment.
Calls save_fields_for_post with the post ID.
delegate_save_post(int $post_id)
Action handler to delegate to appropriate methods when a post is saved.
save_fields_for_post(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_fields_for_cron(int $post_id)
Process fields during a cron request, without saving data since the data isn't changing.
save_to_post_meta(int $post_id, array $data = null)
Helper to save an array of data to post meta.
static mixed
safe_update_post(array $args)
Helper for fieldmanager internals to save a post without worrying about infinite loops.