Changeset 56859 for branches/4.6/src/wp-includes/shortcodes.php
- Timestamp:
- 10/12/2023 02:43:19 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.6/src/wp-includes/shortcodes.php
r37865 r56859 186 186 187 187 /** 188 * Search content for shortcodes and filter shortcodes through their hooks. 188 * Returns a list of registered shortcode names found in the given content. 189 * 190 * Example usage: 191 * 192 * get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' ); 193 * // array( 'audio', 'gallery' ) 194 * 195 * @since 6.3.2 196 * 197 * @param string $content The content to check. 198 * @return string[] An array of registered shortcode names found in the content. 199 */ 200 function get_shortcode_tags_in_content( $content ) { 201 if ( false === strpos( $content, '[' ) ) { 202 return array(); 203 } 204 205 preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); 206 if ( empty( $matches ) ) { 207 return array(); 208 } 209 210 $tags = array(); 211 foreach ( $matches as $shortcode ) { 212 $tags[] = $shortcode[2]; 213 214 if ( ! empty( $shortcode[5] ) ) { 215 $deep_tags = get_shortcode_tags_in_content( $shortcode[5] ); 216 if ( ! empty( $deep_tags ) ) { 217 $tags = array_merge( $tags, $deep_tags ); 218 } 219 } 220 } 221 222 return $tags; 223 } 224 225 /** 226 * Searches content for shortcodes and filter shortcodes through their hooks. 189 227 * 190 228 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset
for help on using the changeset viewer.