From 8ebbb8bff223b83d09ad0896db1d1b320042bfdc Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 25 Mar 2024 11:17:16 +0100 Subject: [PATCH] fbpatch v 0.1.3 --- plugins/fbpatch/fbpatch.php | 3 +- plugins/fbpatch/php/fbpatch_class.php | 166 +------------ plugins/fbpatch/php/patches/hide_show.php | 281 +--------------------- 3 files changed, 5 insertions(+), 445 deletions(-) diff --git a/plugins/fbpatch/fbpatch.php b/plugins/fbpatch/fbpatch.php index 446a3a1..d78ee5c 100644 --- a/plugins/fbpatch/fbpatch.php +++ b/plugins/fbpatch/fbpatch.php @@ -4,7 +4,7 @@ Plugin Name: fbpatch_plugin Plugin URI: Description: some patchs for the form_builder plugin's bugs Author: hugogogo -Version: 0.1.2 +Version: 0.1.3 Author URI: */ @@ -23,7 +23,6 @@ include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu.php'); include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu_toggle.php'); include_once(plugin_dir_path(__FILE__) . '/menu/menu_content.php'); -//include_once(plugin_dir_path(__FILE__) . '/php/calculations.php'); \FBPATCH\Fbpatch::init_hook(); diff --git a/plugins/fbpatch/php/fbpatch_class.php b/plugins/fbpatch/php/fbpatch_class.php index 20759e6..1c55726 100644 --- a/plugins/fbpatch/php/fbpatch_class.php +++ b/plugins/fbpatch/php/fbpatch_class.php @@ -141,11 +141,8 @@ class Fbpatch { } } - /* - * - * OPTIONS END - * --------------------------------------------------------------------------- - */ + + @@ -159,11 +156,6 @@ class Fbpatch { * */ - /* - * STRATEGY 2 - * - */ - private static $_post_id = 0; private static $_has_elements_to_skip = false; private static $_skip_elements = array(); @@ -209,160 +201,6 @@ class Fbpatch { 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 - * 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 - * --------------------------------------------------------------------------- - */ - - } diff --git a/plugins/fbpatch/php/patches/hide_show.php b/plugins/fbpatch/php/patches/hide_show.php index 0672437..435f46b 100644 --- a/plugins/fbpatch/php/patches/hide_show.php +++ b/plugins/fbpatch/php/patches/hide_show.php @@ -11,14 +11,8 @@ if (!defined('ABSPATH')) { - - - - /* -* ------------------------------------------------------------------------ -* strategy 2 -* prevent the meta data to be updated directly in the meta_post_update filter +* prevents 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 * */ @@ -89,6 +83,7 @@ add_action('df_before_insert_post', __NAMESPACE__.'\form_partner_before_insert', * 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." +* filter is added in Fbpatch class * */ function filter_elements_to_skip($null, $object_id, $meta_key, $meta_value, $prev_value) { @@ -122,277 +117,5 @@ 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" -} - - - -*/ - - - ?>