Mendefinisikan Tipe Field
Field ditambahkan ke panel menggunakan method $panel->add_field(). Pastikan parameter section sesuai dengan id section yang dituju.
1. text
Input teks satu baris standar.
$panel->add_field( array(
'id' => 'site_tagline',
'section' => 'general',
'type' => 'text',
'title' => 'Tagline Situs',
'default' => 'Portal Berita Terpercaya',
'desc' => 'Slogan singkat yang melengkapi nama situs.',
) );
2. textarea
Input area teks multi-baris (misalnya untuk deskripsi, custom tracking code, atau alamat).
$panel->add_field( array(
'id' => 'footer_about',
'section' => 'general',
'type' => 'textarea',
'title' => 'Teks Tentang Kami (Footer)',
'default' => 'Perusahaan penyedia solusi digital terdepan di Indonesia.',
'desc' => 'Maksimal 250 karakter.',
) );
3. color
Pemilih warna interaktif berbasis WordPress Color Picker (Iris).
$panel->add_field( array(
'id' => 'brand_color',
'section' => 'general',
'type' => 'color',
'title' => 'Warna Utama Brand',
'default' => '#030813',
'desc' => 'Warna utama untuk tombol dan navbar.',
) );
4. image
Terintegrasi langsung dengan WordPress Media Uploader (modal pustaka media). Menyimpan URL string gambar.
$panel->add_field( array(
'id' => 'logo_url',
'section' => 'general',
'type' => 'image',
'title' => 'Logo Situs',
'desc' => 'Unggah gambar logo dalam format WebP, PNG, atau SVG.',
) );
5. select
Dropdown pilihan statis maupun dinamis.
$panel->add_field( array(
'id' => 'layout_style',
'section' => 'general',
'type' => 'select',
'title' => 'Gaya Layout Kontainer',
'default' => 'boxed',
'options' => array(
'boxed' => 'Kotak (Boxed)',
'full' => 'Layar Penuh (Fullwidth)',
),
) );
Select dengan Divider / Header Grup
Anda dapat menambahkan pemisah visual dengan mendeklarasikan key yang memiliki nilai array() kosong. Baris ini akan dirender sebagai <option disabled> yang tidak dapat dipilih pengguna:
$panel->add_field( array(
'id' => 'header_layout',
'section' => 'header',
'type' => 'select',
'title' => 'Tata Letak Header',
'default' => 'default',
'options' => array(
'— Layout Standar —' => array(), // ← Divider (disabled)
'default' => 'Default — Logo kiri, menu kanan',
'centered' => 'Centered — Logo tengah dengan sub-bar',
'— Layout Khusus —' => array(), // ← Divider (disabled)
'magazine' => 'Magazine — Logo besar & ad banner',
),
) );
Select Dinamis (Query Database)
Mengambil daftar opsi dari kategori atau postingan WordPress:
$cats = get_categories( array( 'hide_empty' => false ) );
$cat_options = array( '' => '— Pilih Kategori —' );
foreach ( $cats as $cat ) {
$cat_options[ $cat->term_id ] = $cat->name . ' (' . $cat->count . ')';
}
$panel->add_field( array(
'id' => 'featured_cat',
'section' => 'general',
'type' => 'select',
'title' => 'Kategori Unggulan Beranda',
'default' => '',
'options' => $cat_options,
) );
6. switch
Saklar toggle aktif/nonaktif modern. Menyimpan nilai string '1' (aktif) atau '0' (nonaktif).
$panel->add_field( array(
'id' => 'show_cta',
'section' => 'header',
'type' => 'switch',
'title' => 'Tampilkan Tombol CTA',
'default' => '1',
'desc' => 'Aktifkan untuk menampilkan tombol aksi di ujung kanan navbar.',
) );
7. typography
Field grup komposit khusus untuk tipografi. Menyimpan data sebagai sub-array berstruktur:
family(string): Slug jenis font.size(string): Ukuran font beserta satuan (misal:1.5rematau24px).line_height(string): Jarak antar baris (misal:1.4).weight(string): Ketebalan font (misal:400,600,bold).color(string): Kode heksadesimal warna teks.
$panel->add_field( array(
'id' => 'typo_heading',
'section' => 'typography',
'type' => 'typography',
'title' => 'Heading Utama (H1–H3)',
'default' => array(
'family' => '', // Kosong = font default tema
'size' => '2.25rem',
'line_height' => '1.25',
'weight' => '700',
'color' => '#0e0f0f',
),
) );
Pilihan daftar font family pada field ini diambil melalui filter madoptionsfontoptions.
Jika Anda ingin meng-override daftar font khusus untuk field tertentu saja, tentukan array di parameter options:
> 'options' => array(
> '' => 'Default Monospace',
> 'monospace' => 'Monospace Sistem',
> 'SFMono' => 'SFMono / Consolas',
> )
>