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