Download the PHP package yipresser/wp-settings-api-helper without Composer
On this page you can find all versions of the php package yipresser/wp-settings-api-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yipresser/wp-settings-api-helper
More information about yipresser/wp-settings-api-helper
Files in yipresser/wp-settings-api-helper
Package wp-settings-api-helper
Short Description A helper class to simplify WordPress Settings and creation of Settings page in WP plugins.
License GPL-3.0-or-later
Informations about the package wp-settings-api-helper
wp-settings-api-helper
An abstract class that simplifies the process of creating WordPress admin settings pages using the WordPress Settings API.
Installation
You can install this package via Composer:
Alternatively, you can use this class in your WordPress plugins or themes to easily define settings sections, fields, and handle their saving process.
Usage
To use the helper, create a new class that extends Yipresser\WpSettingsApiHelper\WP_Settings_API_Helper.
1. Extend the Class and initialize the Settings
You need to define $settings_options for your database options and $settings_sections for the visual sections and fields you want to show on the page. Lastly, you need to run the setup() method.
2. Display the Settings Form
When rendering your options page HTML, call the render_settings_on_page() method so it can generate the settings form, fields, and submit button.
Supported Field Types
The type key in your field configuration supports the following values:
textnumber(supportsminandmaxattributes)emailpasswordtextareacode-editor(supports optionalcode_typeandcode_theme)select(requires achoicesarray['value' => 'Label'])radio(requires achoicesarray)checkbox(optionallabelfor text next to checkbox)checkboxes(requires achoicesarray)slider-checkboxdropdown_pageshiddencallback(requirescallbackand optionalparamkeys to render custom HTML)
Example Select Field
Example Code Editor Field
code_type accepts shorthand values like css, js, javascript, php, html, json, scss, and markdown, or a full MIME-style value like text/css or application/x-httpd-php.
If you set code_theme, the helper only passes the theme name to CodeMirror. It does not enqueue the theme stylesheet for you. You can get the matching CodeMirror 5 theme CSS file from https://github.com/codemirror/codemirror5/tree/master/theme, add it to your plugin or theme, and enqueue it yourself:
Sanitization and Validation
By default, a placeholder sanitize_settings method is provided which returns the options untouched. You need to override sanitize_settings($option) in your child class to safely sanitize your data before saving them to the database.