-
-
Save krishna19/7e9d745a3972fc29fb35 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Loop through an array of shortcodes and check for their existence | |
* @author Gabe Shackle <gabe@hereswhatidid.com> | |
* @param array $shortcodes An array of shortcode strings | |
* @param boolean $match_all Whether to check for the existence of ALL the shortcodes, or just ANY of them | |
* @return mixed The results will either be an array of the found shortcodes or boolean false | |
*/ | |
function shortcodes_exist( $shortcodes = array(), $match_all = false ) { | |
$found_shortcodes = array(); | |
foreach( $shortcodes as $shortcode ) { | |
if ( shortcode_exists( $shortcode ) ) { | |
$found_shortcodes[] = $shortcode; | |
} else { | |
if ( $match_all ) { | |
return false; | |
} | |
} | |
} | |
if ( count( $found_shortcodes ) === 0 ) { | |
return false; | |
} else { | |
return $found_shortcodes; | |
} | |
} | |
$shortcodes_to_find = array( | |
'gallery', | |
'audio', | |
'thiswontwork' | |
); | |
$find_any = shortcodes_exist( $shortcodes_to_find ); | |
// returns array( 'gallery', 'audio' ); | |
$find_all = shortcodes_exist( $shortcodes_to_find, true ); | |
// returns false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment