PHPackages                             wordpressvn/wp-settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wordpressvn/wp-settings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wordpressvn/wp-settings
=======================

Handy wrapper to make creating WordPress settings pages a breeze.

2.6.0(5mo ago)0109GPL-3.0PHPPHP ^8.0

Since Mar 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/wordpressvn/wp-settings)[ Packagist](https://packagist.org/packages/wordpressvn/wp-settings)[ RSS](/packages/wordpressvn-wp-settings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

WP Settings
===========

[](#wp-settings)

This package aims to make it easier to create settings pages for WordPress plugins. Typically, you would use the [Settings API](https://developer.wordpress.org/plugins/settings/settings-api/) or write something custom. While the Settings API works, there is still quite a lot to set up. You still need to write the HTML for your options for example. And it gets quite complicated if you want to add tabs and tab-sections. See this [comparison](https://www.youtube.com/watch?v=WoBRuLgacDo).

Installation
------------

[](#installation)

```
composer require wordpressvn/wp-settings
```

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

```
use WPVNTeam\WPSettings\WPSettings;

$settings = new WPSettings(__('My Plugin Settings'));

$tab = $settings->add_tab(__( 'General', 'textdomain'));

$section = $tab->add_section('MailChimp');

$section->add_option('text', [
    'name' => 'mailchimp_api_key',
    'label' => __('API Key', 'textdomain')
]);

$settings->make();
```

### Creating the settings instance

[](#creating-the-settings-instance)

```
$settings = new WPSettings(__('My Plugin Settings'));
```

By default, the page slug is created by sanitizing the title. You may pass a specific slug as the second parameter of the constructor.

Other methods for this class:

```
$settings->set_capability('manage_options');
$settings->set_option_name('my_plugin_options');
$settings->set_menu_icon('dashicons-admin-generic');
$settings->set_menu_position(5);
$settings->set_menu_parent_slug('options-general.php');
```

### Tabs

[](#tabs)

Tabs are only displayed when there is more then one.

```
$settings->add_tab(__( 'General', 'textdomain'));
```

### Sections

[](#sections)

You can call the `add_section` method from an instance of `Tab`. You can also call it from the `WPSettings` instance. It will then be added to the last created `Tab`.

```
$tab->add_section('Section 1');
```

If you want sections to be displayed as submenu-items, you can do:

```
$tab->add_section('Section 1', ['as_link' => true]);
```

Note that this only has an effect when you have more then one `as_link` section.

### Options

[](#options)

To add an option, you either call the `add_option` method from an instance of `Section`. You may also call `add_option` from the `WPSettings` instance. The option will then be added to the last created section.

#### Text

[](#text)

```
$section->add_option('text', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
]);
```

In addition to `name` and `label`, you can also pass `type`. This makes it possible to set the input type to, for example, password or number.

#### Textarea

[](#textarea)

```
$section->add_option('textarea', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain'),
]);
```

You may also set the `cols` and `rows` attributes.

#### Checkbox

[](#checkbox)

```
$section->add_option('checkbox', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
]);
```

#### Select

[](#select)

```
$section->add_option('select', [
    'name' => 'option_1',
    'label' => __( 'Option 1', 'textdomain' ),
    'options' => [
        'value_1' => 'Label 1',
        'value_2' => 'Label 2'
    ]
]);
```

#### Select2

[](#select2)

```
$section->add_option('select2', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain'),
    'options' => [
        'value_1' => 'Label 1',
        'value_2' => 'Label 2'
    ]
] );
```

#### WP Editor

[](#wp-editor)

```
$section->add_option('wp-editor', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

#### Code Editor

[](#code-editor)

```
$section->add_option('code-editor', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

#### Color

[](#color)

```
$section->add_option('color', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

#### Media

[](#media)

```
$section->add_option('media', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

For an image specific, you can use:

```
$section->add_option('image', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

For video specific, you can use:

```
$section->add_option('video', [
    'name' => 'option_1',
    'label' => __('Option 1', 'textdomain')
] );
```

### Validation

[](#validation)

You are able to validate an option. You may pass a callback and a feedback message. You can pass multiple validation rules.

```
$section->add_option('text', [
    'name' => 'mailchimp_api_key',
    'label' => __('API Key', 'textdomain'),
    'validate' => [
        [
            'feedback' => __('Your API key is too short.', 'textdomain'),
            'callback' => function($value) {
                return strlen($value) > 35;
            }
        ]
    ]
]);
```

### Sanitization

[](#sanitization)

You may pass a sanitization callback.

```
$section->add_option('text', [
    'name' => 'mailchimp_api_key',
    'label' => __('API Key', 'textdomain'),
    'santitize' => function($value) {
        return sanitize_key($value);
    }
]);
```

### Options array structure

[](#options-array-structure)

By default, the options are stored as a one level array:

```
[
    'option_1' => 'value 1',
    'option_2' => 'value 2',
]

```

However, you can add tab and/or section levels in this structure.

```
$tab = $settings->add_tab(__( 'General', 'textdomain'))
    ->option_level();

$section = $tab->add_section('Example', ['as_link' => true])
    ->option_level();
```

Which would result in:

```
[
    'general' => [
        'example' => [
            'option_1' => 'value 1',
            'option_2' => 'value 2',
        ]
    ]
]

```

### Adding a custom option type

[](#adding-a-custom-option-type)

To add an custom option type, you can use the `wp_settings_option_type_map` filter.

```
add_filter('wp_settings_option_type_map', function($options){
    $options['custom'] = YourCustomOption::class;
    return $options;
});
```

You will need to create a class for your custom option type.

```
use WPVNTeam\WPSettings\Options\OptionAbstract;

class YourCustomOption extends OptionAbstract
{
    public $view = 'custom-option';

    public function render()
    {
        echo 'Your custom option HTML';
    }
}
```

Once registered, you can then use your option type like so:

```
$settings->add_option('custom-option', [
    'name' => 'your_option_name',
    'label' => __('Your label')
]);
```

Contributors
------------

[](#contributors)

- [Jeffrey van Rossum](https://github.com/jeffreyvr)

License
-------

[](#license)

MIT. Please see the [License File](/LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance69

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~112 days

Total

12

Last Release

178d ago

Major Versions

1.9.0 → 2.0.02024-09-01

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

2.6.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e94123630d250ccc2fcf91fcf25ada2b6fee4879844e1b60ab1ec5e46c15a315?d=identicon)[wordpressvn](/maintainers/wordpressvn)

---

Top Contributors

[![wordpressvn](https://avatars.githubusercontent.com/u/45707210?v=4)](https://github.com/wordpressvn "wordpressvn (25 commits)")

### Embed Badge

![Health badge](/badges/wordpressvn-wp-settings/health.svg)

```
[![Health](https://phpackages.com/badges/wordpressvn-wp-settings/health.svg)](https://phpackages.com/packages/wordpressvn-wp-settings)
```

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[crwlr/crawler

Web crawling and scraping library.

37214.8k2](/packages/crwlr-crawler)[lingaro/magento2-codegen

Magento 2 Code Generator

966.5k](/packages/lingaro-magento2-codegen)[jeffreyvanrossum/wp-settings

Handy wrapper to make creating WordPress settings pages a breeze.

902.6k1](/packages/jeffreyvanrossum-wp-settings)[dotink/jin

Jsonified Ini Notation

1410.2k2](/packages/dotink-jin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
