Making WordPress.org

Changeset 13548


Ignore:
Timestamp:
04/17/2024 06:10:21 AM (2 months ago)
Author:
dd32
Message:

Support Forums: Blocks: When editing a reply/thread that was created pre-block editor, but now has a block editor, load the block editor upon save.

This fixes edits of old reviews showing block HTML, as old reviews can be edited in the new block editor.

See #6608, #7593.

File:
1 edited

Legend:

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

    r12569 r13548  
    277277
    278278        if ( $use_it ) {
    279             $reply_id = bbp_is_reply_edit() ? bbp_get_reply_id() : ( ( bbp_is_post_request() && ! empty( $_POST['action'] ) && 'bbp-edit-reply' === $_POST['action'] ) ? $_POST['bbp_reply_id'] : 0 );
    280             $topic_id = bbp_is_topic_edit() ? bbp_get_topic_id() : ( ( bbp_is_post_request() && ! empty( $_POST['action'] ) && 'bbp-edit-topic' === $_POST['action'] ) ? $_POST['bbp_topic_id'] : 0 );
    281 
    282             // If we're editing a post made without the editor, let's respect that.
    283             if ( $reply_id ) {
    284                 $reply = bbp_get_reply( $reply_id );
    285 
    286                 if ( $reply && ! has_blocks( $reply->post_content ) ) {
    287                     $use_it = false;
    288                 }
    289             } elseif ( $topic_id ) {
    290                 if ( ! has_blocks( get_post_field( 'post_content', $topic_id ) ) ) {
     279            $content = false;
     280
     281            if ( bbp_is_reply_edit() ) {
     282                $content = bbp_get_reply( bbp_get_reply_id() )->post_content;
     283            } elseif ( bbp_is_topic_edit() ) {
     284                $content = get_post_field( 'post_content', bbp_get_topic_id() );
     285            } elseif ( 'bbp-edit-reply' === $_POST['action'] ?? '' ) {
     286                $content = wp_unslash( $_POST['bbp_reply_content'] ?? '' ) ?: bbp_get_reply( $_POST['bbp_reply_id'] ?? 0 )->post_content;
     287            } elseif ( 'bbp-edit-topic' === $_POST['action'] ?? '' ) {
     288                $content = wp_unslash( $_POST['bbp_topic_content'] ?? '' ) ?: get_post_field( 'post_content', $_POST['bbp_topic_id'] );
     289            }
     290
     291            if ( $content ) {
     292                // Similar to has_blocks(), but optimized for forum use.
     293                $content = trim( $content );
     294                if ( ! str_starts_with( $content, '<!-- wp:' ) || ! str_ends_with( $content, '-->' ) ) {
    291295                    $use_it = false;
    292296                }
Note: See TracChangeset for help on using the changeset viewer.