Forked from lgladdy/acf_enable_detailed_escape_logging_to_php_error_log.php
Created
January 30, 2024 17:23
-
-
Save andreicnegrea/e5c9d0d0b324780c5308dc873bcf3cab to your computer and use it in GitHub Desktop.
Revisions
-
lgladdy revised this gist
Jan 17, 2024 . 1 changed file with 20 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,12 @@ add_action( 'acf/will_remove_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); add_action( 'acf/removed_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); function acf_enable_detailed_escape_logging_to_php_error_log( $function, $selector, $field_object, $post_id ) { if ( $function === 'the_sub_field' ) { $field = get_sub_field_object( $selector, true ); $value = ( is_array( $field ) && isset( $field['value'] ) ) ? $field['value'] : false; } else { $value = get_field( $selector, $post_id ); } if ( is_array( $value ) ) { $value = implode( ', ', $value ); } @@ -11,7 +16,12 @@ function acf_enable_detailed_escape_logging_to_php_error_log( $function, $select $field_type_escapes_html = acf_field_type_supports( $field_type, 'escaping_html' ); if ( $field_type_escapes_html ) { if ( $function === 'the_sub_field' ) { $field = get_sub_field_object( $selector, true, true, true ); $new_value = ( is_array( $field ) && isset( $field['value'] ) ) ? $field['value'] : false; } else { $new_value = get_field( $selector, $post_id, true, true ); } if ( is_array( $new_value ) ) { $new_value = implode( ', ', $new_value ); } @@ -23,15 +33,17 @@ function acf_enable_detailed_escape_logging_to_php_error_log( $function, $select $post_id = acf_get_valid_post_id( $post_id ); } if ( $function === 'acf_shortcode' ) { $template = get_page_template() . ' (likely not relevant for shortcode)'; } else { $template = get_page_template(); } error_log( '***ACF HTML Escaping Debug***' . PHP_EOL . 'HTML modification detected the value of ' . $selector . ' on post ID ' . $post_id . ' via ' . $function . PHP_EOL . 'Raw Value: ' . var_export( $value, true ) . PHP_EOL . 'Escaped Value: ' . var_export( $new_value, true ) . PHP_EOL . 'Template: ' . $template ); } -
lgladdy revised this gist
Jan 17, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php add_action( 'acf/will_remove_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); add_action( 'acf/removed_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); function acf_enable_detailed_escape_logging_to_php_error_log( $function, $selector, $field_object, $post_id ) { -
lgladdy renamed this gist
Jan 17, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
lgladdy revised this gist
Jan 17, 2024 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ add_action( 'acf/will_remove_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); add_action( 'acf/removed_unsafe_html', 'acf_enable_detailed_escape_logging_to_php_error_log', 10, 4 ); function acf_enable_detailed_escape_logging_to_php_error_log( $function, $selector, $field_object, $post_id ) { $value = get_field( $selector, $post_id ); if ( is_array( $value ) ) { $value = implode( ', ', $value ); -
lgladdy revised this gist
Jan 17, 2024 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ add_action( 'acf/will_remove_unsafe_html', 'always_log_post_id', 10, 4 ); add_action( 'acf/removed_unsafe_html', 'always_log_post_id', 10, 4 ); function always_log_post_id( $function, $selector, $field_object, $post_id ) { @@ -22,8 +21,16 @@ function always_log_post_id( $function, $selector, $field_object, $post_id ) { if ( empty( $post_id ) ) { $post_id = acf_get_valid_post_id( $post_id ); } if ($function === "acf_shortcode") { $template = get_page_template() . ' (likely not relevant for shortcode)'; } else { $template = get_page_template(); } error_log( '***ACF HTML Escaping Debug***' . PHP_EOL . 'HTML modification detected the value of ' . $selector . ' on post ID ' . $post_id . ' via ' . $function . PHP_EOL . 'Raw Value: ' . var_export( $value, true ) . PHP_EOL . 'Escaped Value: ' . var_export( $new_value, true ) . PHP_EOL . 'Template: '. $template ); } -
lgladdy revised this gist
Jan 17, 2024 . 1 changed file with 21 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,27 @@ add_action( 'acf/removed_unsafe_html', 'always_log_post_id', 10, 4 ); function always_log_post_id( $function, $selector, $field_object, $post_id ) { $value = get_field( $selector, $post_id ); if ( is_array( $value ) ) { $value = implode( ', ', $value ); } $field_type = is_array( $field_object ) && isset( $field_object['type'] ) ? $field_object['type'] : 'text'; $field_type_escapes_html = acf_field_type_supports( $field_type, 'escaping_html' ); if ( $field_type_escapes_html ) { $new_value = get_field( $selector, $post_id, true, true ); if ( is_array( $new_value ) ) { $new_value = implode( ', ', $new_value ); } } else { $new_value = acf_esc_html( $value ); } if ( empty( $post_id ) ) { $post_id = acf_get_valid_post_id( $post_id ); } error_log( '***ACF Debug***' . PHP_EOL . 'HTML modification detected the value of ' . $selector . ' on post ID ' . $post_id . ' via ' . $function . PHP_EOL . 'Raw Value: ' . var_export( $value, true ) . PHP_EOL . 'Escaped Value: ' . var_export( $new_value, true ) ); } -
lgladdy created this gist
Jan 17, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <?php add_action( 'acf/will_remove_unsafe_html', 'always_log_post_id', 10, 4 ); add_action( 'acf/removed_unsafe_html', 'always_log_post_id', 10, 4 ); function always_log_post_id( $function, $selector, $field_object, $post_id ) { $value = get_field( $selector, $post_id ); if ( empty( $post_id ) ) { $post_id = acf_get_valid_post_id( $post_id ); } if ( is_array( $value ) ) { $value = implode( ', ', $value ); } error_log( 'ACF Debug: HTML modification detected the value of ' . $selector . ' on post ID ' . $post_id . ' via ' . $function . ': ' . $value ); }