Changeset 54319 for trunk/src/wp-includes/shortcodes.php
- Timestamp:
- 09/26/2022 10:41:11 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/shortcodes.php
r54248 r54319 22 22 * To apply shortcode tags to content: 23 23 * 24 * $out = apply_shortcodes( $content );24 * $out = do_shortcode( $content ); 25 25 * 26 26 * @link https://developer.wordpress.org/plugins/shortcodes/ … … 172 172 * Searches content for shortcodes and filter shortcodes through their hooks. 173 173 * 174 * If there are no shortcode tags defined, then the content will be returned 175 * without any filtering. This might cause issues when plugins are disabled but 176 * the shortcode will still show up in the post or content. 174 * This function is an alias for do_shortcode(). 177 175 * 178 176 * @since 5.4.0 179 177 * 180 * @ global array $shortcode_tags List of shortcode tags and their callback hooks.178 * @see do_shortcode() 181 179 * 182 180 * @param string $content Content to search for shortcodes. … … 186 184 */ 187 185 function apply_shortcodes( $content, $ignore_html = false ) { 188 global $shortcode_tags; 189 190 if ( false === strpos( $content, '[' ) ) { 191 return $content; 192 } 193 194 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { 195 return $content; 196 } 197 198 // Find all registered tag names in $content. 199 preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); 200 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 201 202 if ( empty( $tagnames ) ) { 203 return $content; 204 } 205 206 $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); 207 208 $pattern = get_shortcode_regex( $tagnames ); 209 $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content ); 210 211 // Always restore square braces so we don't break things like <!--[if IE ]>. 212 $content = unescape_invalid_shortcodes( $content ); 213 214 return $content; 186 return do_shortcode( $content, $ignore_html ); 215 187 } 216 188 … … 218 190 * Searches content for shortcodes and filter shortcodes through their hooks. 219 191 * 220 * This function is an alias for apply_shortcodes(). 221 * 222 * @since 2.5.0 223 * 224 * @see apply_shortcodes() 192 * If there are no shortcode tags defined, then the content will be returned 193 * without any filtering. This might cause issues when plugins are disabled but 194 * the shortcode will still show up in the post or content. 195 * 196 * @since 2.5.0 197 * 198 * @global array $shortcode_tags List of shortcode tags and their callback hooks. 225 199 * 226 200 * @param string $content Content to search for shortcodes. … … 230 204 */ 231 205 function do_shortcode( $content, $ignore_html = false ) { 232 return apply_shortcodes( $content, $ignore_html ); 206 global $shortcode_tags; 207 208 if ( false === strpos( $content, '[' ) ) { 209 return $content; 210 } 211 212 if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { 213 return $content; 214 } 215 216 // Find all registered tag names in $content. 217 preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); 218 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 219 220 if ( empty( $tagnames ) ) { 221 return $content; 222 } 223 224 $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); 225 226 $pattern = get_shortcode_regex( $tagnames ); 227 $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content ); 228 229 // Always restore square braces so we don't break things like <!--[if IE ]>. 230 $content = unescape_invalid_shortcodes( $content ); 231 232 return $content; 233 233 } 234 234 … … 300 300 301 301 /** 302 * Regular Expression callable for apply_shortcodes() for calling shortcode hook.302 * Regular Expression callable for do_shortcode() for calling shortcode hook. 303 303 * 304 304 * @see get_shortcode_regex() for details of the match array contents.
Note: See TracChangeset
for help on using the changeset viewer.