includes/Admin/class-metabox.php
Handles the functionality for adding and saving metaboxes.
Class Metabox
Metabox Class for Preload Image URL and Asset Manager.
class Metaboxpublic __construct()
public function __construct()Constructor to hook into WordPress actions for adding and saving the metabox.
public add_metabox()
public function add_metabox()Adds metaboxes to the post editor.
public render_metabox()
public function render_metabox($post)Renders the content of the preload image URL metabox. Parameter Type Default Description $post\\WP_Post— The current post object.
public render_asset_manager_metabox()
public function render_asset_manager_metabox($post)Renders the Asset Manager metabox content. Parameter Type Default Description $post\\WP_Post— The current post object.
public save_metabox()
public function save_metabox($post_id, =null $post, =false $update)Saves metabox data when the post is saved. Parameter Type Default Description $post_idint— The ID of the post being saved. $post=null— The post object being saved (null in unit-test direct calls). $update=false— Whether this is an update of an existing post.
private save_preload_image_urls()
private function save_preload_image_urls($post_id)Saves the preload image URLs metabox data. Parameter Type Default Description $post_idint— The ID of the post being saved.
private save_asset_manager_settings()
private function save_asset_manager_settings($post_id)Saves the Asset Manager metabox data (disabled scripts and styles). Parameter Type Default Description $post_idint— The ID of the post being saved.
publicstatic format_asset_size()
public static function format_asset_size($size): stringFormat a captured asset size for the metabox Size column. Parameter Type Default Description $sizemixed— Size in bytes (int) or null when unknown.
Return: string — Human-readable size (e.g. `12.3 KB`) or an em dash when unknown.
privatestatic blocked_notice_key()
private static function blocked_notice_key(int $post_id): stringTransient key for the per-page protected-handle blocked notice. Parameter Type Default Description $post_idint— The post ID.
Return: string — The transient key.
privatestatic set_blocked_notice()
private static function set_blocked_notice(int $post_id, array $handles): voidStore the list of protected handles blocked on the last save. Parameter Type Default Description $post_idint— The post ID. $handlesarray— Blocked handles.
Return: void.
privatestatic consume_blocked_notice()
private static function consume_blocked_notice(int $post_id): arrayConsume (read + delete) the blocked-handle flash notice. Parameter Type Default Description $post_idint— The post ID.
Return: array — Blocked handles, or empty when none pending.
privatestatic clear_blocked_notice()
private static function clear_blocked_notice(int $post_id): voidClear any pending blocked-handle notice (used by one-click revert). Parameter Type Default Description $post_idint— The post ID.
Return: void.
private get_raw_post_array()
private function get_raw_post_array(string $key): arraySafely retrieves an unslashed array from $_POST if it exists and is an array. Parameter Type Default Description $keystring— The $_POST key to check.
Return: array — The raw unslashed array, or an empty array if invalid.
private get_raw_post_string()
private function get_raw_post_string(string $key): stringSafely retrieves an unslashed scalar string from $_POST. Parameter Type Default Description $keystring— The $_POST key to check.
Return: string — The raw unslashed string, or an empty string if invalid.
private process_disabled_assets()
private function process_disabled_assets(array $raw_data, array $valid_handles): arrayHelper method to process disabled assets. Parameter Type Default Description $raw_dataarray— Raw input array from $_POST. $valid_handlesarray— Array of valid handles for the page.
Return: array — Sanitized and whitelisted array of disabled handles.
private process_delay_setting()
private function process_delay_setting(array $raw_data, array $valid_handles, array $allowed_values): arrayHelper method to process associative delay settings (strategies, priorities). Parameter Type Default Description $raw_dataarray— Raw input associative array from $_POST. $valid_handlesarray— Array of valid script handles for the page. $allowed_valuesarray— Array of valid values for the setting.
Return: array — Sanitized and whitelisted associative array.