option list update with form
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user