Make WordPress Core


Ignore:
Timestamp:
10/12/2023 02:25:18 PM (2 years ago)
Author:
davidbaumwald
Message:

Grouped backports to the 4.2 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.2/src/wp-includes/shortcodes.php

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