fbpatch v0.2.2 patch for dates

This commit is contained in:
asus
2024-04-24 00:28:25 +02:00
parent 343f34a15a
commit 24afcffae4
3 changed files with 207 additions and 178 deletions

View File

@@ -45,7 +45,7 @@ class Fbpatch {
private static $_patches = [
'_name'=>'fbpatch_list_of_patches',
'dates' => ['checked'=>true, 'title'=>'dates', 'description'=>"gerer des dates pour acf dans n'importe quels formats"],
'dates' => ['checked'=>true, 'title'=>'dates', 'description'=>"gerer des dates pour acf dans n'importe quels formats (fonctionne bien pour divi, pas certain pour d'autres plugins)"],
'calculations'=> ['checked'=>true, 'title'=>'calculations', 'description'=>"afficher le total des calculs dès l'ouverture des formulaires"],
'hide_show' => ['checked'=>true, 'title'=>'masquer les offres', 'description'=>"permettre de masquer les offres en editant un formulaire, sans les supprimer"],
'modals' => ['checked'=>false, 'title'=>'modals', 'description'=>"permettre plusieurs modals sur une meme page"],
@@ -208,6 +208,104 @@ class Fbpatch {
}
/*
* ---------------------------------------------------------------------------
* DATES
* stores the real dates in the database
*
*/
private static $dates_option = 'dfb_acf_dates_option';
/*
* stores acf dates by post_id
*
*/
public static function update_acf_date($post_id, $acf_key, $acf_date) {
if (empty($acf_date)) {
return;
}
$dates = get_option(self::$dates_option);
/*
* if option does not exists, add it with its first value
*
*/
if ($dates === false) {
$dates[$post_id] = array($acf_key => $acf_date);
add_option(self::$dates_option, $dates, '', false);
return;
}
/*
* if the option does not contains key for this post_id, add it
*
*/
if (!isset($dates[$post_id])) {
$dates[$post_id] = array($acf_key => $acf_date);
update_option(self::$dates_option, $dates, false);
return;
}
/*
* if the post_id dont contains this acf field yet just add it
*
*/
if (!isset($dates[$post_id][$acf_key])) {
$dates[$post_id][$acf_key] = $acf_date;
update_option(self::$dates_option, $dates, false);
return;
}
/*
* if the acf_key already exists,
* only update option if it is different
*
*/
if ($dates[$post_id][$acf_key] !== $acf_date) {
$dates[$post_id][$acf_key] = $acf_date;
update_option(self::$dates_option, $dates, false);
return;
}
}
/*
* if acf_date exists for this acf field, use it instead of the value
* return the date in acf format 'Ymd' or false if doesnt exists
*
*/
public static function get_acf_date($post_id, $acf_key) {
$dates = get_option(self::$dates_option);
if ($dates === false) {
return false;
}
if (!isset($dates[$post_id])) {
return false;
}
if (!isset($dates[$post_id][$acf_key])) {
return false;
}
/*
* returns the date, or false if is empty
*
*/
$date = $dates[$post_id][$acf_key];
if (empty($date)) {
return false;
}
return $date;
}
}