Fieldmanager_Context_Submenu
class Fieldmanager_Context_Submenu extends Fieldmanager_Context_Storable (View source)
Use fieldmanager to create arbitrary pages in the WordPress admin and save data primarily to options.
Properties
Fieldmanager_Field | $fm | The base field associated with this context. |
from Fieldmanager_Context |
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 | $parent_slug | Parent of this submenu page. |
|
string | $page_title | Title of the page. |
|
string | $menu_title | Menu title. |
|
string | $capability | Capability required. |
|
string | $menu_slug | Menu slug. |
|
string | $submit_button_label | Only used for options pages. |
|
string | $updated_message | The "success" message displayed after options are saved. Defaults to "Options updated". |
|
string | $wp_option_autoload | For submenu pages, set autoload to true or false. |
Methods
Create a submenu page out of a field.
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 option.
Add option.
Update option.
Delete option.
Register a submenu page with WordPress.
Helper to attach element_markup() to add_meta_box(). Prints markup for options page.
Save a submenu page
Save the submenu data.
Get the URL for this context's admin page. Mainly pulled from menu_page_url().
Details
__construct(string $parent_slug, string $page_title, string $menu_title = null, string $capability = 'manage_options', string $menu_slug = null, Fieldmanager_Field $fm = null, bool $already_registered = false)
Create a submenu page out of a field.
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 $data_id, string $option_name, bool $single = false)
Get option.
protected bool|int
add_data(int $data_id, string $option_name, string $option_value, bool $unique = false)
Add option.
protected mixed
update_data(int $data_id, string $option_name, string $option_value, string $option_prev_value = '')
Update option.
protected bool
delete_data(int $data_id, string $option_name, string $option_value = '')
Delete option.
register_submenu_page()
Register a submenu page with WordPress.
render_submenu_page()
Helper to attach element_markup() to add_meta_box(). Prints markup for options page.
handle_submenu_save()
Save a submenu page
bool
save_submenu_data(array $data = null)
Save the submenu data.
string
url()
Get the URL for this context's admin page. Mainly pulled from menu_page_url().