amirhwsin/wpsbuilder

There is no license information available for the latest version (v1.0.4) of this package.

Build setting pages for wordpress and show in menus or submenus.

v1.0.4 2020-12-12 18:26 UTC

This package is auto-updated.

Last update: 2024-05-12 22:45:50 UTC


README

Top Langs Open Source Love svg3

WpsBuilder is a tool to create wordpress like setting page or edit page.

  • Can add Menu or submenu
  • Support most of input types
  • Support callback response function

Supported inputs

All the inputs uses wordpress classes.

  • Text Input
  • Hidden input
  • Text Area
  • Select box
  • Radio Groups
  • CheckBoxes
  • Media Selector (Still in development)
  • Text (p tag)

You can also:

  • Set forms method (post,get,put,...)
  • Set Page and menu Title
  • Set page description

Installation

WpsBuilder requires WordPress v4+ and php v5.6+ to run.

Install using composer.

$ composer require amirhwsin/wpsbuilder

or install manually, first download package.

require_once('wpsBuilder/wpsBuilder.php');

Usage

WpsBuilder have simple and easy syntax, you can see some examples for menu or submenu cases.

Create Menu

$builder = new wpsBuilder();
$builder->addMenu('magical_menu')
        ->setPosition(6)
        ->setCapability('manage_options')
        ->setIconUrl('dashicons-editor-code')
        ->setPageTitle('Magic is real')
        ->setMenuTitle('See Magic')
        ->setPageDescription('This page can do some magics for you.')
        ->setFormMethod('post')
        ->input('pass', 'Password',  array(['key' => 'type', 'value' => 'password']))
        ->textArea('describe_ys', 'Describe yourself to me')
        ->hiddenInput('hidden_value','thats_right')
        ->text('yu','Username', 'amirhwisn *You cant edit this')
        ->checkbox('cbid', 'Do magic can happen?', 'Shall we play magic?', true)
        ->radio('radio', array('field_1' => 'this one', 'field_2' => 'that one'),'Which you choose?', 'that one')
        ->select('selectbox', array('key1'=> 'one', 'key2' => 'two'), 'title', 'two')
        ->media('media_id', 'Choose Profile picture')
        ->build();

Create Submenu

$builder = new wpsBuilder();
$builder->attachToMenu('magical_menu')
         ->setPageTitle('This is a little magic')
         ->setMenuTitle('Menu Title')
         ->setCapability('manage_options')
         ->setMenuSlug('magical_submenu')
         ...
         ->build();

Get Response and store data

You can call `responsefunction and pass a function as an argument and do your stuff. When you callresponseyou get a variable from your declared function can called anything thats your data that collected from form. Remember at the end you should pass an array from yourfunctionthat first element is response message like unvalid errors or success message and second one should betrueorfalse` as success or failed; In case of null passed or nothing passed no messages will be shown at the page.

$builder->response(function($res) {
        print_r($res);
        return array('message', true);
});

Todos

  • Develope media functions
  • Create a usefull document
  • Add more inputs

License

GPL2

Free Software, Hell Yeah! Feel free to contribute