Making WordPress.org


Ignore:
Timestamp:
12/16/2022 04:55:38 AM (17 months ago)
Author:
dd32
Message:

Support Forums: Blocks: Store emoji's as emojis, not as img.emoji.

This allows emojis to be rendered by the viewer, rather than the conversions being based on the posters browser support.

See #6608.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-blocks.php

    r12340 r12341  
    5454
    5555        // Implement Blocks-no-empty-replies.
    56         add_filter( 'bbp_new_reply_pre_content', [ $this, 'bbp_new_reply_pre_content' ] );
     56        add_filter( 'bbp_new_reply_pre_content', [ $this, 'no_empty_block_replies' ] );
     57        add_filter( 'bbp_new_topic_pre_content', [ $this, 'no_empty_block_replies' ] );
     58
     59        // Reverse twemoji replacements. Before bbPress sanitization gets to it.
     60        add_filter( 'bbp_new_reply_pre_content', [ $this, 'reverse_twemoji_upon_save' ], 5 );
     61        add_filter( 'bbp_new_topic_pre_content', [ $this, 'reverse_twemoji_upon_save' ], 5 );
    5762    }
    5863
     
    286291     * Don't allow empty block replies.
    287292     */
    288     public function bbp_new_reply_pre_content( $content ) {
     293    public function no_empty_block_replies( $content ) {
    289294        // Remove HTML tags.
    290295        $no_html_content = wp_strip_all_tags( $content, true );
     
    303308
    304309    /**
     310     * Reverse twemoji upon save.
     311     *
     312     * @see https://core.trac.wordpress.org/ticket/52219
     313     */
     314    public function reverse_twemoji_upon_save( $content ) {
     315        // <img ... class="emoji" alt="emojihere" ... />
     316        if ( false === str_contains( $content, 'emoji' ) ) {
     317            return $content;
     318        }
     319
     320        $content = wp_unslash( $content );
     321
     322        // Replace all img.emoji with the alt text.
     323        $content = preg_replace(
     324            '~<img[^>]+class="emoji"[^>]+alt="(.*?)"+[^>]+>~i',
     325            '$1',
     326            $content
     327        );
     328
     329        return wp_slash( $content ); // Expect slashed.
     330    }
     331
     332    /**
    305333     * Register pre-defs for the forums.
    306334     */
Note: See TracChangeset for help on using the changeset viewer.