Skip to:
Content

bbPress.org

Changeset 7334


Ignore:
Timestamp:
07/02/2025 02:47:24 PM (10 months ago)
Author:
johnjamesjacoby
Message:

Tools - Warnings/Notices: begin phasing out of utf8_encode() for PHP 8.2 and higher.

This change moves the existing utf8_encode() usages into a new common formatting function: bbp_format_user_display_name(), and uses this new function to abstract & encapsulate checking that mbstring equivalents are loaded & supported.

Props philipjohn.

In branches/2.6, for 2.6.14.

Fixes #3585.

Location:
branches/2.6/src/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/common/formatting.php

    r7159 r7334  
    783783    return $reason;
    784784}
     785
     786/** Users *********************************************************************/
     787
     788/**
     789 * Format the display name of a user.
     790 *
     791 * Abstracts mbstring library check and fallback to utf8_encode().
     792 *
     793 * @link https://bbpress.trac.wordpress.org/ticket/2141
     794 *
     795 * @since 2.6.14
     796 *
     797 * @param string $display_name The author display
     798 * @return string
     799 */
     800function bbp_format_user_display_name( $display_name = '' ) {
     801
     802    // Default return value
     803    $retval = $display_name;
     804
     805    // Use the mbstring library if possible
     806    if ( function_exists( 'mb_check_encoding' ) && ! mb_check_encoding( $display_name, 'UTF-8' ) ) {
     807        $retval = mb_convert_encoding( $display_name, 'UTF-8', 'ISO-8859-1' );
     808
     809    // Fallback to function that (deprecated in PHP8.2)
     810    } elseif ( seems_utf8( $display_name ) === false ) {
     811        $retval = utf8_encode( $display_name );
     812    }
     813
     814    // Return
     815    return $retval;
     816}
  • branches/2.6/src/includes/core/filters.php

    r7234 r7334  
    306306
    307307// Topic and reply author display names
    308 add_filter( 'bbp_get_topic_author_display_name', 'wptexturize'   );
    309 add_filter( 'bbp_get_topic_author_display_name', 'convert_chars' );
    310 add_filter( 'bbp_get_topic_author_display_name', 'esc_html'      );
    311 add_filter( 'bbp_get_reply_author_display_name', 'wptexturize'   );
    312 add_filter( 'bbp_get_reply_author_display_name', 'convert_chars' );
    313 add_filter( 'bbp_get_reply_author_display_name', 'esc_html'      );
     308add_filter( 'bbp_get_topic_author_display_name', 'bbp_format_user_display_name' );
     309add_filter( 'bbp_get_topic_author_display_name', 'wptexturize'                  );
     310add_filter( 'bbp_get_topic_author_display_name', 'convert_chars'                );
     311add_filter( 'bbp_get_topic_author_display_name', 'esc_html'                     );
     312add_filter( 'bbp_get_reply_author_display_name', 'bbp_format_user_display_name' );
     313add_filter( 'bbp_get_reply_author_display_name', 'wptexturize'                  );
     314add_filter( 'bbp_get_reply_author_display_name', 'convert_chars'                );
     315add_filter( 'bbp_get_reply_author_display_name', 'esc_html'                     );
    314316
    315317/**
  • branches/2.6/src/includes/replies/template.php

    r7323 r7334  
    10991099        }
    11001100
    1101         // Encode possible UTF8 display names
    1102         if ( seems_utf8( $author_name ) === false ) {
    1103             $author_name = utf8_encode( $author_name );
    1104         }
    1105 
    11061101        // Filter & return
    11071102        return apply_filters( 'bbp_get_reply_author_display_name', $author_name, $reply_id );
  • branches/2.6/src/includes/topics/template.php

    r7254 r7334  
    13321332        }
    13331333
    1334         // Encode possible UTF8 display names
    1335         if ( seems_utf8( $author_name ) === false ) {
    1336             $author_name = utf8_encode( $author_name );
    1337         }
    1338 
    13391334        // Filter & return
    13401335        return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id );
Note: See TracChangeset for help on using the changeset viewer.