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.
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 19
Watchers: 3
Forks: 4
Open Issues: 0
Type:wordpress-plugin
Requires
- php: >=7
- composer/installers: ^1.2
This package is not auto-updated.
Last update: 2024-11-18 05:47:31 UTC
README
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
- Url
- Tel
- Number
- Color
- Date
- Datetime-local
- Month
- Week
- Time
Installation
The plugin is available as a Composer package.
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 file.
$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', ] ), ] ), ] );