Changeset 6440 for trunk/src/includes/common/template.php
- Timestamp:
- 05/27/2017 07:53:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/template.php
r6438 r6440 1111 1111 $bbp_classes[] = 'bbp-search-results'; 1112 1112 $bbp_classes[] = 'forum-search-results'; 1113 1114 /** Shortcodes ************************************************************/ 1115 1116 } elseif ( bbp_has_shortcode() ) { 1117 $bbp_classes[] = 'bbp-shortcode'; 1113 1118 } 1114 1119 … … 1128 1133 // Filter & return 1129 1134 return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes ); 1135 } 1136 1137 /** 1138 * Check if text contains a bbPress shortcode. 1139 * 1140 * Loops through registered bbPress shortcodes and keeps track of which ones 1141 * were used in a blob of text. If no text is passed, the current global post 1142 * content is assumed. 1143 * 1144 * A preliminary strpos() is performed before looping through each shortcode, to 1145 * prevent unnecessarily processing. 1146 * 1147 * @since 2.6.0 1148 * 1149 * @uses is_singular() 1150 * @uses bbp_get_global_post_field() 1151 * @uses has_shortcode(); 1152 * 1153 * @param string $text 1154 * @return bool 1155 */ 1156 function bbp_has_shortcode( $text = '' ) { 1157 1158 // Default return value 1159 $retval = false; 1160 $found = array(); 1161 1162 // Fallback to global post_content 1163 if ( empty( $text ) && is_singular() ) { 1164 $text = bbp_get_global_post_field( 'post_content', 'raw' ); 1165 } 1166 1167 // Skip if empty, or string doesn't contain the bbPress shortcode prefix 1168 if ( ! empty( $text ) && ( false !== strpos( $text, '[bbp' ) ) ) { 1169 1170 // Get possible shortcodes 1171 $codes = array_keys( bbpress()->shortcodes->codes ); 1172 1173 // Loop through codes 1174 foreach ( $codes as $code ) { 1175 1176 // Looking for shortcode in text 1177 if ( has_shortcode( $text, $code ) ) { 1178 $retval = true; 1179 $found[] = $code; 1180 } 1181 } 1182 } 1183 1184 // Filter & return 1185 return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text ); 1130 1186 } 1131 1187 … … 1151 1207 * @uses bbp_is_topics_created() 1152 1208 * @uses bbp_is_replies_created() 1209 * @uses bbp_has_shortcode() 1210 * 1153 1211 * @return bool In a bbPress page 1154 1212 */ … … 1236 1294 } elseif ( bbp_is_search_results() ) { 1237 1295 $retval = true; 1296 1297 /** Shortcodes ************************************************************/ 1298 1299 } elseif ( bbp_has_shortcode() ) { 1300 $retval = true; 1238 1301 } 1239 1302 1240 1303 /** Done ******************************************************************/ 1241 1304 1305 // Filter & return 1242 1306 return (bool) apply_filters( 'is_bbpress', $retval ); 1243 1307 }
Note: See TracChangeset
for help on using the changeset viewer.