WordPress.org

Make WordPress Core

Changeset 27394


Ignore:
Timestamp:
03/04/2014 07:10:46 AM (7 years ago)
Author:
nacin
Message:

Bail early from shortcode functions if no delimiter is present.

This is a significant performance improvement for processing content without shortcodes, and only the slightest hit when content contains shortcodes (which must then undergo processing anyway). Performance results on the ticket.

props TobiasBg.
fixes #23855.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/shortcodes.php

    r26868 r27394  
    156156 */
    157157function has_shortcode( $content, $tag ) {
     158    if ( false === strpos( $content, '[' ) ) {
     159        return false;
     160    }
     161
    158162    if ( shortcode_exists( $tag ) ) {
    159163        preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
     
    186190function do_shortcode($content) {
    187191    global $shortcode_tags;
     192
     193    if ( false === strpos( $content, '[' ) ) {
     194        return $content;
     195    }
    188196
    189197    if (empty($shortcode_tags) || !is_array($shortcode_tags))
     
    376384    global $shortcode_tags;
    377385
     386    if ( false === strpos( $content, '[' ) ) {
     387        return $content;
     388    }
     389
    378390    if (empty($shortcode_tags) || !is_array($shortcode_tags))
    379391        return $content;
Note: See TracChangeset for help on using the changeset viewer.