https://github.com/chandrapatel/wp-custom-settings
Allows developers to create a custom admin menu page with settings using Settings API without registering callbacks to every settings section and field.
https://github.com/chandrapatel/wp-custom-settings
settings-api wordpress wordpress-php-library
Last synced: 13 days ago
JSON representation
Allows developers to create a custom admin menu page with settings using Settings API without registering callbacks to every settings section and field.
- Host: GitHub
- URL: https://github.com/chandrapatel/wp-custom-settings
- Owner: chandrapatel
- Created: 2020-08-15T10:43:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-24T11:38:17.000Z (over 5 years ago)
- Last Synced: 2024-11-16T01:44:07.488Z (about 1 year ago)
- Topics: settings-api, wordpress, wordpress-php-library
- Language: PHP
- Homepage:
- Size: 335 KB
- Stars: 19
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WP Custom Settings
Allows developers to create a custom admin menu page with settings using Settings API without registering callbacks to every settings section and field.
## Supported form elements and input types
- Textarea
- Select
- Input Types
- Text
- Password
- Email
- Url
- Tel
- Number
- Color
- Date
- Datetime-local
- Month
- Week
- Time
## Installation
The plugin is available as a [Composer package](https://packagist.org/packages/chandrapatel/wp-custom-settings).
```
composer require chandrapatel/wp-custom-settings
```
**Note:** If you are not using Composer then I'd suggest to add WP Custom Settings main file in your theme or plugin instead of adding as standalone plugin. This way you can modify it as per your need and avoid dependency.
## Usage
You need to create an object of `WP_Custom_Settings` class and it accepts three arguments to create menu page, register setting and sections & fields.
Please check [example.php](https://github.com/chandrapatel/wp-custom-settings/blob/master/example.php) file.
```php
$custom_settings = new WP_Custom_Settings(
// Arguments to add menu page. Following arguments are same as add_menu_page() function arguments.
// Callback argument does not needed.
[
'page_title' => __( 'Custom Settings', 'wp-custom-settings' ),
'menu_title' => __( 'Custom Settings', 'wp-custom-settings' ),
'capability' => 'manage_options',
'menu_slug' => 'wp-custom-settings-page',
'icon_url' => '',
'position' => null,
],
// Arguments to register setting. Following arguments are same as register_setting() function arguments.
[
'option_group' => 'wp_custom_settings_group',
'option_name' => 'wp_custom_settings_options',
'args' => array(
'type' => 'array',
'description' => 'Description of Custom Settings.',
'show_in_rest' => true,
'default' => array(),
'sanitize_callback' => null,
),
],
// Arguments to add sections and fields.
[
new WP_Custom_Settings_Section(
'wp_custom_settings_section', // ID.
__( 'Section Title.', 'wp-custom-settings' ), // Title.
__( 'Section Description.', 'wp-custom-settings' ), // Description.
[
new WP_Custom_Settings_Field(
'text', // Field type.
'wp_custom_settings_field', // ID. Also, it will used for "name" attribute.
__( 'Field Title', 'wp-settings-api-wrapper' ), // Title.
[ // Pass additional arguments.
'description' => 'Description of Custom Settings.',
'label_for' => 'wp_custom_settings_field',
'class' => 'regular-text',
]
),
]
),
]
);
```
## Screenshot
