103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
namespace FBPATCH;
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
*
|
|
*/
|
|
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 $_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'],
|
|
];
|
|
//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']);
|
|
}
|
|
$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 $patch => $data) {
|
|
if ($patch === '_name') {
|
|
continue;
|
|
}
|
|
if (isset($patches_option[$patch])) {
|
|
continue;
|
|
}
|
|
$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() {
|
|
self::set_option_patches();
|
|
$patches = get_option(self::$_patches['_name']);
|
|
return unserialize($patches);
|
|
}
|
|
public static function set_patchs($query) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|