Making WordPress.org

Changeset 8782


Ignore:
Timestamp:
05/13/2019 03:26:41 PM (5 years ago)
Author:
coffee2code
Message:

Developer: Fix unwarranted HTML entity encoding within code shortcodes of Block Editor handbook pages.

See #4388.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/import-block-editor.php

    r8765 r8782  
    1919        add_filter( 'wporg_markdown_after_transform',  array( $this, 'wporg_markdown_after_transform' ), 10, 2 );
    2020
     21        add_filter( 'the_content',                     array( $this, 'fix_code_entity_encoding' ), 6 );
     22
    2123        add_action( 'pre_post_update', function( $post_id, $data ) {
    2224            if ( $this->get_post_type() === $data['post_type'] ) {
     
    5961
    6062        return $display;
     63    }
     64
     65    /**
     66     * Fixes unwarranted HTML entity encoding within code shortcodes.
     67     *
     68     * @param string $content Post content.
     69     * @return string
     70     */
     71    public function fix_code_entity_encoding( $content ) {
     72        if ( $this->get_post_type() !== get_post_type() ) {
     73            return $content;
     74        }
     75
     76        if ( false !== mb_strpos( $content, '[code' ) ) {
     77            $content = preg_replace_callback(
     78                '|(\[code[^\]]*\])(.+)(\[\/code\])|Us',
     79                function( $matches ) {
     80                    return $matches[1] . html_entity_decode( $matches[2], ENT_QUOTES | ENT_HTML401 ) . $matches[3];
     81                },
     82                $content
     83            );
     84        }
     85
     86        return $content;
    6187    }
    6288
Note: See TracChangeset for help on using the changeset viewer.