Settings API for WordPress

0.0.5 2020-01-21 07:10 UTC

This package is auto-updated.

Last update: 2024-04-29 03:15:48 UTC


Build Status Latest Stable Version Total Downloads Latest Unstable Version License PHP from Packagist

WordPress Settings API the OOP way

Work in progress: the project is currently in beta until considered viable. Until a 1.0.0 release the code in this repository is not stable. Expect changes breaking backward compatibility between minor versions (0.1.x -> 0.2.x).

Table Of Contents


The best way to use this package is through Composer:

composer require italystrap/settings

This package adheres to the SemVer specification and will be fully backward compatible between minor versions.

Idea of the structure

  • Plugin MUST HAVE one options storage (call get_option one time and get all the options)
  • Plugin COULD HAVE one or more settings pages with its own menu link (Parent and/or Child)
  • Settings page COULD HAVE 0, 1 or many section
  • Sections MUST HAVE at least 1 field
  • Sections ARE separated by tabs
  • Plugin COULD HAVE 0, 1 or more links in the plugins.php page

Basic Usage

The simpler way to use it is to instantiate the Builder and add the stuff you need.

You can find last updated code in the example.php file

use ItalyStrap\Settings\Page;
use ItalyStrap\Settings\SettingsBuilder;

$text_domain = 'ItalyStrap';
$option_name = 'italystrap';
$settings_config = \ItalyStrap\Config\ConfigFactory::make(
	require __DIR__ . '/tests/_data/fixtures/config/settings.php'

// Initialize the builder
$settings = new SettingsBuilder(

// You can add configuration via the \ItalyStrap\Config\ConfigFactory::class
	$settings_config->get( 'page' ),
	$settings_config->get( 'sections' )

// Ora manually
// The section parameter is optional
// Not every page need a section with fields
// For example in a docs page
// Manu title and slug are mandatory
		Page::PARENT		=> 'italystrap-dashboard',
		Page::PAGE_TITLE	=> \__( 'Dashboard 2', 'italystrap' ),
		Page::MENU_TITLE	=> \__( 'Child1', 'italystrap' ),
		Page::SLUG			=> 'slug-for-child-page',
		Page::VIEW			=> __DIR__ . '/tests/_data/fixtures/view/empty_form.php',

// You can also add a sub page either for you parent page or for the WP admin pages
		Page::PARENT		=> 'options-general.php',
//		Page::PAGE_TITLE	=> \__( 'ItalyStrap Dashboard 2', 'italystrap' ),
		Page::MENU_TITLE	=> \__( 'Child-general', 'italystrap' ),
		Page::SLUG			=> 'slug-for-child-general',
		Page::VIEW			=> __DIR__ . '/tests/_data/fixtures/view/empty_form.php',

// You can also add a link to the plugins.php page in your plugin link for activation
// For example if you want to add an external link to your docs.
	[ 'target' => '_blank' ]

// After you added pages[?section] and/or link call the build() method.

Advanced Usage



All feedback / bug reports / pull requests are welcome.


Copyright (c) 2019 Enea Overclokk, ItalyStrap

This code is licensed under the MIT.