Ticket #47616: 47616.patch
File 47616.patch, 2.9 KB (added by , 20 months ago) |
---|
-
wp-includes/shortcodes.php
42 42 $shortcode_tags = array(); 43 43 44 44 /** 45 * Container the keeps track of currently running shortcodes. 46 * 47 * @since 5.2.x 48 * @var array 49 * @global array $wp_current_shortcode 50 */ 51 global $wp_current_shortcode; 52 53 if ( ! isset( $wp_current_shortcode ) ) { 54 $wp_current_shortcode = array(); 55 } 56 57 /** 45 58 * Adds a new shortcode. 46 59 * 47 60 * Care should be taken through prefixing or other means to ensure that the … … 160 173 } 161 174 162 175 /** 176 * Retrieve the name of the current shortcode being processed. 177 * 178 * @since 5.2.x 179 * 180 * @global array $wp_current_shortcode Stores the list of current shortcodes with the current one last. 181 * 182 * @return string Tag name of the current shortcode. 183 */ 184 function current_shortcode() { 185 global $wp_current_shortcode; 186 return end( $wp_current_shortcode ); 187 } 188 189 /** 190 * Check if a shortcode is currently being processed. 191 * 192 * This function allows detection for any shortcode currently being 193 * executed (despite not being the most recent shortcode to fire, in the case of 194 * shortcodes called from shortcode callbacks) to be verified. 195 * 196 * @since 5.2.x 197 * 198 * @global array $wp_current_shortcode Current shortcode(s). 199 * 200 * @param null|string $tag Optional. Shortcode tag to check. Defaults to null, which 201 * checks if any shortcode is currently being run. 202 * @return bool Whether the shortcode is currently in the stack. 203 */ 204 function doing_shortcode( $tag = null ) { 205 global $wp_current_shortcode; 206 207 if ( null === $tag ) { 208 return ! empty( $wp_current_shortcode ); 209 } 210 211 return in_array( $tag, $wp_current_shortcode ); 212 } 213 214 /** 163 215 * Search content for shortcodes and filter shortcodes through their hooks. 164 216 * 165 217 * If there are no shortcode tags defined, then the content will be returned … … 285 337 * @return string|false False on failure. 286 338 */ 287 339 function do_shortcode_tag( $m ) { 288 global $shortcode_tags ;340 global $shortcode_tags, $wp_current_shortcode; 289 341 290 342 // allow [[foo]] syntax for escaping a tag 291 343 if ( $m[1] == '[' && $m[6] == ']' ) { … … 302 354 return $m[0]; 303 355 } 304 356 357 $wp_current_shortcode[] = $tag; 358 305 359 /** 306 360 * Filters whether to call a shortcode callback. 307 361 * … … 317 371 */ 318 372 $return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m ); 319 373 if ( false !== $return ) { 374 array_pop( $wp_current_shortcode ); 320 375 return $return; 321 376 } 322 377 … … 334 389 * @param array|string $attr Shortcode attributes array or empty string. 335 390 * @param array $m Regular expression match array. 336 391 */ 337 return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m ); 392 $return = apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m ); 393 394 array_pop( $wp_current_shortcode ); 395 396 return $return; 338 397 } 339 398 340 399 /**