Make WordPress Core


Ignore:
Timestamp:
10/12/2023 02:28:05 PM (3 years ago)
Author:
davidbaumwald
Message:

Grouped backports to the 4.3 branch.

  • Comments: Prevent users who can not see a post from seeing comments on it.
  • Shortcodes: Restrict ajax handler for media shortcode.
  • Prevent unintended behavior when certain objects are unserialized.

Merges [56835], [56836], and [56838] to the 4.1 branch.
Props xknown, jorbin, joehoyle, peterwilsoncc, ehtis, tykoted, antpb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3/src/wp-includes/shortcodes.php

    r34144 r56852  
    172172
    173173/**
    174  * Search content for shortcodes and filter shortcodes through their hooks.
     174 * Returns a list of registered shortcode names found in the given content.
     175 *
     176 * Example usage:
     177 *
     178 *     get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
     179 *     // array( 'audio', 'gallery' )
     180 *
     181 * @since 6.3.2
     182 *
     183 * @param string $content The content to check.
     184 * @return string[] An array of registered shortcode names found in the content.
     185 */
     186function get_shortcode_tags_in_content( $content ) {
     187    if ( false === strpos( $content, '[' ) ) {
     188        return array();
     189    }
     190
     191    preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
     192    if ( empty( $matches ) ) {
     193        return array();
     194    }
     195
     196    $tags = array();
     197    foreach ( $matches as $shortcode ) {
     198        $tags[] = $shortcode[2];
     199
     200        if ( ! empty( $shortcode[5] ) ) {
     201            $deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
     202            if ( ! empty( $deep_tags ) ) {
     203                $tags = array_merge( $tags, $deep_tags );
     204            }
     205        }
     206    }
     207
     208    return $tags;
     209}
     210
     211/**
     212 * Searches content for shortcodes and filter shortcodes through their hooks.
    175213 *
    176214 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset for help on using the changeset viewer.