diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php
index 62d1d1e644..509957daf1 100644
a
|
b
|
|
41 | 41 | */ |
42 | 42 | $shortcode_tags = array(); |
43 | 43 | |
| 44 | /** |
| 45 | * Container to keep track of currently running shortcodes. |
| 46 | * |
| 47 | * @since 5.7.0 |
| 48 | * |
| 49 | * @var array |
| 50 | * @global array $wp_current_shortcode |
| 51 | */ |
| 52 | global $wp_current_shortcode; |
| 53 | |
| 54 | if ( ! isset( $wp_current_shortcode ) ) { |
| 55 | $wp_current_shortcode = array(); |
| 56 | } |
| 57 | |
44 | 58 | /** |
45 | 59 | * Adds a new shortcode. |
46 | 60 | * |
… |
… |
function has_shortcode( $content, $tag ) { |
159 | 173 | return false; |
160 | 174 | } |
161 | 175 | |
| 176 | /** |
| 177 | * Retrieve the name of the current shortcode being processed. |
| 178 | * |
| 179 | * @since 5.7.0 |
| 180 | * |
| 181 | * @global array $wp_current_shortcode Stores the list of current shortcodes with the current one last. |
| 182 | * |
| 183 | * @return string Tag name of the current shortcode. |
| 184 | */ |
| 185 | function current_shortcode() { |
| 186 | global $wp_current_shortcode; |
| 187 | return end( $wp_current_shortcode ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Check if a shortcode is currently being processed. |
| 192 | * |
| 193 | * This function allows detection for any shortcode currently being executed |
| 194 | * (despite not being the most recent shortcode to fire, in the case of |
| 195 | * shortcodes called from shortcode callbacks) to be verified. |
| 196 | * |
| 197 | * @since 5.7.0 |
| 198 | * |
| 199 | * @global array $wp_current_shortcode Current shortcode(s). |
| 200 | * |
| 201 | * @param null|string $tag Optional. Shortcode tag to check. Defaults to null, which |
| 202 | * checks if any shortcode is currently being run. |
| 203 | * @return bool Whether the shortcode is currently in the stack. |
| 204 | */ |
| 205 | function doing_shortcode( $tag = null ) { |
| 206 | global $wp_current_shortcode; |
| 207 | |
| 208 | if ( null === $tag ) { |
| 209 | return ! empty( $wp_current_shortcode ); |
| 210 | } |
| 211 | |
| 212 | return in_array( $tag, $wp_current_shortcode ); |
| 213 | } |
| 214 | |
162 | 215 | /** |
163 | 216 | * Search content for shortcodes and filter shortcodes through their hooks. |
164 | 217 | * |
… |
… |
function get_shortcode_regex( $tagnames = null ) { |
298 | 351 | * @access private |
299 | 352 | * |
300 | 353 | * @global array $shortcode_tags |
| 354 | * @global array $wp_current_shortcode |
301 | 355 | * |
302 | 356 | * @param array $m Regular expression match array. |
303 | 357 | * @return string|false Shortcode output on success, false on failure. |
304 | 358 | */ |
305 | 359 | function do_shortcode_tag( $m ) { |
306 | | global $shortcode_tags; |
| 360 | global $shortcode_tags, $wp_current_shortcode; |
307 | 361 | |
308 | 362 | // Allow [[foo]] syntax for escaping a tag. |
309 | 363 | if ( '[' === $m[1] && ']' === $m[6] ) { |
… |
… |
function do_shortcode_tag( $m ) { |
320 | 374 | return $m[0]; |
321 | 375 | } |
322 | 376 | |
| 377 | $wp_current_shortcode[] = $tag; |
| 378 | |
323 | 379 | /** |
324 | 380 | * Filters whether to call a shortcode callback. |
325 | 381 | * |
… |
… |
function do_shortcode_tag( $m ) { |
335 | 391 | */ |
336 | 392 | $return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m ); |
337 | 393 | if ( false !== $return ) { |
| 394 | array_pop( $wp_current_shortcode ); |
338 | 395 | return $return; |
339 | 396 | } |
340 | 397 | |
… |
… |
function do_shortcode_tag( $m ) { |
352 | 409 | * @param array|string $attr Shortcode attributes array or empty string. |
353 | 410 | * @param array $m Regular expression match array. |
354 | 411 | */ |
355 | | return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m ); |
| 412 | $return = apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m ); |
| 413 | |
| 414 | array_pop( $wp_current_shortcode ); |
| 415 | |
| 416 | return $return; |
356 | 417 | } |
357 | 418 | |
358 | 419 | /** |