Skip to content

Callback Field

Overview

The callback field type allows you to execute a custom function or piece of code in the context of your settings or meta box. This is especially useful when you need to display complex UI elements, run custom logic, or output dynamic HTML.

Field Configuration

A simple implementation of the callback field type:

php
// 2. Callback field
array(
    'type'     => 'callback',
    'function' => 'cmf_callback_function',
),

// 1. Define your callback function any where
function cmf_callback_function() {
    echo '<h1>Welcome to CodexShaper Framework.</h1>';
};

Specific Parameters

ParameterTypeDefaultDescription
functionstring-The name of the function to be called. This function is responsible for rendering or processing output.

General Parameters

ParameterTypeDefaultDescription
idstring-Unique identifier for the field.
iconstring-Icon for each individual section.
typestring-Defines the field type.
titlestring-The title displayed for the field.
subtitlestring-The text displayed under the title.
classstring-Field additional class.
data_typestringserializeDefines how data is stored (e.g., serialize).
namestring-Custom name for the field.
placeholderstringNot selectedPlaceholder text for the input.
attributesarrayarray()Custom HTML attributes.
beforestring-Content to display before the field.
afterstring-Content to display after the field.
descriptionstring-A detailed description of the field.
descstring-A short description, used if description is not set.
helpstring-Additional helper text for guidance. Usually show on the top right corner of the field.
errorstring-Error message to display when validation fails.
dependenciesarray-Show/Hide a field base on another field value.

Example Usage

Simple Callback

php
array(
    'type'     => 'callback',
    'function' => 'my_callback_function',
),

function cmf_callback_function() {
    echo '<h1>Welcome to CodexShaper Framework.</h1>';
};

Advanced Callback with Additional Logic

php
array(
    'id'       => 'cmf_advanced_callback_field',
    'type'     => 'callback',
    'function' => 'cmf_advanced_callback',
    'desc'     => 'This field outputs a custom HTML block using a callback function.',
),

function cmf_advanced_callback() {
    // Perform some checks or retrieve data
    $dynamic_value = 'Some dynamic data';

    // Output HTML
    echo '<div class="my-advanced-callback">';
    echo '<h2>Dynamic Data:</h2>';
    echo '<p>' . esc_html($dynamic_value) . '</p>';
    echo '</div>';
};