dev-master
9999999-dev https://github.com/amarkal/amarkal-settingsAdd setting pages with Amarkal UI components to your WordPress theme or plugin
GPL-3.0
The Requires
by Askupa Software
wordpress settings form ui admin options user interface
Wallogit.com
2017 © Pedro Peláez
Add setting pages with Amarkal UI components to your WordPress theme or plugin
Add setting pages with amarkal-ui components to your WordPress theme or plugin., (*1)
Tested up to: WordPress 4.8
Dependencies: amarkal-core, amarkal-ui, (*2)
, (*3)
amarkal-settings lets you create setting pages for your theme or plugin, based on amarkal-ui components. Setting pages store data as options in the database, and use AJAX to store the data asynchronously to improve user experience., (*4)
If you are using the command line:, (*5)
$ composer require askupa-software/amarkal-settings:dev-master
Or simply add the following to your composer.json file:, (*6)
"require": {
"askupa-software/amarkal-settings": "dev-master"
}
And run the command, (*7)
$ composer install
This will install the package in the directory vendors/askupa-software/amarkal-settings.
Now all you need to do is include the composer autoloader., (*8)
require_once 'path/to/vendor/autoload.php';
Download amarkal-core, amarkal-ui and amarkal-settings from github and include them in your project., (*9)
require_once 'path/to/amarkal-core/bootstrap.php'; require_once 'path/to/amarkal-ui/bootstrap.php'; require_once 'path/to/amarkal-settings/bootstrap.php';
A Setting page is a graphical user interface (based on amarkal-ui) that provides a convenient way for your users to store and retrieve options for your theme/plugin. A setting page is presented in the admin menu as a child page to an existing top level menu item., (*10)
The following example shows how to add settings page that will be available under the 'Tools' submenu., (*11)
$page = amarkal_add_settings_page(array(
'slug' => 'my-settings-page',
'parent_slug' => 'tools.php', // The 'Tools' top level menu item slug
'title' => 'My Settings',
'menu_title' => 'My Settings'
));
Now you can use the returned instance to add settings fields. Any Amarkal UI component can be used as a field., (*12)
$page->add_field(array(
'type' => 'text',
'default' => 'Default text...',
'title' => 'My Text',
'name' => 'my-text'
));
You can also divide your settings into sections, to better organize them and make it easier for the user to find what he is looking for., (*13)
When you add one or more sections, a sidebar will appear with all the added section names, as well as a search box to search for a settings field in all the sections., (*14)
$page->add_section(array(
'slug' => 'my-section', // Must be unique within the list of sections for this page
'title' => 'My Section'
));
// Make sure to add a 'section' argument to fields to associate them with a given section
$page->add_field(array(
'section' => 'my-section',
'type' => 'text',
'default' => 'Default text...',
'title' => 'My Text',
'name' => 'my-text'
));
You can retrieve the value of a certain field by its name, and the slug of the page in which it is registered., (*15)
This method checks the database first, and if nothing is found, it will return the field's default value., (*16)
$value = amarkal_get_settings_value('my-settings-page', 'my-text');
Add a settings page., (*17)
amarkal_add_settings_page( $args )
This function is used to create a settings page in WordPresss admin section. Once created, a menu item will be added to the submenu of the parent slug given in 'parent_slug'., (*18)
If you want to create a top-level settings page, you need to create a menu page using
add_menu_page(), and then set the settings page's'parent_slug'to the slug of the top-level menu page that you've created., (*19)
Parameters
* $args (Array) The list of page arguments. Acceptable arguments are:
* parent_slug (String) The slug name for the parent menu (or the file name of a standard WordPress admin page).
* slug (String) The slug name to refer to this menu by (should be unique for this menu).
* title (String) The text to be displayed in the title tags of the page when it is displayed.
* subtitle (String) The text to be displayed below the title at the top part of the page.
* menu_title (String) The text to be used for the menu.
* capability (String) The capability required for this menu to be displayed to the user. Used to determine whether or not a page is included in the menu.
* footer_html (String) Specifies the HTML to be printed at the footer of the settings page.
* subfooter_html (String) Specifies the HTML to be printed below footer of the settings page., (*20)
Return Value
(Amarkal\Settings\SettingsPag) The instance of the settings page, (*21)
Example Usage, (*22)
amarkal_add_settings_page(array(
'parent_slug' => 'tools.php',
'slug' => 'my-settings-page',
'title' => 'My Settings',
'menu_title' => 'My Settings',
'capability' => 'manage_options'
));
Get the instance of a settings page., (*23)
amarkal_get_settings_page( $slug )
This function is used to get the instance of a reigstered settings page by its slug., (*24)
Parameters
* slug (String) The slug name of the settings page, (*25)
Return Value
(Amarkal\Settings\SettingsPage) The instance of the settings page, (*26)
Example Usage, (*27)
$page = amarkal_get_settings_page('my-settings-page');
Get the value of the given field., (*28)
amarkal_get_settings_value( $slug, $field_name )
This function is used to retrieve the value of a given field. If no value exists in the database, the default value will be returned. This function makes a call to get_option() internally, providing the default value of the field as the second argument., (*29)
Parameters
* $slug (String) The slug of the settings page to which this field belongs
* $field_name (String) The name of the field., (*30)
Return Value
(Mixed) The value of the given field., (*31)
Example Usage, (*32)
$value = amarkal_get_settings_value('my-settings','my-text');
Get all the values for the given settings page as an array., (*33)
amarkal_get_settings_values( $slug )
This function is used to retrieve all the value of a given settings page. If no value exists in the database, the default values will be returned. This function makes a call to get_option() internally, providing the default value of the field as the second argument., (*34)
Parameters
* $slug (String) The slug of the settings page of which the values are to be retrieved., (*35)
Return Value
(Array) The list of all field values, (*36)
Example Usage, (*37)
$values = amarkal_get_settings_values('my-settings');
Add setting pages with Amarkal UI components to your WordPress theme or plugin
GPL-3.0
wordpress settings form ui admin options user interface