Closed luizbills closed 5 years ago
There already is one. It lives in the Plugins subpage under Forms.
Here's how WP Libre Formbuilder does it (it doesn't do anything with it yet):
add_action("plugins_loaded", function () {
$wplf = wplf();
$builder = WP_Libre_Formbuilder::instance();
$wplf->plugins->register([
"name" => "Formbuilder",
"description" => "Visual editor for the HTML impaired.",
"link" => "https://github.com/k1sul1/wp-libre-formbuilder",
"version" => WPLFB_VERSION,
"instance" => $builder,
"settings_page" => [$builder, "renderSettingsPage"],
]);
});
It doesn't care how you save or render data, but it allows plugin authors to add a settings page. If we ever need a settings page in the core plugin, it can be added to the plugin class.
IMO we do not need separate settings page or availability to do so.
I was thinking in something like woocommerce settings page. A central of all plugins settings with a friendly API to easily add new settings.
something like this:
$my_prefix = 'wpfl_plugin';
// each section would have its own tab
// or we can create default tabs like: general, customization, email, etc
add_filter( 'wplf_settings_sections', function ( $sections ) use ( $my_prefix ) {
return array_merge( $sections, [
//slug => Section Name
$my_prefix => 'Custom Plugin',
] );
});
add_action( "wplf_${my_prefix}_display_settings", function () use ( $my_prefix ) {
// section title
echo '<h2>My Plugin Settings</h2>';
// render a text field
wplf_settings_text_field( [
'id' => "${my_prefix}_foo", // [name] field attr
'default' => 'bar',
// etc
] );
});
add_action( "wplf_${my_prefix}_save_settings", function () use ( $my_prefix ) {
// render a text field
if ( ! empty( $_POST["${my_prefix}_foo"] ) ) {
update_option( "${my_prefix}_foo", $_POST["${my_prefix}_foo"] );
}
});
So we can recommend all plugin creators to use our Settings API to avoid having multiple settings pages in wp-admin.
We're already "recommending" authors to use wplf()->plugins->register()
, so they won't have to pollute the menu with useless options pages. How said authors save data doesn't concern us. Some may want to use post_meta, and someone else might need to use custom tables or wp_options.
We're already "recommending" authors to use
wplf()->plugins->register()
, so they won't have to pollute the menu with useless options pages. How said authors save data doesn't concern us. Some may want to use post_meta, and someone else might need to use custom tables or wp_options.
Oh sorry. I thought every author had to create his settings page if he used wplf()->plugins->register()
.
A global settings page for WP Libre Form it will be a good idea now that we have a plugins section. So all plugins can add their settings on this single page.
Optional: a simple settings api to easily add new fields.