abstract class Meta_Box extends Singleton

A manager for Meta Boxes that appear on admin edit pages. Manages the form rendering and post save hooking processes.

Properties

static protected Singleton[] $_instances from  Singleton
string $context
string $priority
string|array $screen
string $permissions

Methods

__construct()

Construct the Meta_Box. Set the default properties if they are not set.

static Singleton
instance(mixed $args = null)

Maybe initialize singleton instance and return the instance.

static array
get_instances()

Return a copy of the instances array.

get_class_reflection()

A short one-liner tool to get a ReflectionClass so we can get runtime info for the static class instance and not this abstract.

static 
render()

The function that will output the Meta Box HTML. Hooked by { $this->add_meta_box() } through { self::_render() }.

static 
save_post(int $post_id, WP_Post|null $Post = null)

The code to be run after the _save_post hook checks.

static string
meta_key()

A meta key to use when saving the Post Meta to the database. Should be lowercase and underscored.

static string
get_id()

Return the ID of the Meta Box (used in the "id" attribute, says WordPress docs, i.e. the "id" attribute in the HTML DOM for Javascript events).

static string
get_title()

The title of the Meta Box.

static string
get_nonce()

A generated nonce for super class forms.

static string
get_nonce_action()

A generated nonce action for super class forms.

static string
create_input_name(string $input_name)

Get the HTML name attribute prefix for grouping data inputs in this meta box.

static 
_save_post(int $post_id, WP_Post|null $Post = null)

WordPress hook for 'save_post', verify autosaving and Meta Box nonce.

static 
_render()

The hook to use when adding the meta box to the WordPress environment. The gets called in { $this->add_meta_box() }.

add_meta_box()

Add the Meta Box to the WordPress environment.

static mixed
get_post_data()

Return the expected input data from the POST data.

Details

at line 108
__construct()

Construct the Meta_Box. Set the default properties if they are not set.

in Singleton at line 42
final static Singleton instance(mixed $args = null)

Maybe initialize singleton instance and return the instance.

Parameters

mixed $args

The arguments to pass to the singleton constructor if constructing.

Return Value

Singleton

This instance.

in Singleton at line 63
final static array get_instances()

Return a copy of the instances array.

Return Value

array

A list of Singleton instances that have been instantiated.

in Singleton at line 72
final protected ReflectionClass get_class_reflection()

A short one-liner tool to get a ReflectionClass so we can get runtime info for the static class instance and not this abstract.

Return Value

ReflectionClass

The runtime instance of this class being evalutated.

at line 50
abstract static protected render()

The function that will output the Meta Box HTML. Hooked by { $this->add_meta_box() } through { self::_render() }.

at line 58
abstract static protected save_post(int $post_id, WP_Post|null $Post = null)

The code to be run after the _save_post hook checks.

Parameters

int $post_id

The ID of the Post being saved.

WP_Post|null $Post

A copy of the Post instance being saved.

at line 65
abstract static string meta_key()

A meta key to use when saving the Post Meta to the database. Should be lowercase and underscored.

Return Value

string

The lowercase, underscored meta key.

at line 73
abstract static string get_id()

Return the ID of the Meta Box (used in the "id" attribute, says WordPress docs, i.e. the "id" attribute in the HTML DOM for Javascript events).

The ID should be lowercase and underscored to be consistent with the { $this->meta_key() } value.

Return Value

string

The slug ID of the Meta Box.

at line 80
abstract static string get_title()

The title of the Meta Box.

Return Value

string

The Meta Box title.

at line 87
final static string get_nonce()

A generated nonce for super class forms.

Return Value

string

The nonce.

at line 94
final static string get_nonce_action()

A generated nonce action for super class forms.

Return Value

string

The nonce action.

at line 103
final static string create_input_name(string $input_name)

Get the HTML name attribute prefix for grouping data inputs in this meta box.

Parameters

string $input_name

The desired key you would like the input value to be submitted with.

Return Value

string

The name attribute prefix for inputs.

at line 124
final static _save_post(int $post_id, WP_Post|null $Post = null)

WordPress hook for 'save_post', verify autosaving and Meta Box nonce.

Parameters

int $post_id

The ID of the Post being saved.

WP_Post|null $Post

A copy of the Post instance being saved.

at line 151
final static _render()

The hook to use when adding the meta box to the WordPress environment. The gets called in { $this->add_meta_box() }.

at line 159
final add_meta_box()

Add the Meta Box to the WordPress environment.

at line 175
final static mixed get_post_data()

Return the expected input data from the POST data.

Return Value

mixed

The data expected from the post or NULL if not found.