bbp_has_shortcode( string $text = '' )
Check if text contains a bbPress shortcode.
Description Description
Loops through registered bbPress shortcodes and keeps track of which ones were used in a blob of text. If no text is passed, the current global post content is assumed.
A preliminary strpos() is performed before looping through each shortcode, to prevent unnecessarily processing.
Parameters Parameters
- $text
-
(Optional)
Default value: ''
Return Return
(bool)
Source Source
File: includes/common/template.php
function bbp_has_shortcode( $text = '' ) { // Default return value $retval = false; $found = array(); // Fallback to global post_content if ( empty( $text ) && is_singular() ) { $text = bbp_get_global_post_field( 'post_content', 'raw' ); } // Skip if empty, or string doesn't contain the bbPress shortcode prefix if ( ! empty( $text ) && ( false !== strpos( $text, '[bbp' ) ) ) { // Get possible shortcodes $codes = array_keys( bbpress()->shortcodes->codes ); // Loop through codes foreach ( $codes as $code ) { // Looking for shortcode in text if ( has_shortcode( $text, $code ) ) { $retval = true; $found[] = $code; } } } // Filter & return return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |