WordPress.org

Make WordPress Core

Ticket #29029: 29029.diff

File 29029.diff, 1.9 KB (added by ericlewis, 6 years ago)
  • src/wp-includes/shortcodes.php

    diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php
    index 55e64a1..3ed33b2 100644
    a b function has_shortcode( $content, $tag ) { 
    176176}
    177177
    178178/**
     179 * Search content for shortcodes and return them.
     180 *
     181 * @param  string       $content  Content to search for shortcodes.
     182 * @param  string|array $tagnames Tagnames to search for. If false, will search all.
     183 * @return false|array Array of shortcodes found.
     184 */
     185function get_shortcodes( $content, $tagnames = false ) {
     186        if ( is_string( $tagnames ) ) {
     187                $tagnames = array( $tagnames );
     188        }
     189        preg_match_all( '/' . get_shortcode_regex( $tagnames ) . '/s', $content, $matches, PREG_SET_ORDER );
     190
     191        if ( empty( $matches ) )
     192                return false;
     193
     194        $found_shortcodes = array();
     195        foreach ( $matches as $shortcode ) {
     196                $found_shortcodes[] = array(
     197                        'tag' => $shortcode[2],
     198                        'atts' => shortcode_parse_atts( $shortcode[3] )
     199                );
     200        }
     201        return $found_shortcodes;
     202}
     203
     204/**
    179205 * Search content for shortcodes and filter shortcodes through their hooks.
    180206 *
    181207 * If there are no shortcode tags defined, then the content will be returned
    function do_shortcode($content) { 
    221247 *
    222248 * @since 2.5.0
    223249 *
    224  * @uses $shortcode_tags
    225  *
    226  * @return string The shortcode search regular expression
     250 * @param  array $tagnames Specific tags to build the regex for.
     251 * @return string          The shortcode search regular expression.
    227252 */
    228 function get_shortcode_regex() {
     253function get_shortcode_regex( $tagnames = '' ) {
    229254        global $shortcode_tags;
    230         $tagnames = array_keys($shortcode_tags);
     255        if ( empty( $tagnames ) ) {
     256                $tagnames = array_keys( $shortcode_tags );
     257        }
    231258        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    232259
    233260        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()