Make WordPress Core


Ignore:
Timestamp:
10/01/2015 05:33:58 PM (10 years ago)
Author:
wonderboymusic
Message:

Shortcodes: prevent registration of invalid shortcode names.

Adds unit tests.

Props miqrogroove.
Fixes #34090.

File:
1 edited

Legend:

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

    r34744 r34745  
    8989function add_shortcode($tag, $func) {
    9090    global $shortcode_tags;
     91
     92    if ( '' == trim( $tag ) ) {
     93        $message = __( 'Invalid shortcode name.  Empty name given.' );
     94        _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
     95        return;
     96    }
     97
     98    if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20]@', $tag ) ) {
     99        $message = sprintf( __( 'Invalid shortcode name: %s  Do not use spaces or reserved chars: & / < > [ ]' ), $tag );
     100        _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
     101        return;
     102    }
     103
    91104    $shortcode_tags[ $tag ] = $func;
    92105}
Note: See TracChangeset for help on using the changeset viewer.