Making WordPress.org

Changeset 12340


Ignore:
Timestamp:
12/16/2022 02:50:12 AM (2 years ago)
Author:
dd32
Message:

Support Forums: Blocks: Don't allow empty block replies.

See https://wordpress.slack.com/archives/C02RQC6RW/p1671157667631789.
See #6608.

File:
1 edited

Legend:

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

    r12334 r12340  
    5252        add_action( 'admin_init', [ $this, 'admin_init' ] );
    5353        add_action( 'save_post', [ $this, 'metabox_forum_optin_save_handler' ] );
     54
     55        // Implement Blocks-no-empty-replies.
     56        add_filter( 'bbp_new_reply_pre_content', [ $this, 'bbp_new_reply_pre_content' ] );
    5457    }
    5558
     
    281284
    282285    /**
     286     * Don't allow empty block replies.
     287     */
     288    public function bbp_new_reply_pre_content( $content ) {
     289        // Remove HTML tags.
     290        $no_html_content = wp_strip_all_tags( $content, true );
     291        // Remove HTML comments (including encoded).
     292        $no_html_content = preg_replace( '@(<|&lt;)!--.*?--(>|&gt;)@i', '', $no_html_content );
     293        // Remove whitespace.
     294        $no_html_content = trim( $no_html_content );
     295
     296        if ( empty( $no_html_content ) ) {
     297            // Trigger bbPress's internal "This looks empty!" checks. See bbp_new_reply_handler().
     298            $content = '';
     299        }
     300
     301        return $content;
     302    }
     303
     304    /**
    283305     * Register pre-defs for the forums.
    284306     */
Note: See TracChangeset for help on using the changeset viewer.