Make WordPress Core

Ticket #25435: 25435.5.diff

File 25435.5.diff, 1.5 KB (added by rmccue, 8 years ago)

Add shortcode tag to error message

  • wp-includes/shortcodes.php

    diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php
    index 057fad7..beba16f 100644
    a b function do_shortcode( $content, $ignore_html = false ) { 
    228228}
    229229
    230230/**
     231 * Executes a single shortcode with given attributes.
     232 *
     233 * This function is not meant for use with nested shortcodes. For that, use do_shortcode().
     234 *
     235 * @since 4.4.0
     236 *
     237 * @global array $shortcode_tags Shortcode tags.
     238 *
     239 * @param string $tag     Name of a registered shortcode.
     240 * @param array  $atts    Optional. Attributes to pass to the shortcode hook. Default empty array.
     241 * @param string $content Optional. Content to use inside the shortcode tag. Default null (self-closing).
     242 * @return string|WP_Error Shortcode content, or WP_Error instance if invalid.
     243 */
     244function do_single_shortcode( $tag, $atts = array(), $content = null ) {
     245        global $shortcode_tags;
     246
     247        if ( empty( $shortcode_tags[ $tag ] ) ) {
     248                return new WP_Error( 'shortcode_invalid_tag', sprintf( __( 'Shortcode %s is not registered' ), $tag ), $tag );
     249        }
     250
     251        $callback = $shortcode_tags[ $tag ];
     252
     253        if ( ! is_callable( $callback ) ) {
     254                return new WP_Error( 'shortcode_invalid_callback', sprintf( __( 'Shortcode %s does not have a valid registered callback.' ), $tag ), $tag );
     255        }
     256
     257        return call_user_func( $callback, $atts, $content, $tag );
     258}
     259
     260/**
    231261 * Retrieve the shortcode regular expression for searching.
    232262 *
    233263 * The regular expression combines the shortcode tags in the regular expression