Created
December 6, 2013 18:18
-
-
Save annalinneajohansson/7829632 to your computer and use it in GitHub Desktop.
Allow array check for shortcode (based on has_shortcode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hip_has_shortcode( $content, $tags ) { | |
if( is_array( $tags ) ) { | |
foreach ( $tags as $tag ) { | |
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); | |
if ( empty( $matches ) ) | |
return false; | |
foreach ( $matches as $shortcode ) { | |
if ( $tag === $shortcode[2] ) | |
return true; | |
} | |
} | |
} else { | |
if ( shortcode_exists( $tags ) ) { | |
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); | |
if ( empty( $matches ) ) | |
return false; | |
foreach ( $matches as $shortcode ) { | |
if ( $tags === $shortcode[2] ) | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment