hide show post elements works
This commit is contained in:
@@ -159,31 +159,143 @@ class Fbpatch {
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
/*
|
||||
* STRATEGY 2
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
private static $_post_id = 0;
|
||||
private static $_has_elements_to_skip = false;
|
||||
private static $_skip_elements = array();
|
||||
|
||||
public static function is_post_id($id) {
|
||||
return self::$_post_id == $id;
|
||||
}
|
||||
public static function is_to_skip($key) {
|
||||
return in_array($key, self::$_skip_elements);
|
||||
}
|
||||
|
||||
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];
|
||||
/*
|
||||
* create an array of the elements to forget
|
||||
*
|
||||
*/
|
||||
public static function set_post_elements_to_forget($id, $is_to_skip, $skip_array) {
|
||||
self::$_post_id = $id;
|
||||
self::$_has_elements_to_skip = $is_to_skip;
|
||||
self::$_skip_elements = $skip_array;
|
||||
|
||||
error_log("self::_post_id: " . json_encode(self::$_post_id));
|
||||
error_log("self::_skip_elements: " . json_encode(self::$_skip_elements));
|
||||
}
|
||||
|
||||
/*
|
||||
* if there is elements to skip, add the filter, otherwise removes it (to be sure)
|
||||
*
|
||||
*/
|
||||
public static function init_skip_hook() {
|
||||
if (false === self::$_has_elements_to_skip) {
|
||||
remove_filter("update_post_metadata", __NAMESPACE__.'\filter_elements_to_skip');
|
||||
return;
|
||||
}
|
||||
|
||||
error_log("_post_identification: " . json_encode(self::$_post_identification));
|
||||
add_filter("update_post_metadata", __NAMESPACE__.'\filter_elements_to_skip', 10, 5);
|
||||
}
|
||||
|
||||
/*
|
||||
* after insertion finished, removes filter
|
||||
*
|
||||
*/
|
||||
public static function end_skip_hook() {
|
||||
remove_filter("update_post_metadata", __NAMESPACE__.'\filter_elements_to_skip');
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"post_status":"publish",
|
||||
"field_title":["Nom commercial","Votre site Internet","Dans quelle rubrique devez-vous para\u00eetre ? ","L\\'accroche en t\u00eate de page","Pr\u00e9sentez-vous","Votre logo ","Image principale","Voulez-vous afficher cette offre ?","Dur\u00e9e de l\\'offre","Validit\u00e9 de l\\'offre","Titre","Texte de l\\'offre","Image (facultatif)","Voulez-vous afficher cette offre ?","Dur\u00e9e de l\\'offre","Validit\u00e9 de l\\'offre","Titre","Texte de l\\'offre","Image (facultatif)","Voulez-vous afficher cette offre ?","Dur\u00e9e de l\\'offre","Validit\u00e9 de l\\'offre","Titre","Texte de l\\'offre","Image (facultatif)","slug"],
|
||||
"post_title":"test_hugo",
|
||||
"meta_input":[
|
||||
"de_fb_url_partenaire",
|
||||
"de_fb_logo_partenaire",
|
||||
"de_fb_afficher_offre_1",
|
||||
"de_fb_duree_offre_1",
|
||||
"de_fb_fin_offre_1",
|
||||
"de_fb_offre_1_titre",
|
||||
"de_fb_offre_1_txt",
|
||||
"de_fb_offre_1_image",
|
||||
"de_fb_afficher_offre_2",
|
||||
"de_fb_duree_offre_2",
|
||||
"de_fb_fin_offre_2",
|
||||
"de_fb_offre_2_titre",
|
||||
"de_fb_offre_2_txt",
|
||||
"de_fb_offre_2_image",
|
||||
"de_fb_afficher_offre_3",
|
||||
"de_fb_duree_offre_3",
|
||||
"de_fb_fin_offre_3",
|
||||
"de_fb_offre_3_titre",
|
||||
"de_fb_offre_3_txt",
|
||||
"de_fb_offre_3_image"
|
||||
],
|
||||
"url_partenaire":"",
|
||||
"tax_input":["de_fb_category"],
|
||||
"category":"autres",
|
||||
"post_excerpt":"accroche",
|
||||
"post_content":"presentation",
|
||||
"_ajax_linking_nonce":"9e6b4bfea2",
|
||||
"logo_partenaire":"41585",
|
||||
"post_thumbnail":"41584",
|
||||
"afficher_offre_1":"Masquer",
|
||||
"offre_1_image":"41587",
|
||||
"afficher_offre_2":"Afficher",
|
||||
"duree_offre_2":"Permanente",
|
||||
"offre_2_titre":"titre 2",
|
||||
"offre_2_txt":"offre 2",
|
||||
"offre_2_image":"41588",
|
||||
"afficher_offre_3":"Afficher",
|
||||
"duree_offre_3":"Permanente",
|
||||
"offre_3_titre":"titre 3",
|
||||
"offre_3_txt":"offre 3",
|
||||
"offre_3_image":"41589",
|
||||
"post_name":"test_hugo",
|
||||
"ID":"41586",
|
||||
"form_type_confirm":""
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* STRATEGY 1
|
||||
*
|
||||
*/
|
||||
|
||||
//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
|
||||
@@ -192,50 +304,50 @@ class Fbpatch {
|
||||
* 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;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
}
|
||||
// /*
|
||||
// * 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;
|
||||
}
|
||||
// /*
|
||||
// * 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;
|
||||
}
|
||||
// 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",
|
||||
|
||||
@@ -8,6 +8,176 @@ if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------------
|
||||
* strategy 2
|
||||
* prevent the meta data to be updated directly in the meta_post_update filter
|
||||
* because nor form_builder nor wp provides filters to modify post_array
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 305 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
function form_partner_before_process($form_id, $post_array, $form_type) {
|
||||
//error_log("post_array: " . json_encode($post_array));
|
||||
|
||||
if (is_null($post_array) || empty($post_array)) {
|
||||
//nothing to overwrite
|
||||
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||
}
|
||||
if (!isset($post_array['meta_input']) || empty($post_array['meta_input'])) {
|
||||
//nothing to overwrite
|
||||
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* creating a meta_input list without the prefix
|
||||
*
|
||||
*/
|
||||
$raw_meta_input = $post_array['meta_input'];
|
||||
$meta_input = array();
|
||||
$prefix = 'de_fb_';
|
||||
foreach($raw_meta_input as $meta) {
|
||||
if (substr($meta, 0, strlen($prefix)) === $prefix) {
|
||||
$meta_input[] = substr($meta, strlen($prefix));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* if there is meta to skip, init the variables
|
||||
*
|
||||
*/
|
||||
$to_skip = array();
|
||||
foreach($meta_input as $meta) {
|
||||
if (!isset($post_array[$meta])) {
|
||||
$to_skip[] = $meta;
|
||||
}
|
||||
}
|
||||
if (empty($to_skip)) {
|
||||
//nothing to overwrite
|
||||
return Fbpatch::set_post_elements_to_forget(0, false, array());
|
||||
}
|
||||
return Fbpatch::set_post_elements_to_forget($post_array["ID"], true, $to_skip);
|
||||
|
||||
}
|
||||
add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
||||
|
||||
/*
|
||||
* 506 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
function form_partner_before_insert($form_id, $post_array) {
|
||||
//error_log("--form_id : " . json_encode($form_id));
|
||||
//error_log("post_array : " . json_encode($post_array));
|
||||
|
||||
Fbpatch::init_skip_hook();
|
||||
}
|
||||
add_action('df_before_insert_post', __NAMESPACE__.'\form_partner_before_insert', 10, 2);
|
||||
|
||||
/*
|
||||
* 235 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/meta.php
|
||||
* $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
|
||||
* "Returning a non-null value will effectively short-circuit the function."
|
||||
*
|
||||
*/
|
||||
function filter_elements_to_skip($null, $object_id, $meta_key, $meta_value, $prev_value) {
|
||||
if (false === Fbpatch::is_post_id($object_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (false === Fbpatch::is_to_skip($meta_key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 558 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
* do_action( 'df_after_insert_post', $form_id, $post_id, $post_array );
|
||||
*
|
||||
*/
|
||||
function after_form_inserted($form_id, $post_id, $post_array) {
|
||||
//error_log("--form_id : " . json_encode($form_id));
|
||||
//error_log("post_id: " . json_encode($post_id));
|
||||
//error_log("post_array: " . json_encode($post_array));
|
||||
Fbpatch::end_skip_hook();
|
||||
}
|
||||
add_action('df_after_insert_post', '');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------------
|
||||
* strategy 1
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 305 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
//function form_partner_before_process($form_id, $post_array, $form_type) {
|
||||
// //error_log("post_array: " . json_encode($post_array));
|
||||
// Fbpatch::set_post_array($post_array);
|
||||
//}
|
||||
//add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
||||
|
||||
|
||||
/*
|
||||
* 506 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
//function form_partner_before_insert($form_id, $post_array) {
|
||||
// //error_log("--form_id : " . json_encode($form_id));
|
||||
// //error_log("post_array : " . json_encode($post_array));
|
||||
// Fbpatch::set_post_identification($post_array);
|
||||
//}
|
||||
//add_action('df_before_insert_post', __NAMESPACE__.'\form_partner_before_insert', 10, 2);
|
||||
|
||||
|
||||
/*
|
||||
* 4179 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/post.php
|
||||
*
|
||||
*/
|
||||
//function maybe_abort_insert_post($maybe_empty, $postarr) {
|
||||
// error_log("- in filter maybe empty, postarr: " . json_encode($postarr));
|
||||
// $prevent = Fbpatch::should_prevent_insert($postarr);
|
||||
// error_log("prevent: " . json_encode($prevent));
|
||||
// return false;
|
||||
//}
|
||||
//add_filter( 'wp_insert_post_empty_content', __NAMESPACE__.'\maybe_abort_insert_post', 10, 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------------------
|
||||
* researches
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 4674 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/modules/Form/Form.php
|
||||
*
|
||||
@@ -22,56 +192,13 @@ if (!defined('ABSPATH')) {
|
||||
//}
|
||||
//add_action('de_fb_before_form_render', 'form_partner_before_render_CIPF');
|
||||
|
||||
|
||||
/*
|
||||
* 305 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
function form_partner_before_process($form_id, $post_array, $form_type) {
|
||||
//error_log("post_array: " . json_encode($post_array));
|
||||
Fbpatch::set_post_array($post_array);
|
||||
}
|
||||
add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
||||
|
||||
|
||||
/*
|
||||
* 506 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
||||
*
|
||||
*/
|
||||
function form_partner_before_insert($form_id, $post_array) {
|
||||
//error_log("--form_id : " . json_encode($form_id));
|
||||
//error_log("post_array : " . json_encode($post_array));
|
||||
Fbpatch::set_post_identification($post_array);
|
||||
}
|
||||
add_action('df_before_insert_post', __NAMESPACE__.'\form_partner_before_insert', 10, 2);
|
||||
|
||||
|
||||
/*
|
||||
* 4179 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/post.php
|
||||
*
|
||||
*/
|
||||
function maybe_abort_insert_post($maybe_empty, $postarr) {
|
||||
error_log("- in filter maybe empty, postarr: " . json_encode($postarr));
|
||||
$prevent = Fbpatch::should_prevent_insert($postarr);
|
||||
error_log("prevent: " . json_encode($prevent));
|
||||
return false;
|
||||
}
|
||||
add_filter( 'wp_insert_post_empty_content', __NAMESPACE__.'\maybe_abort_insert_post', 10, 2);
|
||||
|
||||
/*
|
||||
* 235 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/meta.php
|
||||
* $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
function test_attachment_filter($data, $postarr, $unsanitized_postarr, $update) {
|
||||
error_log("-- in test_attachment_filter");
|
||||
error_log("data: " . json_encode($data));
|
||||
error_log("postarr: " . json_encode($postarr));
|
||||
error_log("unsanitized_postarr: " . json_encode($unsanitized_postarr));
|
||||
error_log("update: " . json_encode($update));
|
||||
}
|
||||
//function test_attachment_filter($data, $postarr, $unsanitized_postarr, $update) {
|
||||
// error_log("-- in test_attachment_filter");
|
||||
// error_log("data: " . json_encode($data));
|
||||
// error_log("postarr: " . json_encode($postarr));
|
||||
// error_log("unsanitized_postarr: " . json_encode($unsanitized_postarr));
|
||||
// error_log("update: " . json_encode($update));
|
||||
//}
|
||||
//add_filter( 'wp_insert_attachment_data', __NAMESPACE__.'\test_attachment_filter', 10, 4);
|
||||
|
||||
|
||||
@@ -80,17 +207,16 @@ function test_attachment_filter($data, $postarr, $unsanitized_postarr, $update)
|
||||
* $data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr, $update );
|
||||
*
|
||||
*/
|
||||
function test_post_filter($data, $postarr, $unsanitized_postarr, $update) {
|
||||
error_log("-- in test_post_filter");
|
||||
error_log("data: " . json_encode($data));
|
||||
error_log("postarr: " . json_encode($postarr));
|
||||
error_log("unsanitized_postarr: " . json_encode($unsanitized_postarr));
|
||||
error_log("update: " . json_encode($update));
|
||||
return $data;
|
||||
}
|
||||
//function test_post_filter($data, $postarr, $unsanitized_postarr, $update) {
|
||||
// error_log("-- in test_post_filter");
|
||||
// error_log("data: " . json_encode($data));
|
||||
// error_log("postarr: " . json_encode($postarr));
|
||||
// error_log("unsanitized_postarr: " . json_encode($unsanitized_postarr));
|
||||
// error_log("update: " . json_encode($update));
|
||||
// return $data;
|
||||
//}
|
||||
//add_filter('wp_insert_post_data', __NAMESPACE__.'\test_post_filter', 10, 4);
|
||||
|
||||
|
||||
/*
|
||||
* 4558 : update_post_meta( $post_id, $field, $value );
|
||||
* 2552 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/post.php
|
||||
@@ -104,6 +230,15 @@ function test_post_filter($data, $postarr, $unsanitized_postarr, $update) {
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* strategy 2 :
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user