From 15a61e59746d138d9386d4ef1df4e0d9961b1774 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 13 Jul 2019 10:44:44 +0200 Subject: [PATCH] Add the new hook save_plugin_parameters to the demo plugin --- plugins/demo_plugin/demo_plugin.meta | 3 +++ plugins/demo_plugin/demo_plugin.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/plugins/demo_plugin/demo_plugin.meta b/plugins/demo_plugin/demo_plugin.meta index b063ecb..cd61644 100644 --- a/plugins/demo_plugin/demo_plugin.meta +++ b/plugins/demo_plugin/demo_plugin.meta @@ -1 +1,4 @@ description="A demo plugin covering all use cases for template designers and plugin developers." +parameters="DEMO_PLUGIN_PARAMETER;DEMO_PLUGIN_OTHER_PARAMETER" +parameter.DEMO_PLUGIN_PARAMETER="This is a parameter dedicated to the demo plugin. It'll be suffixed." +parameter.DEMO_PLUGIN_OTHER_PARAMETER="Other demo parameter" diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 95ea7fe..71ba749 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -456,6 +456,23 @@ function hook_demo_plugin_render_feed($data) return $data; } +/** + * When plugin parameters are saved. + * + * @param array $data $_POST array + * + * @return array Updated $_POST array + */ +function hook_demo_plugin_save_plugin_parameters($data) +{ + // Here we edit the provided value, but we can use this to generate config files, etc. + if (! empty($data['DEMO_PLUGIN_PARAMETER']) && ! endsWith($data['DEMO_PLUGIN_PARAMETER'], '_SUFFIX')) { + $data['DEMO_PLUGIN_PARAMETER'] .= '_SUFFIX'; + } + + return $data; +} + /** * This function is never called, but contains translation calls for GNU gettext extraction. */ @@ -463,4 +480,6 @@ function demo_dummy_translation() { // meta t('A demo plugin covering all use cases for template designers and plugin developers.'); + t('This is a parameter dedicated to the demo plugin. It\'ll be suffixed.'); + t('Other demo parameter'); }