MetaBox
in package
MetaBox Module class.
Table of Contents
Properties
- $action_hook_add : ActionHook
- ActionHook instance.
- $action_hook_save : ActionHook
- ActionHook instance.
- $callback : callable
- Meta box callback.
- $callback_args : array<string|int, mixed>
- Meta box callback arguments.
- $context : string
- Meta box context.
- $id : string
- Meta box ID.
- $priority : string
- Meta box priority.
- $screen : string
- Meta box screen.
- $title : string
- Meta box title.
Methods
- __construct() : mixed
- Constructor.
- __toString() : string
- Custom toString magic method.
- add_meta_box() : mixed
- Adds the meta box to WordPress.
- render_post_meta_box() : mixed
- Default callback for rendering the meta box content.
- update_post_meta() : mixed
- Updates the post meta.
- initialize() : void
- Initializes the meta box.
Properties
$action_hook_add
ActionHook instance.
private
ActionHook
$action_hook_add
ActionHook object for the add_meta_box method.
Tags
$action_hook_save
ActionHook instance.
private
ActionHook
$action_hook_save
ActionHook object for the save_post method.
Tags
$callback
Meta box callback.
private
callable
$callback
Meta box callback. Defaults to internal rendering method if not provided.
Tags
$callback_args
Meta box callback arguments.
private
array<string|int, mixed>
$callback_args
Meta box callback arguments.
Tags
$context
Meta box context.
private
string
$context
Meta box context.
Tags
$id
Meta box ID.
private
string
$id
Meta box ID. Must be unique.
Tags
$priority
Meta box priority.
private
string
$priority
Meta box priority.
Tags
$screen
Meta box screen.
private
string
$screen
Meta box screen.
Tags
$title
Meta box title.
private
string
$title
Meta box title.
Tags
Methods
__construct()
Constructor.
public
__construct(string $id, string $title[, callable|null $callback = null ][, string|null $screen = null ][, string $context = 'advanced' ][, string $priority = 'default' ][, array<string|int, mixed>|null $callback_args = null ][, ActionHook $action_hook_add = null ][, ActionHook $action_hook_save = null ]) : mixed
Initializes a MetaBox object with specified properties. If no callback is provided,
defaults to using the render_post_meta_box
method.
Parameters
- $id : string
-
Meta box ID. Must be unique.
- $title : string
-
Meta box title.
- $callback : callable|null = null
-
Optional. Meta box callback. Defaults to internal render method.
- $screen : string|null = null
-
Optional. Meta box screen. Default null.
- $context : string = 'advanced'
-
Optional. Meta box context. Default 'advanced'.
- $priority : string = 'default'
-
Optional. Meta box priority. Default 'default'.
- $callback_args : array<string|int, mixed>|null = null
-
Optional. Meta box callback arguments. Default null.
- $action_hook_add : ActionHook = null
-
Optional. ActionHook instance for the add_meta_box method. Default 'add_meta_boxes'.
- $action_hook_save : ActionHook = null
-
Optional. ActionHook instance for the save_post method. Default 'save_post'.
__toString()
Custom toString magic method.
public
__toString() : string
Returns the meta box as a JSON string.
Tags
Return values
string —JSON string.
add_meta_box()
Adds the meta box to WordPress.
public
add_meta_box() : mixed
Uses the add_meta_box()
function to add the meta box to WordPress.
Tags
render_post_meta_box()
Default callback for rendering the meta box content.
public
render_post_meta_box(WP_Post $post, array<string|int, mixed> $args) : mixed
Displays the meta box using custom fields defined in the callback arguments.
Parameters
- $post : WP_Post
-
Post object.
- $args : array<string|int, mixed>
-
Additional arguments including 'id' and 'field_type'.
update_post_meta()
Updates the post meta.
public
update_post_meta(int $post_id) : mixed
Updates the post meta with the specified field ID and field value.
Parameters
- $post_id : int
-
Post ID.
Tags
initialize()
Initializes the meta box.
private
initialize() : void
Hooks the action to register the meta box and adds the meta box to the registry.