Coder Social home page Coder Social logo

refactored-settings's Introduction

Build Status Coverage Status

Refactored Settings

An easy to use fluent wrapper for the WordPress Settings API.

Requirements

PHP 5.3+

Example

Below is an example.

$settings = Refactored_Settings_0_5_0::withKey('my_settings')
    ->version('1.0');

$section = Refactored_Settings_Section_0_5_0::withKey('general')
    ->name('Sample Section')
    ->description('A short description.')
    ->addFields(array(
        Refactored_Settings_Field_0_5_0::withKey('name')
            ->type('text')
            ->name('Field Name')
            ->description('The name of a custom field.')
            ->defaultValue('custom'),
        Refactored_Settings_Field_0_5_0::withKey('enabled')
            ->type('checkbox')
            ->name('Enabled')
            ->description('If the feature should be enabled.')
            ->defaultValue(false),
    ));

$settings->addSection($section);

$settings->init();

You should now have a fully functioning settings page with all the options you've specified. You'll also be able to access your settings:

$settings->general->enabled->getValue();

Versioning

To avoid possible conflicts with plugins using different versions, class names have the version number appended.

Please be aware this project is still in development and may rapidly change.

Hooks

Various action hooks are provided for your convenience.

Settings Hooks

These hooks are related to the main settings class which will be passed as an argument. Replace {$setting} with your chosen key.

rfs/pre_init:{$setting}

Fires before the setting is initialized. Useful for adding sections on the fly.

rfs/post_init:{$setting}

Fires after the setting is initialized

rfs/before:{$setting}

Print to settings page before the form

rfs/after:{$setting}

Print to settings page after the form

rfs/activation:{$setting}

If a plugin file is specified, this is fired upon activation

rfs/deactivation:{$setting}

If a plugin file is specified, this is fired upon deactivation

Section Hooks

These hooks are related to the settings section class which will be passed as an argument. Replace {$setting} and {$section} with their relative keys.

rfs/pre_init:{$setting}.{$section}

Fires before the section is initialized. Useful for adding fields on the fly.

rfs/post_init:{$setting}.{$section}

Fires after the section is initialized

Field Hooks

These hooks are related to the settings field class which will be passed as an argument. Replace {$setting}, {$section}, and {$field} with their relative keys.

rfs/pre_init:{$setting}.{$section}.{$field}

Fires before the field is initialized

rfs/post_init:{$setting}.{$section}.{$field}

Fires after the field is initialized

refactored-settings's People

Contributors

suth avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.