399 lines
12 KiB
PHP
399 lines
12 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!');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* ------------------------------------------------------------------------
|
|
* 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
|
|
*
|
|
*/
|
|
//function form_partner_before_render_CIPF() {
|
|
// PLGNTLS_class::debug_infos();
|
|
//
|
|
// $cipf_form_partner = new PLGNTLS_class();
|
|
// $cipf_form_partner->add_to_front(array(
|
|
// 'css/hide_show_form_elements.css',
|
|
// ));
|
|
//}
|
|
//add_action('de_fb_before_form_render', 'form_partner_before_render_CIPF');
|
|
|
|
//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);
|
|
|
|
|
|
/*
|
|
* 4462 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/post.php
|
|
* $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;
|
|
//}
|
|
//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
|
|
* function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' )
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* 4845 : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/functions.php
|
|
* function wp_parse_args( $args, $defaults = array() )
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* strategy 2 :
|
|
*
|
|
* 1. first collect the original post to see the fields that should be empty :
|
|
* - 305 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
|
* - add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
|
* 2. then hook for each entries and check if should abort the updating of the meta data
|
|
* - 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 );
|
|
*
|
|
*
|
|
* strategy 1 : ABORTED -> we cannot prevent divi-form-builder to insert the post itself, since it needs the id in returns, and preventing returns an id of 0
|
|
*
|
|
* in divi form builder : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
|
|
* 1. first collect the original post to see the fields that should be empty :
|
|
* - 305 : add_action('df_before_process', __NAMESPACE__.'\form_partner_before_process', 10, 3);
|
|
* 2. then insert the post before divi form builder does it :
|
|
* - 506 : do_action( 'df_before_insert_post', $form_id, $post_array );
|
|
* in wp : ../../../../wordpress_docker/volumes/wp_volume/wp-includes/post.php
|
|
* 3. in wp, use a filter to check that the post is inserted by divi form builder and abort
|
|
* - 4181 : apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr )
|
|
*
|
|
*/
|
|
|
|
/*
|
|
"post_title":"test_hugo",
|
|
"ID":41586,
|
|
"_ajax_linking_nonce":"9e6b4bfea2",
|
|
|
|
|
|
before process :
|
|
{
|
|
"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":""
|
|
}
|
|
|
|
in filter maybe empty
|
|
{
|
|
"post_author":24,
|
|
"post_content":"presentation",
|
|
"post_content_filtered":"",
|
|
"post_title":"test_hugo",
|
|
"post_excerpt":"accroche",
|
|
"post_status":"publish",
|
|
"post_type":"post",
|
|
"comment_status":"",
|
|
"ping_status":"",
|
|
"post_password":"",
|
|
"to_ping":"",
|
|
"pinged":"",
|
|
"post_parent":0,
|
|
"menu_order":0,
|
|
"guid":"",
|
|
"import_id":0,
|
|
"context":"",
|
|
"post_date":"2024-03-22 22:59:57",
|
|
"post_date_gmt":"",
|
|
"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"],
|
|
"meta_input":{
|
|
"url_partenaire":"",
|
|
"_url_partenaire":"field_65cb83096d020",
|
|
"logo_partenaire":"41585",
|
|
"_logo_partenaire":"field_65cb79150ac4f",
|
|
"afficher_offre_1":"Masquer",
|
|
"_afficher_offre_1":"field_65d8cf09395a5",
|
|
"duree_offre_1":[],
|
|
"fin_offre_1":[],
|
|
"offre_1_titre":[],
|
|
"offre_1_txt":[],
|
|
"offre_1_image":"41587",
|
|
"_offre_1_image":"field_65d8bc5d5bf8b",
|
|
"afficher_offre_2":"Afficher",
|
|
"_afficher_offre_2":"field_65e20fb8785ba",
|
|
"duree_offre_2":"Permanente",
|
|
"_duree_offre_2":"field_65f3fc577fec4",
|
|
"fin_offre_2":[],
|
|
"offre_2_titre":"titre 2",
|
|
"_offre_2_titre":"field_65d8bc201740b",
|
|
"offre_2_txt":"offre 2",
|
|
"_offre_2_txt":"field_65d8bc4c5bf89",
|
|
"offre_2_image":"41588",
|
|
"_offre_2_image":"field_65d8bc6e5bf8c",
|
|
"afficher_offre_3":"Afficher",
|
|
"_afficher_offre_3":"field_65d8cf48395a6",
|
|
"duree_offre_3":"Permanente",
|
|
"_duree_offre_3":"field_65f3ff78c7ffd",
|
|
"fin_offre_3":[],
|
|
"offre_3_titre":"titre 3",
|
|
"_offre_3_titre":"field_65d8bc2e644ab",
|
|
"offre_3_txt":"offre 3",
|
|
"_offre_3_txt":"field_65d8bc545bf8a",
|
|
"offre_3_image":"41589",
|
|
"_offre_3_image":"field_65d8bc8c5bf8e"
|
|
},
|
|
"tax_input":{"category":[1]},
|
|
"_ajax_linking_nonce":"9e6b4bfea2",
|
|
"post_thumbnail":"41584",
|
|
"post_name":"test_hugo",
|
|
"ID":41586,
|
|
"form_type_confirm":"",
|
|
"filter":"db"
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
?>
|
|
|