Make WordPress Core

Ticket #29810: miqro-29810.2.patch

File miqro-29810.2.patch, 17.2 KB (added by miqrogroove, 10 years ago)
  • src/wp-admin/import.php

     
    7979<table class="widefat importers">
    8080
    8181<?php
     82        disable_shortcodes();
    8283        $alt = '';
    8384        foreach ($importers as $importer_id => $data) {
    8485                $action = '';
     
    115116                                <td class='desc'>{$data[1]}</td>
    116117                        </tr>";
    117118        }
     119        enable_shortcodes();
    118120?>
    119121
    120122</table>
  • src/wp-admin/includes/plugin.php

     
    165165                if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] )
    166166                        $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
    167167
     168                disable_shortcodes();
    168169                $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
     170                enable_shortcodes();
    169171
    170172                if ( $plugin_data['Author'] )
    171173                        $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>';
  • src/wp-admin/menu-header.php

     
    4646function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
    4747        global $self, $parent_file, $submenu_file, $plugin_page, $typenow;
    4848
     49        disable_shortcodes();
     50       
    4951        $first = true;
    5052        // 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes, 5 = hookname, 6 = icon_url
    5153        foreach ( $menu as $key => $item ) {
     
    204206        echo '<li id="collapse-menu" class="hide-if-no-js"><div id="collapse-button"><div></div></div>';
    205207        echo '<span>' . esc_html__( 'Collapse menu' ) . '</span>';
    206208        echo '</li>';
     209       
     210        enable_shortcodes();
    207211}
    208212
    209213?>
  • src/wp-includes/class-wp-theme.php

     
    658658                                        $value = $this->get_stylesheet();
    659659                                break;
    660660                        case 'Description' :
     661                                disable_shortcodes();
    661662                                $value = wptexturize( $value );
     663                                enable_shortcodes();
    662664                                break;
    663665                        case 'Author' :
    664666                                if ( $this->get('AuthorURI') ) {
  • src/wp-includes/comment-template.php

     
    963963        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
    964964                return;
    965965        }
     966       
     967        disable_shortcodes();
    966968
    967969        echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    968970                        xmlns:dc="http://purl.org/dc/elements/1.1/"
     
    976978        echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
    977979        echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
    978980        echo '</rdf:RDF>';
     981       
     982        enable_shortcodes();
    979983}
    980984
    981985/**
  • src/wp-includes/default-filters.php

     
    9292
    9393// Format strings for display.
    9494foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) {
    95         add_filter( $filter, 'wptexturize'   );
    96         add_filter( $filter, 'convert_chars' );
    97         add_filter( $filter, 'esc_html'      );
     95        add_filter( $filter, 'restrict_shortcodes', 8 );
     96        add_filter( $filter, 'wptexturize'            );
     97        add_filter( $filter, 'convert_chars'          );
     98        add_filter( $filter, 'esc_html'               );
     99        add_filter( $filter, 'enable_shortcodes',  12 );
    98100}
    99101
    100102// Format WordPress
     
    104106
    105107// Format titles
    106108foreach ( array( 'single_post_title', 'single_cat_title', 'single_tag_title', 'single_month_title', 'nav_menu_attr_title', 'nav_menu_description' ) as $filter ) {
    107         add_filter( $filter, 'wptexturize' );
    108         add_filter( $filter, 'strip_tags'  );
     109        add_filter( $filter, 'restrict_shortcodes', 8 );
     110        add_filter( $filter, 'wptexturize'            );
     111        add_filter( $filter, 'strip_tags'             );
     112        add_filter( $filter, 'enable_shortcodes',  12 );
    109113}
    110114
    111115// Format text area for display.
    112116foreach ( array( 'term_description' ) as $filter ) {
    113         add_filter( $filter, 'wptexturize'      );
    114         add_filter( $filter, 'convert_chars'    );
    115         add_filter( $filter, 'wpautop'          );
    116         add_filter( $filter, 'shortcode_unautop');
     117        add_filter( $filter, 'restrict_shortcodes', 8 );
     118        add_filter( $filter, 'wptexturize'            );
     119        add_filter( $filter, 'convert_chars'          );
     120        add_filter( $filter, 'wpautop'                );
     121        add_filter( $filter, 'shortcode_unautop'      );
     122        add_filter( $filter, 'enable_shortcodes',  12 );
    117123}
    118124
    119125// Format for RSS
     
    124130add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
    125131
    126132// Display filters
    127 add_filter( 'the_title', 'wptexturize'   );
    128 add_filter( 'the_title', 'convert_chars' );
    129 add_filter( 'the_title', 'trim'          );
     133add_filter( 'the_title', 'restrict_shortcodes', 8 );
     134add_filter( 'the_title', 'wptexturize'            );
     135add_filter( 'the_title', 'convert_chars'          );
     136add_filter( 'the_title', 'trim'                   );
     137add_filter( 'the_title', 'enable_shortcodes',  12 );
    130138
    131139add_filter( 'the_content', 'wptexturize'        );
    132140add_filter( 'the_content', 'convert_smilies'    );
     
    135143add_filter( 'the_content', 'shortcode_unautop'  );
    136144add_filter( 'the_content', 'prepend_attachment' );
    137145
    138 add_filter( 'the_excerpt',     'wptexturize'      );
    139 add_filter( 'the_excerpt',     'convert_smilies'  );
    140 add_filter( 'the_excerpt',     'convert_chars'    );
    141 add_filter( 'the_excerpt',     'wpautop'          );
    142 add_filter( 'the_excerpt',     'shortcode_unautop');
     146add_filter( 'the_excerpt', 'restrict_shortcodes', 8 );
     147add_filter( 'the_excerpt', 'wptexturize'            );
     148add_filter( 'the_excerpt', 'convert_smilies'        );
     149add_filter( 'the_excerpt', 'convert_chars'          );
     150add_filter( 'the_excerpt', 'wpautop'                );
     151add_filter( 'the_excerpt', 'shortcode_unautop'      );
     152add_filter( 'the_excerpt', 'enable_shortcodes',  12 );
     153
    143154add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
    144155
     156add_filter( 'comment_text', 'restrict_shortcodes', 8 );
    145157add_filter( 'comment_text', 'wptexturize'            );
    146158add_filter( 'comment_text', 'convert_chars'          );
    147159add_filter( 'comment_text', 'make_clickable',      9 );
     160add_filter( 'comment_text', 'enable_shortcodes',  12 );
    148161add_filter( 'comment_text', 'force_balance_tags', 25 );
    149162add_filter( 'comment_text', 'convert_smilies',    20 );
    150163add_filter( 'comment_text', 'wpautop',            30 );
     
    151164
    152165add_filter( 'comment_excerpt', 'convert_chars' );
    153166
    154 add_filter( 'list_cats',         'wptexturize' );
     167add_filter( 'list_cats', 'restrict_shortcodes', 8 );
     168add_filter( 'list_cats', 'wptexturize'            );
     169add_filter( 'list_cats', 'enable_shortcodes',  12 );
    155170
    156171add_filter( 'wp_sprintf', 'wp_sprintf_l', 10, 2 );
    157172
  • src/wp-includes/formatting.php

     
    2828 * @return string The string replaced with html entities
    2929 */
    3030function wptexturize($text, $reset = false) {
    31         global $wp_cockneyreplace;
     31        global $wp_cockneyreplace, $shortcode_enabled;
    3232        static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
    3333                $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true;
    3434
     
    203203        $no_texturize_tags_stack = array();
    204204        $no_texturize_shortcodes_stack = array();
    205205
     206        $find_shortcodes = false;
     207        $html = '';
     208       
     209        if ( 'false' !== $shortcode_enabled ) {
     210                if ( 'restricted' === $shortcode_enabled ) {
     211                        // Shortcodes in this $text are not allowed to contain raw HTML.
     212                        $html = '<>';
     213                }
     214                $pos = strpos( $text, '[' );
     215                if ( false !== $pos ) {
     216                        if ( false !== strpos( $text, ']', $pos ) ) {
     217                                $find_shortcodes = true;
     218                        }
     219                }
     220        }
     221       
    206222        // Look for shortcodes and HTML elements.
    207223
    208224        $comment_regex =
    209                         '!'                             // Start of comment, after the <.
    210                 .       '(?:'                   // Unroll the loop: Consume everything until --> is found.
    211                 .               '-(?!->)'       // Dash not followed by end of comment.
    212                 .               '[^\-]*+'       // Consume non-dashes.
    213                 .       ')*+'                   // Loop possessively.
    214                 .       '(?:-->)?';             // End of comment. If not found, match all input.
    215        
     225                  '!'                // Start of comment, after the <.
     226                . '(?:'              // Unroll the loop: Consume everything until --> is found.
     227                .     '-(?!->)'      // Dash not followed by end of comment.
     228                .     '[^\-]*+'      // Consume non-dashes.
     229                . ')*+'              // Loop possessively.
     230                . '(?:-->)?';        // End of comment. If not found, match all input.
     231
     232        $html_regex =
     233                  '<'                // Find start of element.
     234                . '(?(?=!--)'        // Is this a comment?
     235                .     $comment_regex // Find end of comment.
     236                . '|'
     237                .     '[^>]+>'       // Find end of element.
     238                . ')';
     239
    216240        $shortcode_regex =
    217                         '\['                    // Find start of shortcode.
    218                 .       '[\/\[]?'               // Shortcodes may begin with [/ or [[
    219                 .       '[^\s\/\[\]]'   // No whitespace before name.
    220                 .       '[^\[\]]*+'             // Shortcodes do not contain other shortcodes. Possessive critical.
    221                 .       '\]'                    // Find end of shortcode.
    222                 .       '\]?';                  // Shortcodes may end with ]]
    223        
    224         $regex =
    225                         '/('                                    // Capture the entire match.
    226                 .               '<'                                     // Find start of element.
    227                 .               '(?(?=!--)'                     // Is this a comment?
    228                 .                       $comment_regex  // Find end of comment.
    229                 .               '|'
    230                 .                       '[^>]+>'                // Find end of element.
    231                 .               ')'
    232                 .       '|'
    233                 .               $shortcode_regex        // Find shortcodes.
    234                 .       ')/s';
     241                  '\['               // Find start of shortcode.
     242                . '[\/\[]?'          // Shortcodes may begin with [/ or [[
     243                . '[^\s\/\[\]]'      // No whitespace before name.
     244                . "[^\[\]$html]*+"   // Shortcodes do not contain other shortcodes. Possessive critical.
     245                . '\]'               // Find end of shortcode.
     246                . '\]?';             // Shortcodes may end with ]]
    235247
     248        if ( $find_shortcodes ) {
     249                $regex = "/($html_regex|$shortcode_regex)/s";
     250        } else {
     251                $regex = "/($html_regex)/s";
     252        }
     253
    236254        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    237255
    238256        foreach ( $textarr as &$curl ) {
     
    253271
    254272                        continue;
    255273
    256                 } elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
     274                } elseif ( $find_shortcodes && '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
    257275                        // This is a shortcode delimiter.
    258276
    259277                        if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
     
    482500 * @return string The filtered content.
    483501 */
    484502function shortcode_unautop( $pee ) {
    485         global $shortcode_tags;
     503        global $shortcode_tags, $shortcode_enabled;
    486504
    487         if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
     505        if ( 'false' === $shortcode_enabled || empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
    488506                return $pee;
    489507        }
    490508
     
    491509        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
    492510        $spaces = wp_spaces_regexp();
    493511
     512        if ( 'restricted' === $shortcode_enabled ) {
     513                $html = '<>';
     514        } else {
     515                $html = '';
     516        }
     517
    494518        $pattern =
    495519                  '/'
    496520                . '<p>'                              // Opening paragraph
     
    500524                .     "($tagregexp)"                 // 2: Shortcode name
    501525                .     '(?![\\w-])'                   // Not followed by word character or hyphen
    502526                                                     // Unroll the loop: Inside the opening shortcode tag
    503                 .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
     527                .     "[^\\]\\/$html]*"              // Not a closing bracket or forward slash
    504528                .     '(?:'
    505529                .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket
    506                 .         '[^\\]\\/]*'               // Not a closing bracket or forward slash
     530                .         "[^\\]\\/$html]*"          // Not a closing bracket or forward slash
    507531                .     ')*?'
    508532                .     '(?:'
    509533                .         '\\/\\]'                   // Self closing tag and closing bracket
  • src/wp-includes/general-template.php

     
    11291129 * @return string HTML link content for archive.
    11301130 */
    11311131function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
     1132        disable_shortcodes();
    11321133        $text = wptexturize($text);
     1134        enable_shortcodes();
    11331135        $url = esc_url($url);
    11341136
    11351137        if ('link' == $format)
  • src/wp-includes/media.php

     
    10721072                                $image_output
    10731073                        </{$icontag}>";
    10741074                if ( $captiontag && trim($attachment->post_excerpt) ) {
     1075                        disable_shortcodes();
    10751076                        $output .= "
    10761077                                <{$captiontag} class='wp-caption-text gallery-caption'>
    10771078                                " . wptexturize($attachment->post_excerpt) . "
    10781079                                </{$captiontag}>";
     1080                        enable_shortcodes();
    10791081                }
    10801082                $output .= "</{$itemtag}>";
    10811083                if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
  • src/wp-includes/shortcodes.php

     
    4444$shortcode_tags = array();
    4545
    4646/**
     47 * The status of the Shortcode API, which may need to be known in related functions.
     48 *
     49 * Values:
     50 *   'true'       - Full shortcode support.
     51 *   'restricted' - Shortcodes that contain special characters will be ignored.
     52 *   'false'      - All shortcode features are disabled.
     53 *
     54 * @since 4.1.0
     55 *
     56 * @name $shortcode_enabled
     57 * @var string
     58 * @global string $shortcode_enabled
     59 */
     60$shortcode_enabled = 'true';
     61
     62/**
    4763 * Add hook for shortcode tag.
    4864 *
    4965 * There can only be one hook for each shortcode. Which means that if another
     
    191207 * @return string Content with shortcodes filtered out.
    192208 */
    193209function do_shortcode($content) {
    194         global $shortcode_tags;
     210        global $shortcode_tags, $shortcode_enabled;
    195211
    196         if ( false === strpos( $content, '[' ) ) {
     212        if ( 'false' === $shortcode_enabled || false === strpos( $content, '[' ) ) {
    197213                return $content;
    198214        }
    199215
     
    226242 * @return string The shortcode search regular expression
    227243 */
    228244function get_shortcode_regex() {
    229         global $shortcode_tags;
     245        global $shortcode_tags, $shortcode_enabled;
    230246        $tagnames = array_keys($shortcode_tags);
    231247        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     248       
     249        if ( 'restricted' === $shortcode_enabled ) {
     250                $html = '<>';
     251        } else {
     252                $html = '';
     253        }
    232254
    233255        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
    234256        // Also, see shortcode_unautop() and shortcode.js.
     
    238260                . "($tagregexp)"                     // 2: Shortcode name
    239261                . '(?![\\w-])'                       // Not followed by word character or hyphen
    240262                . '('                                // 3: Unroll the loop: Inside the opening shortcode tag
    241                 .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
     263                .     "[^\\]\\/$html]*"              // Not a closing bracket or forward slash
    242264                .     '(?:'
    243265                .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket
    244                 .         '[^\\]\\/]*'               // Not a closing bracket or forward slash
     266                .         "[^\\]\\/$html]*"          // Not a closing bracket or forward slash
    245267                .     ')*?'
    246268                . ')'
    247269                . '(?:'
     
    384406 * @return string Content without shortcode tags.
    385407 */
    386408function strip_shortcodes( $content ) {
    387         global $shortcode_tags;
     409        global $shortcode_tags, $shortcode_enabled;
    388410
    389         if ( false === strpos( $content, '[' ) ) {
     411        if ( 'false' === $shortcode_enabled || false === strpos( $content, '[' ) ) {
    390412                return $content;
    391413        }
    392414
     
    407429        return $m[1] . $m[6];
    408430}
    409431
     432/**
     433 * Enable the Shortcode API
     434 *
     435 * @since 4.1.0
     436 *
     437 * @param string $filter_arg Allows this function to get hooked to a filter.
     438 * @return string The first param will be returned.
     439 */
     440function enable_shortcodes( $filter_arg = '' ) {
     441        $shortcode_enabled = 'true';
     442        return $filter_arg;
     443}
     444
     445/**
     446 * Restrict the Shortcode API from parsing shortcodes that contain HTML.
     447 *
     448 * @since 4.1.0
     449 *
     450 * @param string $filter_arg Allows this function to get hooked to a filter.
     451 * @return string The first param will be returned.
     452 */
     453function restrict_shortcodes( $filter_arg = '' ) {
     454        $shortcode_enabled = 'restricted';
     455        return $filter_arg;
     456}
     457
     458/**
     459 * Disable the Shortcode API
     460 *
     461 * @since 4.1.0
     462 *
     463 * @param string $filter_arg Allows this function to get hooked to a filter.
     464 * @return string The first param will be returned.
     465 */
     466function disable_shortcodes( $filter_arg = '' ) {
     467        $shortcode_enabled = 'false';
     468        return $filter_arg;
     469}
     470
    410471add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()