From f882caf850515a3813ccca0ac360b560b392454b Mon Sep 17 00:00:00 2001 From: asus Date: Sun, 24 Mar 2024 15:05:00 +0100 Subject: [PATCH] option list update with form --- plugins/fbpatch/menu/menu_content.php | 17 ++++++++++++- plugins/fbpatch/php/fbpatch_class.php | 36 +++++++++++++++++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/plugins/fbpatch/menu/menu_content.php b/plugins/fbpatch/menu/menu_content.php index a2d76cd..7703e09 100644 --- a/plugins/fbpatch/menu/menu_content.php +++ b/plugins/fbpatch/menu/menu_content.php @@ -44,8 +44,23 @@ function patches_choice() { /* * * +[24-Mar-2024 12:24:08 UTC] -> _POST { + "action":"add_patches", + "nonce_name":"7eeb560dc0", + "_wp_http_referer":"\/wp-admin\/admin.php?page=fbpatch-plugin", + "hide_show":"on" +} */ - + error_log("-> _POST: " . json_encode($_POST)); + $pathes_on = array(); + foreach($_POST as $key => $value) { + if ($value !== 'on') { + continue; + } + $pathes_on[] = $key; + } + error_log("-> pathes_update: " . json_encode($pathes_on)); + Fbpatch::set_patches($pathes_on); \FBPATCH\redirect_menu_referer($_POST); } diff --git a/plugins/fbpatch/php/fbpatch_class.php b/plugins/fbpatch/php/fbpatch_class.php index d95e5e5..4f2890b 100644 --- a/plugins/fbpatch/php/fbpatch_class.php +++ b/plugins/fbpatch/php/fbpatch_class.php @@ -24,21 +24,19 @@ class Fbpatch { private static $_patches = [ '_name'=>'fbpatch_list_of_patches', - 'calculations'=>['checked'=>'false', 'title'=>'calculations title', 'description'=>'calculation description'], - 'hide_show'=>['checked'=>'false', 'title'=>'hide/show title', 'description'=>'hide/show description'], + 'calculations'=>['checked'=>false, 'title'=>'calculations title', 'description'=>'calculation description'], + 'hide_show'=>['checked'=>false, 'title'=>'hide/show title', 'description'=>'hide/show description'], ]; //private static $_patches = ['_name'=>'fbpatch_list_of_patches', 'hide_show']; //private static $_patches = ['_name'=>'fbpatch_list_of_patches']; private static function set_option_patches() { - error_log("---"); /* * get the list of patches in option * create option if needed * */ $raw_patches_option = get_option(self::$_patches['_name']); - error_log("raw_patches_option: " . json_encode($raw_patches_option)); if (false === $raw_patches_option) { add_option(self::$_patches['_name']); } @@ -51,7 +49,6 @@ class Fbpatch { * if the option miss patches, add them * */ - error_log("patches_option before 1: " . json_encode($patches_option)); foreach (self::$_patches as $patch => $data) { if ($patch === '_name') { continue; @@ -61,29 +58,24 @@ class Fbpatch { } $patches_option[$patch] = $data; } - error_log("patches_option after 1: " . json_encode($patches_option)); /* * if the option has additional patches, delete them * */ - error_log("patches_option before 2: " . json_encode($patches_option)); foreach ($patches_option as $patch => $data) { if (isset(self::$_patches[$patch])) { continue; } unset($patches_option[$patch]); } - error_log("patches_option after 2: " . json_encode($patches_option)); /* * change the option list with the update patches * */ ksort($patches_option); - error_log("ksorted patches_option: " . json_encode($patches_option)); $serialize_patches_option = serialize($patches_option); - error_log("serialize patches_option: " . json_encode($serialize_patches_option)); update_option(self::$_patches['_name'], $serialize_patches_option); } public static function get_patches() { @@ -91,7 +83,29 @@ class Fbpatch { $patches = get_option(self::$_patches['_name']); return unserialize($patches); } - public static function set_patchs($query) { + public static function set_patches($patches_on) { + /* + * loop through the option list and update occording to the received list + * + */ + $raw_patches = get_option(self::$_patches['_name']); + $patches_option = unserialize($raw_patches); + foreach($patches_option as $patch => $data) { + if (in_array($patch, $patches_on)) { + $patches_option[$patch]['checked'] = true; + } + else { + $patches_option[$patch]['checked'] = false; + } + } + + /* + * change the option list with the update patches + * + */ + ksort($patches_option); + $serialize_patches_option = serialize($patches_option); + update_option(self::$_patches['_name'], $serialize_patches_option); } }