monkeyscode/customizer

Create theme option in Wordpress

1.2.0 2018-01-09 15:18 UTC

This package is not auto-updated.

Last update: 2019-06-11 08:46:04 UTC


README

Create theme options

Installation

composer require monkeyscode/customizer

Usage

You have to run under customize_register action.

  • The Data passed through an instance is array. Each element of this array must have data:info and data:fields. Each element of data must have info:name as required. Other section options are optional. Every data:field must have field:name and field:type. Other field options are optional.

For example:

$data = [
    [
        'info' => [
            'name' => 'duy_customize_section',
            'label' => 'Duy Section',
            'description' => '',
            'priority' => 0,
        ],
        'fields' => [
            [
                'name' => 'my_text',
                'type' => 'text',
                'default' => 'hole',
                'label' => 'Text Field'
            ]
        ]
    ],
    [
        'info' => [
            'name' => 'duy_customize_section_2',
            'label' => 'Duy Section 2',
            'description' => '',
            'priority' => 0,
        ],
        'fields' => [
            [
                'name' => 'my_text_2',
                'type' => 'text',
                'default' => 'hole 2',
                'label' => 'Text Field 2'
            ]
        ]
    ],
];

$customizer = new Customizer($data);
$customizer->create();

List of Fields

  • Text Field
[
    'name' => 'my_field',
    'type' => 'text',
    'default' => 'hole',
    'label' => 'Text Field'
]
  • Textarea Field
[
    'name' => 'my_field',
    'type' => 'textarea',
    'default' => 'hole',
    'label' => 'Textarea Field'
]
  • Radio Field
[
    'name' => 'my_field',
    'type' => 'radio',
    'default' => 'hole',
    'label' => 'Radio Field',
    'choices' => [
        1 => 1,
        2 => 2
    ]
]
  • Checkbox Field
[
    'name' => 'my_field',
    'type' => 'checkbox',
    'default' => 'hole',
    'label' => 'Checkbox Field',
]
  • Select Field
[
    'name' => 'my_field',
    'type' => 'select',
    'default' => 'hole',
    'label' => 'Select Field',
    'choices' => [
        1 => 1,
        2 => 2
    ]
]
  • Upload Field
[
    'name' => 'my_field',
    'type' => 'upload',
    'default' => 'hole',
    'label' => 'Upload Field',
]
  • Color Field
[
    'name' => 'my_field',
    'type' => 'color',
    'default' => 'hole',
    'label' => 'Color Field',
]

Use in template file

get_option('<section_name>_<field_name>');

Contributor

Duy Nguyen