WordPress.org

Make WordPress Core

Ticket #12368: shortcode-limit.patch

File shortcode-limit.patch, 978 bytes (added by abelcheung, 6 years ago)
  • wp-includes/shortcodes.php

    function remove_all_shortcodes() { 
    139139 * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes. 
    140140 * 
    141141 * @param string $content Content to search for shortcodes 
     142 * @param int $limit Maximum number of shortcode replacements, default is no limit 
    142143 * @return string Content with shortcodes filtered out. 
    143144 */ 
    144 function do_shortcode($content) { 
     145function do_shortcode($content, $limit = -1) { 
    145146        global $shortcode_tags; 
    146147 
    147148        if (empty($shortcode_tags) || !is_array($shortcode_tags)) 
    148149                return $content; 
    149150 
    150151        $pattern = get_shortcode_regex(); 
    151         return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content); 
     152        $limit = (int)$limit; 
     153        return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content, $limit); 
    152154} 
    153155 
    154156/**