class-metabox.php

Handles the functionality for adding and saving metaboxes.

Source includes/Admin/class-metabox.php4 min readPart of Performance Optimisation

includes/Admin/class-metabox.php

Handles the functionality for adding and saving metaboxes.

Namespace: PerformanceOptimise\\Inc · Lines: 1006

Class Metabox

Metabox Class for Preload Image URL and Asset Manager.

Source: includes/Admin/class-metabox.php, line 30

class Metabox

Tags: @since 1.0.0 · @package PerformanceOptimise\\Inc

public __construct()

public function __construct()

Constructor to hook into WordPress actions for adding and saving the metabox.

Tags: @since 1.0.0

Source: includes/Admin/class-metabox.php, line 37

public add_metabox()

public function add_metabox()

Adds metaboxes to the post editor.

Tags: @since 1.0.0

Source: includes/Admin/class-metabox.php, line 49

public render_metabox()

public function render_metabox($post)

Renders the content of the preload image URL metabox.

ParameterTypeDefaultDescription
$post\\WP_Post—The current post object.

Tags: @since 1.0.0 · @since 2.0.0 Output intentionally remains server-side/iframe-safe.

Source: includes/Admin/class-metabox.php, line 88

public render_asset_manager_metabox()

public function render_asset_manager_metabox($post)

Renders the Asset Manager metabox content.

ParameterTypeDefaultDescription
$post\\WP_Post—The current post object.

Tags: @since 1.1.0 · @since 2.0.0 Output intentionally remains server-side/iframe-safe.

Source: includes/Admin/class-metabox.php, line 138

public save_metabox()

public function save_metabox($post_id, =null $post, =false $update)

Saves metabox data when the post is saved.

ParameterTypeDefaultDescription
$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.

Tags: @since 1.0.0

Source: includes/Admin/class-metabox.php, line 489

private save_preload_image_urls()

private function save_preload_image_urls($post_id)

Saves the preload image URLs metabox data.

ParameterTypeDefaultDescription
$post_idint—The ID of the post being saved.

Tags: @since 1.2.1

Source: includes/Admin/class-metabox.php, line 515

private save_asset_manager_settings()

private function save_asset_manager_settings($post_id)

Saves the Asset Manager metabox data (disabled scripts and styles).

ParameterTypeDefaultDescription
$post_idint—The ID of the post being saved.

Tags: @since 1.2.1

Source: includes/Admin/class-metabox.php, line 583

publicstatic format_asset_size()

public static function format_asset_size($size): string

Format a captured asset size for the metabox Size column.

ParameterTypeDefaultDescription
$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.

Tags: @since 2.3.0

Source: includes/Admin/class-metabox.php, line 797

privatestatic blocked_notice_key()

private static function blocked_notice_key(int $post_id): string

Transient key for the per-page protected-handle blocked notice.

ParameterTypeDefaultDescription
$post_idint—The post ID.

Return: string — The transient key.

Tags: @since 2.3.0

Source: includes/Admin/class-metabox.php, line 820

privatestatic set_blocked_notice()

private static function set_blocked_notice(int $post_id, array $handles): void

Store the list of protected handles blocked on the last save.

ParameterTypeDefaultDescription
$post_idint—The post ID.
$handlesarray—Blocked handles.

Return: void.

Tags: @since 2.3.0

Source: includes/Admin/class-metabox.php, line 837

privatestatic consume_blocked_notice()

private static function consume_blocked_notice(int $post_id): array

Consume (read + delete) the blocked-handle flash notice.

ParameterTypeDefaultDescription
$post_idint—The post ID.

Return: array — Blocked handles, or empty when none pending.

Tags: @since 2.3.0

Source: includes/Admin/class-metabox.php, line 858

privatestatic clear_blocked_notice()

private static function clear_blocked_notice(int $post_id): void

Clear any pending blocked-handle notice (used by one-click revert).

ParameterTypeDefaultDescription
$post_idint—The post ID.

Return: void.

Tags: @since 2.3.0

Source: includes/Admin/class-metabox.php, line 896

private get_raw_post_array()

private function get_raw_post_array(string $key): array

Safely retrieves an unslashed array from $_POST if it exists and is an array.

ParameterTypeDefaultDescription
$keystring—The $_POST key to check.

Return: array — The raw unslashed array, or an empty array if invalid.

Tags: @since 2.0.0

Source: includes/Admin/class-metabox.php, line 917

private get_raw_post_string()

private function get_raw_post_string(string $key): string

Safely retrieves an unslashed scalar string from $_POST.

ParameterTypeDefaultDescription
$keystring—The $_POST key to check.

Return: string — The raw unslashed string, or an empty string if invalid.

Tags: @since 2.0.0

Source: includes/Admin/class-metabox.php, line 931

private process_disabled_assets()

private function process_disabled_assets(array $raw_data, array $valid_handles): array

Helper method to process disabled assets.

ParameterTypeDefaultDescription
$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.

Tags: @since 2.0.0

Source: includes/Admin/class-metabox.php, line 945

private process_delay_setting()

private function process_delay_setting(array $raw_data, array $valid_handles, array $allowed_values): array

Helper method to process associative delay settings (strategies, priorities).

ParameterTypeDefaultDescription
$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.

Tags: @since 2.0.0

Source: includes/Admin/class-metabox.php, line 975