| 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 | */ |
| 244 | function 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 | /** |