wip patches added to options

This commit is contained in:
asus
2024-03-24 12:37:38 +01:00
parent 5c93938b53
commit 94dbe05f87
3 changed files with 87 additions and 19 deletions

View File

@@ -20,24 +20,78 @@ class Fbpatch {
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_fbpatch', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide'];
const NONCE = ['_name'=>'nonce_name', '_action'=>'action_name'];
const ADMIN_POST_PATCH_CHOICE = 'add_patches';
private static $_patchs = ['calculations', 'hide_show'];
// const PATCH_CALCULATIONS = ['_name'=>'calculations', 'title'=>'calculations title', '_description'=>'description---'];
// const PATCH_HIDE_SHOW = ['_name'=>'hide_chow', '_title'=>'hide/show title', '_description'=>'description...'];
private static $_patches = ['_name'=>'fbpatch_list_of_patches', 'calculations', 'hide_show'];
//private static $_patches = ['_name'=>'fbpatch_list_of_patches', 'hide_show'];
private static function set_patchs() {
foreach (self::$_patchs as $patch) {
error_log("patch : " . $patch);
private static function set_option_patchs() {
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']);
}
$patches_option = unserialize($raw_patches_option);
if (empty($patches_option)) {
$patches_option = array();
}
/*
* if the option miss patches, add them
*
*/
error_log("patches_option before 1: " . json_encode($patches_option));
foreach (self::$_patches as $key => $patch) {
if ($key === '_name') {
continue;
}
if (isset($patches_option[$patch])) {
continue;
}
$patches_option[$patch] = false;
}
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 $key => $patch) {
if (in_array($key, self::$_patches)) {
continue;
}
unset($patches_option[$key]);
}
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_patchs() {
self::set_patchs();
self::set_option_patchs();
$patches = get_option(self::$_patches['_name']);
return serialize($patches);
}
public static function update_patchs($query) {
public static function set_patchs($query) {
}
}
?>