clearcode/wordpress-settings

WordPress Settings library by Clearcode.

v1.1.3 2022-07-21 09:22 UTC

This package is auto-updated.

Last update: 2024-12-21 14:27:35 UTC


README

WordPress Settings library by Clearcode.

Installation

$ composer require clearcode/wordpress-settings
require __DIR__ . '/vendor/autoload.php';

new Settings( [
    'option_name' => [
        'group' => 'option_group', // optional
        'type' => 'string', // optional
        'description' => 'setting description', // optional
        'rest' => false, // optional
        'pages' => [
            'page_slug' => [
                'title' => 'page title',
                'capability' => 'manage_options', // optional
                'menu' => [
                    'title' => 'menu title',
                    'icon' => 'dashicons-admin-plugins',
                    'position' => null,
                    'parent' => 'options-general.php'
                ],
                'tabs' => [
                    'tab_1' => [
                        'title' => 'tab title',
                        'sections' => [
                            'section_1' => [
                                'title' => 'section title',
                                'render' => [
                                    'template' => 'section', // template file path
                                    'args' => [ 
                                        'content' => 'section description'
                                    ]
                                ],
                                'fields' => [
                                    'field_1' => [
                                        'title' => 'field title',
                                        'default' => 'default value',
                                        'sanitize' => function( $value ) { return $value; }, // callback function
                                        'render' => [
                                            'template' => 'input', // supported templates: input, textarea, select
                                            'args' => [
                                                'atts' => [
                                                    'type' => 'text'
                                                ],
                                                'before' => 'before text',
                                                'after' => 'after text',
                                                'description' => 'description text'
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
] );

License

GPL3.0+ see LICENSE.txt and AUTHORS.txt