Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andreicnegrea/e5c9d0d0b324780c5308dc873bcf3cab to your computer and use it in GitHub Desktop.

Select an option

Save andreicnegrea/e5c9d0d0b324780c5308dc873bcf3cab to your computer and use it in GitHub Desktop.

Revisions

  1. @lgladdy lgladdy revised this gist Jan 17, 2024. 1 changed file with 20 additions and 8 deletions.
    28 changes: 20 additions & 8 deletions acf_enable_detailed_escape_logging_to_php_error_log.php
    Original 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 ) {
    $value = get_field( $selector, $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 ) {
    $new_value = get_field( $selector, $post_id, true, true );
    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") {
    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 );
    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
    );
    }
  2. @lgladdy lgladdy revised this gist Jan 17, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions acf_enable_detailed_escape_logging_to_php_error_log.php
    Original 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 ) {
  3. @lgladdy lgladdy renamed this gist Jan 17, 2024. 1 changed file with 0 additions and 0 deletions.
  4. @lgladdy lgladdy revised this gist Jan 17, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions acf-always-log-post-id-and-value.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    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 ) {
    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 );
  5. @lgladdy lgladdy revised this gist Jan 17, 2024. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions acf-always-log-post-id-and-value.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    <?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 ) {
    @@ -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 );
    }
    error_log( '***ACF Debug***' . PHP_EOL .

    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 ) );
    'Escaped Value: ' . var_export( $new_value, true ) . PHP_EOL .
    'Template: '. $template );
    }
  6. @lgladdy lgladdy revised this gist Jan 17, 2024. 1 changed file with 21 additions and 5 deletions.
    26 changes: 21 additions & 5 deletions acf-always-log-post-id-and-value.php
    Original 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 ( 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 );
    }

    $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 ) );
    }
  7. @lgladdy lgladdy created this gist Jan 17, 2024.
    13 changes: 13 additions & 0 deletions acf-always-log-post-id-and-value.php
    Original 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 );
    }