Make WordPress Core


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

Grouped backports to the 5.0 branch.

  • Comments: Prevent users who can not see a post from seeing comments on it.
  • Shortcodes: Restrict media shortcode ajax to certain type.
  • REST API: Ensure no-cache headers are sent when methods are overridden.
  • REST API: Limit search_columns for users without list_users.
  • Prevent unintended behavior when certain objects are unserialized.

Merges [56833], [56834], [56835], [56836], and [56838] to the 5.0 branch.
Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue.

File:
1 edited

Legend:

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

    r41286 r56871  
    160160
    161161/**
    162  * Search content for shortcodes and filter shortcodes through their hooks.
     162 * Returns a list of registered shortcode names found in the given content.
     163 *
     164 * Example usage:
     165 *
     166 *     get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
     167 *     // array( 'audio', 'gallery' )
     168 *
     169 * @since 6.3.2
     170 *
     171 * @param string $content The content to check.
     172 * @return string[] An array of registered shortcode names found in the content.
     173 */
     174function get_shortcode_tags_in_content( $content ) {
     175    if ( false === strpos( $content, '[' ) ) {
     176        return array();
     177    }
     178
     179    preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
     180    if ( empty( $matches ) ) {
     181        return array();
     182    }
     183
     184    $tags = array();
     185    foreach ( $matches as $shortcode ) {
     186        $tags[] = $shortcode[2];
     187
     188        if ( ! empty( $shortcode[5] ) ) {
     189            $deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
     190            if ( ! empty( $deep_tags ) ) {
     191                $tags = array_merge( $tags, $deep_tags );
     192            }
     193        }
     194    }
     195
     196    return $tags;
     197}
     198
     199/**
     200 * Searches content for shortcodes and filter shortcodes through their hooks.
    163201 *
    164202 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset for help on using the changeset viewer.