wip first strategy to overwrite the formbuilder post update is a dead end
This commit is contained in:
@@ -21,16 +21,10 @@ class Fbpatch {
|
||||
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'=>true, 'title'=>'calculations title', 'description'=>'calculation description'],
|
||||
'hide_show' =>['checked'=>true, 'title'=>'hide/show title', 'description'=>'hide/show description'],
|
||||
'modals' =>['checked'=>false, 'title'=>'modals title', 'description'=>'modals description'],
|
||||
'urls' =>['checked'=>false, 'title'=>'urls title', 'description'=>'urls description'],
|
||||
];
|
||||
//private static $_patches = ['_name'=>'fbpatch_list_of_patches', 'hide_show'];
|
||||
//private static $_patches = ['_name'=>'fbpatch_list_of_patches'];
|
||||
|
||||
/*
|
||||
* get path an url from plugin root
|
||||
*
|
||||
*/
|
||||
public static function root_path() {
|
||||
return plugin_dir_path(__DIR__);
|
||||
}
|
||||
@@ -39,6 +33,23 @@ class Fbpatch {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
* OPTIONS
|
||||
* these functions are used to select which patch is applied
|
||||
*
|
||||
*/
|
||||
|
||||
private static $_patches = [
|
||||
'_name'=>'fbpatch_list_of_patches',
|
||||
'calculations'=>['checked'=>true, 'title'=>'calculations title', 'description'=>'calculation description'],
|
||||
'hide_show' =>['checked'=>true, 'title'=>'hide/show title', 'description'=>'hide/show description'],
|
||||
'modals' =>['checked'=>false, 'title'=>'modals title', 'description'=>'modals description'],
|
||||
'urls' =>['checked'=>false, 'title'=>'urls title', 'description'=>'urls description'],
|
||||
];
|
||||
|
||||
private static function set_option_patches() {
|
||||
/*
|
||||
* get the list of patches in option
|
||||
@@ -129,6 +140,118 @@ class Fbpatch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* OPTIONS END
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
* HIDE SHOW
|
||||
* to hide the chosen elements of the form without deleting the data in acf fields
|
||||
*
|
||||
*/
|
||||
|
||||
private static $_identification_fields = array("post_title", "ID", "_ajax_linking_nonce");
|
||||
private static $_post_array_begin = array();
|
||||
private static $_post_identification = array();
|
||||
private static $_has_post_to_overwrite = false;
|
||||
private static $_was_inserted_once = false;
|
||||
|
||||
public static function set_post_array($array) {
|
||||
self::$_post_array_begin = $array;
|
||||
self::$_post_identification = array();
|
||||
self::$_has_post_to_overwrite = true;
|
||||
self::$_was_inserted_once = false;
|
||||
}
|
||||
|
||||
public static function set_post_identification($array) {
|
||||
error_log("-in set_post_identification");
|
||||
foreach(self::$_identification_fields as $field) {
|
||||
if (!isset($array[$field])) {
|
||||
continue;
|
||||
}
|
||||
self::$_post_identification[$field] = $array[$field];
|
||||
}
|
||||
|
||||
error_log("_post_identification: " . json_encode(self::$_post_identification));
|
||||
}
|
||||
|
||||
/*
|
||||
* check if should insert post :
|
||||
* only prevent insert if the post was already inserted with divi_form_builder hook
|
||||
* so we must let the post be inserted a first time, then prevent it
|
||||
* 1. checks if there is a post to overwrite
|
||||
* 2. checks if it has the same identifications than the form_builder post
|
||||
*
|
||||
*/
|
||||
public static function should_prevent_insert($array) {
|
||||
error_log("-in should_prevent_insert");
|
||||
$is_same = false;
|
||||
if (self::$_has_post_to_overwrite === false) {
|
||||
error_log("_has_post_to_overwrite === false");
|
||||
self::$_post_identification = array();
|
||||
self::$_post_array_begin = array();;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* check if the post identifications matches the post to overwrite
|
||||
*
|
||||
*/
|
||||
foreach(self::$_post_identification as $key => $value) {
|
||||
if (!isset($array[$key])) {
|
||||
error_log("!isset array[key]");
|
||||
return false;
|
||||
}
|
||||
// some identifications are number, but might be in string format, hence '!=' instead of '!=='
|
||||
if ($array[$key] != $value) {
|
||||
error_log("array[key] != value");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* the post identify to the post to overwrite
|
||||
* so we should insert it a first time
|
||||
* then prevent it to be inserted a second time
|
||||
*
|
||||
*/
|
||||
if (self::$_was_inserted_once === false) {
|
||||
error_log("_was_inserted_once === true");
|
||||
self::$_was_inserted_once = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$_post_array_begin = array();;
|
||||
self::$_post_identification = array();
|
||||
self::$_has_post_to_overwrite = false;
|
||||
self::$_was_inserted_once = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
"post_title":"test_hugo",
|
||||
"ID":41586,
|
||||
"_ajax_linking_nonce":"9e6b4bfea2",
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* HIDE SHOW
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user