Changeset 56871 for branches/5.0/src/wp-includes/shortcodes.php
- Timestamp:
- 10/12/2023 02:59:28 PM (3 years ago)
- File:
-
- 1 edited
-
branches/5.0/src/wp-includes/shortcodes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/shortcodes.php
r41286 r56871 160 160 161 161 /** 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 */ 174 function 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. 163 201 * 164 202 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset
for help on using the changeset viewer.