Make WordPress Core

Ticket #25435: 25435.3.diff

File 25435.3.diff, 1.2 KB (added by miqrogroove, 8 years ago)
  • src/wp-includes/shortcodes.php

     
    228228}
    229229
    230230/**
     231 * Execute a single shortcode with given attributes.
     232 *
     233 * @param string $tag Name of a registered Shortcode.
     234 * @param array $atts Attributes to pass to the shortcode hook.
     235 * @param string $content Content inside the tag. Null for self-closing.
     236 * @return string|WP_Error Shortcode content, or WP_Error instance if invalid.
     237 */
     238function do_single_shortcode( $tag, $atts = array(), $content = null ) {
     239        global $shortcode_tags;
     240        if ( empty( $shortcode_tags[ $tag ] ) ) {
     241                return new WP_Error( 'shortcode_invalid_tag', __( 'Shortcode is not registered' ), $tag );
     242        }
     243
     244        $callback = $shortcode_tags[ $tag ];
     245        if ( ! is_callable( $callback ) ) {
     246                return new WP_Error( 'shortcode_invalid_callback', __( 'Shortcode does not have a valid callback registered' ), $tag );
     247        }
     248
     249        return call_user_func( $callback, $atts, $content, $tag );
     250}
     251
     252/**
    231253 * Retrieve the shortcode regular expression for searching.
    232254 *
    233255 * The regular expression combines the shortcode tags in the regular expression