Changeset 56851 for branches/4.2/src/wp-includes/shortcodes.php
- Timestamp:
- 10/12/2023 02:25:18 PM (2 years ago)
- File:
-
- 1 edited
-
branches/4.2/src/wp-includes/shortcodes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/src/wp-includes/shortcodes.php
r34145 r56851 174 174 175 175 /** 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 */ 188 function 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. 177 215 * 178 216 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset
for help on using the changeset viewer.