Changeset 56852 for branches/4.3/src/wp-includes/shortcodes.php
- Timestamp:
- 10/12/2023 02:28:05 PM (3 years ago)
- File:
-
- 1 edited
-
branches/4.3/src/wp-includes/shortcodes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.3/src/wp-includes/shortcodes.php
r34144 r56852 172 172 173 173 /** 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 */ 186 function 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. 175 213 * 176 214 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset
for help on using the changeset viewer.