Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
@@ -168,6 +168,44 @@ function has_shortcode( $content, $tag ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of registered shortcode names found in the given content.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
|
||||
* // array( 'audio', 'gallery' )
|
||||
*
|
||||
* @since 6.3.2
|
||||
*
|
||||
* @param string $content The content to check.
|
||||
* @return string[] An array of registered shortcode names found in the content.
|
||||
*/
|
||||
function get_shortcode_tags_in_content( $content ) {
|
||||
if ( false === strpos( $content, '[' ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
|
||||
if ( empty( $matches ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
foreach ( $matches as $shortcode ) {
|
||||
$tags[] = $shortcode[2];
|
||||
|
||||
if ( ! empty( $shortcode[5] ) ) {
|
||||
$deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
|
||||
if ( ! empty( $deep_tags ) ) {
|
||||
$tags = array_merge( $tags, $deep_tags );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches content for shortcodes and filter shortcodes through their hooks.
|
||||
*
|
||||
@@ -222,7 +260,7 @@ function do_shortcode( $content, $ignore_html = false ) {
|
||||
}
|
||||
|
||||
// Ensure this context is only added once if shortcodes are nested.
|
||||
$has_filter = has_filter( 'wp_get_attachment_image_context', '_filter_do_shortcode_context' );
|
||||
$has_filter = has_filter( 'wp_get_attachment_image_context', '_filter_do_shortcode_context' );
|
||||
$filter_added = false;
|
||||
|
||||
if ( ! $has_filter ) {
|
||||
|
||||
Reference in New Issue
Block a user