PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-includes/shortcodes.php

https://gitlab.com/VTTE/sitios-vtte
PHP | 671 lines | 301 code | 67 blank | 303 comment | 46 complexity | 2c1e155130f1163fa52698c22607c969 MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress API for creating bbcode-like tags or what WordPress calls
  4. * "shortcodes". The tag and attribute parsing or regular expression code is
  5. * based on the Textpattern tag parser.
  6. *
  7. * A few examples are below:
  8. *
  9. * [shortcode /]
  10. * [shortcode foo="bar" baz="bing" /]
  11. * [shortcode foo="bar"]content[/shortcode]
  12. *
  13. * Shortcode tags support attributes and enclosed content, but does not entirely
  14. * support inline shortcodes in other shortcodes. You will have to call the
  15. * shortcode parser in your function to account for that.
  16. *
  17. * {@internal
  18. * Please be aware that the above note was made during the beta of WordPress 2.6
  19. * and in the future may not be accurate. Please update the note when it is no
  20. * longer the case.}}
  21. *
  22. * To apply shortcode tags to content:
  23. *
  24. * $out = do_shortcode( $content );
  25. *
  26. * @link https://developer.wordpress.org/plugins/shortcodes/
  27. *
  28. * @package WordPress
  29. * @subpackage Shortcodes
  30. * @since 2.5.0
  31. */
  32. /**
  33. * Container for storing shortcode tags and their hook to call for the shortcode
  34. *
  35. * @since 2.5.0
  36. *
  37. * @name $shortcode_tags
  38. * @var array
  39. * @global array $shortcode_tags
  40. */
  41. $shortcode_tags = array();
  42. /**
  43. * Adds a new shortcode.
  44. *
  45. * Care should be taken through prefixing or other means to ensure that the
  46. * shortcode tag being added is unique and will not conflict with other,
  47. * already-added shortcode tags. In the event of a duplicated tag, the tag
  48. * loaded last will take precedence.
  49. *
  50. * @since 2.5.0
  51. *
  52. * @global array $shortcode_tags
  53. *
  54. * @param string $tag Shortcode tag to be searched in post content.
  55. * @param callable $callback The callback function to run when the shortcode is found.
  56. * Every shortcode callback is passed three parameters by default,
  57. * including an array of attributes (`$atts`), the shortcode content
  58. * or null if not set (`$content`), and finally the shortcode tag
  59. * itself (`$shortcode_tag`), in that order.
  60. */
  61. function add_shortcode( $tag, $callback ) {
  62. global $shortcode_tags;
  63. if ( '' == trim( $tag ) ) {
  64. $message = __( 'Invalid shortcode name: Empty name given.' );
  65. _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
  66. return;
  67. }
  68. if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
  69. /* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
  70. $message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' );
  71. _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
  72. return;
  73. }
  74. $shortcode_tags[ $tag ] = $callback;
  75. }
  76. /**
  77. * Removes hook for shortcode.
  78. *
  79. * @since 2.5.0
  80. *
  81. * @global array $shortcode_tags
  82. *
  83. * @param string $tag Shortcode tag to remove hook for.
  84. */
  85. function remove_shortcode( $tag ) {
  86. global $shortcode_tags;
  87. unset( $shortcode_tags[ $tag ] );
  88. }
  89. /**
  90. * Clear all shortcodes.
  91. *
  92. * This function is simple, it clears all of the shortcode tags by replacing the
  93. * shortcodes global by a empty array. This is actually a very efficient method
  94. * for removing all shortcodes.
  95. *
  96. * @since 2.5.0
  97. *
  98. * @global array $shortcode_tags
  99. */
  100. function remove_all_shortcodes() {
  101. global $shortcode_tags;
  102. $shortcode_tags = array();
  103. }
  104. /**
  105. * Whether a registered shortcode exists named $tag
  106. *
  107. * @since 3.6.0
  108. *
  109. * @global array $shortcode_tags List of shortcode tags and their callback hooks.
  110. *
  111. * @param string $tag Shortcode tag to check.
  112. * @return bool Whether the given shortcode exists.
  113. */
  114. function shortcode_exists( $tag ) {
  115. global $shortcode_tags;
  116. return array_key_exists( $tag, $shortcode_tags );
  117. }
  118. /**
  119. * Whether the passed content contains the specified shortcode
  120. *
  121. * @since 3.6.0
  122. *
  123. * @global array $shortcode_tags
  124. *
  125. * @param string $content Content to search for shortcodes.
  126. * @param string $tag Shortcode tag to check.
  127. * @return bool Whether the passed content contains the given shortcode.
  128. */
  129. function has_shortcode( $content, $tag ) {
  130. if ( false === strpos( $content, '[' ) ) {
  131. return false;
  132. }
  133. if ( shortcode_exists( $tag ) ) {
  134. preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
  135. if ( empty( $matches ) ) {
  136. return false;
  137. }
  138. foreach ( $matches as $shortcode ) {
  139. if ( $tag === $shortcode[2] ) {
  140. return true;
  141. } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
  142. return true;
  143. }
  144. }
  145. }
  146. return false;
  147. }
  148. /**
  149. * Search content for shortcodes and filter shortcodes through their hooks.
  150. *
  151. * This function is an alias for do_shortcode().
  152. *
  153. * @since 5.4.0
  154. *
  155. * @see do_shortcode()
  156. *
  157. * @param string $content Content to search for shortcodes.
  158. * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
  159. * Default false.
  160. * @return string Content with shortcodes filtered out.
  161. */
  162. function apply_shortcodes( $content, $ignore_html = false ) {
  163. return do_shortcode( $content, $ignore_html );
  164. }
  165. /**
  166. * Search content for shortcodes and filter shortcodes through their hooks.
  167. *
  168. * If there are no shortcode tags defined, then the content will be returned
  169. * without any filtering. This might cause issues when plugins are disabled but
  170. * the shortcode will still show up in the post or content.
  171. *
  172. * @since 2.5.0
  173. *
  174. * @global array $shortcode_tags List of shortcode tags and their callback hooks.
  175. *
  176. * @param string $content Content to search for shortcodes.
  177. * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
  178. * Default false.
  179. * @return string Content with shortcodes filtered out.
  180. */
  181. function do_shortcode( $content, $ignore_html = false ) {
  182. global $shortcode_tags;
  183. if ( false === strpos( $content, '[' ) ) {
  184. return $content;
  185. }
  186. if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
  187. return $content;
  188. }
  189. // Find all registered tag names in $content.
  190. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
  191. $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
  192. if ( empty( $tagnames ) ) {
  193. return $content;
  194. }
  195. $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );
  196. $pattern = get_shortcode_regex( $tagnames );
  197. $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );
  198. // Always restore square braces so we don't break things like <!--[if IE ]>.
  199. $content = unescape_invalid_shortcodes( $content );
  200. return $content;
  201. }
  202. /**
  203. * Retrieve the shortcode regular expression for searching.
  204. *
  205. * The regular expression combines the shortcode tags in the regular expression
  206. * in a regex class.
  207. *
  208. * The regular expression contains 6 different sub matches to help with parsing.
  209. *
  210. * 1 - An extra [ to allow for escaping shortcodes with double [[]]
  211. * 2 - The shortcode name
  212. * 3 - The shortcode argument list
  213. * 4 - The self closing /
  214. * 5 - The content of a shortcode when it wraps some content.
  215. * 6 - An extra ] to allow for escaping shortcodes with double [[]]
  216. *
  217. * @since 2.5.0
  218. * @since 4.4.0 Added the `$tagnames` parameter.
  219. *
  220. * @global array $shortcode_tags
  221. *
  222. * @param array $tagnames Optional. List of shortcodes to find. Defaults to all registered shortcodes.
  223. * @return string The shortcode search regular expression
  224. */
  225. function get_shortcode_regex( $tagnames = null ) {
  226. global $shortcode_tags;
  227. if ( empty( $tagnames ) ) {
  228. $tagnames = array_keys( $shortcode_tags );
  229. }
  230. $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
  231. // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag().
  232. // Also, see shortcode_unautop() and shortcode.js.
  233. // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
  234. return '\\[' // Opening bracket.
  235. . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
  236. . "($tagregexp)" // 2: Shortcode name.
  237. . '(?![\\w-])' // Not followed by word character or hyphen.
  238. . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
  239. . '[^\\]\\/]*' // Not a closing bracket or forward slash.
  240. . '(?:'
  241. . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
  242. . '[^\\]\\/]*' // Not a closing bracket or forward slash.
  243. . ')*?'
  244. . ')'
  245. . '(?:'
  246. . '(\\/)' // 4: Self closing tag...
  247. . '\\]' // ...and closing bracket.
  248. . '|'
  249. . '\\]' // Closing bracket.
  250. . '(?:'
  251. . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
  252. . '[^\\[]*+' // Not an opening bracket.
  253. . '(?:'
  254. . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
  255. . '[^\\[]*+' // Not an opening bracket.
  256. . ')*+'
  257. . ')'
  258. . '\\[\\/\\2\\]' // Closing shortcode tag.
  259. . ')?'
  260. . ')'
  261. . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]].
  262. // phpcs:enable
  263. }
  264. /**
  265. * Regular Expression callable for do_shortcode() for calling shortcode hook.
  266. *
  267. * @see get_shortcode_regex for details of the match array contents.
  268. *
  269. * @since 2.5.0
  270. * @access private
  271. *
  272. * @global array $shortcode_tags
  273. *
  274. * @param array $m Regular expression match array
  275. * @return string|false False on failure.
  276. */
  277. function do_shortcode_tag( $m ) {
  278. global $shortcode_tags;
  279. // Allow [[foo]] syntax for escaping a tag.
  280. if ( '[' === $m[1] && ']' === $m[6] ) {
  281. return substr( $m[0], 1, -1 );
  282. }
  283. $tag = $m[2];
  284. $attr = shortcode_parse_atts( $m[3] );
  285. if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
  286. /* translators: %s: Shortcode tag. */
  287. $message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
  288. _doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
  289. return $m[0];
  290. }
  291. /**
  292. * Filters whether to call a shortcode callback.
  293. *
  294. * Returning a non-false value from filter will short-circuit the
  295. * shortcode generation process, returning that value instead.
  296. *
  297. * @since 4.7.0
  298. *
  299. * @param false|string $return Short-circuit return value. Either false or the value to replace the shortcode with.
  300. * @param string $tag Shortcode name.
  301. * @param array|string $attr Shortcode attributes array or empty string.
  302. * @param array $m Regular expression match array.
  303. */
  304. $return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m );
  305. if ( false !== $return ) {
  306. return $return;
  307. }
  308. $content = isset( $m[5] ) ? $m[5] : null;
  309. $output = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6];
  310. /**
  311. * Filters the output created by a shortcode callback.
  312. *
  313. * @since 4.7.0
  314. *
  315. * @param string $output Shortcode output.
  316. * @param string $tag Shortcode name.
  317. * @param array|string $attr Shortcode attributes array or empty string.
  318. * @param array $m Regular expression match array.
  319. */
  320. return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m );
  321. }
  322. /**
  323. * Search only inside HTML elements for shortcodes and process them.
  324. *
  325. * Any [ or ] characters remaining inside elements will be HTML encoded
  326. * to prevent interference with shortcodes that are outside the elements.
  327. * Assumes $content processed by KSES already. Users with unfiltered_html
  328. * capability may get unexpected output if angle braces are nested in tags.
  329. *
  330. * @since 4.2.3
  331. *
  332. * @param string $content Content to search for shortcodes
  333. * @param bool $ignore_html When true, all square braces inside elements will be encoded.
  334. * @param array $tagnames List of shortcodes to find.
  335. * @return string Content with shortcodes filtered out.
  336. */
  337. function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
  338. // Normalize entities in unfiltered HTML before adding placeholders.
  339. $trans = array(
  340. '&#91;' => '&#091;',
  341. '&#93;' => '&#093;',
  342. );
  343. $content = strtr( $content, $trans );
  344. $trans = array(
  345. '[' => '&#91;',
  346. ']' => '&#93;',
  347. );
  348. $pattern = get_shortcode_regex( $tagnames );
  349. $textarr = wp_html_split( $content );
  350. foreach ( $textarr as &$element ) {
  351. if ( '' == $element || '<' !== $element[0] ) {
  352. continue;
  353. }
  354. $noopen = false === strpos( $element, '[' );
  355. $noclose = false === strpos( $element, ']' );
  356. if ( $noopen || $noclose ) {
  357. // This element does not contain shortcodes.
  358. if ( $noopen xor $noclose ) {
  359. // Need to encode stray '[' or ']' chars.
  360. $element = strtr( $element, $trans );
  361. }
  362. continue;
  363. }
  364. if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
  365. // Encode all '[' and ']' chars.
  366. $element = strtr( $element, $trans );
  367. continue;
  368. }
  369. $attributes = wp_kses_attr_parse( $element );
  370. if ( false === $attributes ) {
  371. // Some plugins are doing things like [name] <[email]>.
  372. if ( 1 === preg_match( '%^<\s*\[\[?[^\[\]]+\]%', $element ) ) {
  373. $element = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $element );
  374. }
  375. // Looks like we found some crazy unfiltered HTML. Skipping it for sanity.
  376. $element = strtr( $element, $trans );
  377. continue;
  378. }
  379. // Get element name.
  380. $front = array_shift( $attributes );
  381. $back = array_pop( $attributes );
  382. $matches = array();
  383. preg_match( '%[a-zA-Z0-9]+%', $front, $matches );
  384. $elname = $matches[0];
  385. // Look for shortcodes in each attribute separately.
  386. foreach ( $attributes as &$attr ) {
  387. $open = strpos( $attr, '[' );
  388. $close = strpos( $attr, ']' );
  389. if ( false === $open || false === $close ) {
  390. continue; // Go to next attribute. Square braces will be escaped at end of loop.
  391. }
  392. $double = strpos( $attr, '"' );
  393. $single = strpos( $attr, "'" );
  394. if ( ( false === $single || $open < $single ) && ( false === $double || $open < $double ) ) {
  395. /*
  396. * $attr like '[shortcode]' or 'name = [shortcode]' implies unfiltered_html.
  397. * In this specific situation we assume KSES did not run because the input
  398. * was written by an administrator, so we should avoid changing the output
  399. * and we do not need to run KSES here.
  400. */
  401. $attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr );
  402. } else {
  403. // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'".
  404. // We do not know if $content was unfiltered. Assume KSES ran before shortcodes.
  405. $count = 0;
  406. $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count );
  407. if ( $count > 0 ) {
  408. // Sanitize the shortcode output using KSES.
  409. $new_attr = wp_kses_one_attr( $new_attr, $elname );
  410. if ( '' !== trim( $new_attr ) ) {
  411. // The shortcode is safe to use now.
  412. $attr = $new_attr;
  413. }
  414. }
  415. }
  416. }
  417. $element = $front . implode( '', $attributes ) . $back;
  418. // Now encode any remaining '[' or ']' chars.
  419. $element = strtr( $element, $trans );
  420. }
  421. $content = implode( '', $textarr );
  422. return $content;
  423. }
  424. /**
  425. * Remove placeholders added by do_shortcodes_in_html_tags().
  426. *
  427. * @since 4.2.3
  428. *
  429. * @param string $content Content to search for placeholders.
  430. * @return string Content with placeholders removed.
  431. */
  432. function unescape_invalid_shortcodes( $content ) {
  433. // Clean up entire string, avoids re-parsing HTML.
  434. $trans = array(
  435. '&#91;' => '[',
  436. '&#93;' => ']',
  437. );
  438. $content = strtr( $content, $trans );
  439. return $content;
  440. }
  441. /**
  442. * Retrieve the shortcode attributes regex.
  443. *
  444. * @since 4.4.0
  445. *
  446. * @return string The shortcode attribute regular expression
  447. */
  448. function get_shortcode_atts_regex() {
  449. return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
  450. }
  451. /**
  452. * Retrieve all attributes from the shortcodes tag.
  453. *
  454. * The attributes list has the attribute name as the key and the value of the
  455. * attribute as the value in the key/value pair. This allows for easier
  456. * retrieval of the attributes, since all attributes have to be known.
  457. *
  458. * @since 2.5.0
  459. *
  460. * @param string $text
  461. * @return array|string List of attribute values.
  462. * Returns empty array if trim( $text ) == '""'.
  463. * Returns empty string if trim( $text ) == ''.
  464. * All other matches are checked for not empty().
  465. */
  466. function shortcode_parse_atts( $text ) {
  467. $atts = array();
  468. $pattern = get_shortcode_atts_regex();
  469. $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text );
  470. if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) {
  471. foreach ( $match as $m ) {
  472. if ( ! empty( $m[1] ) ) {
  473. $atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] );
  474. } elseif ( ! empty( $m[3] ) ) {
  475. $atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] );
  476. } elseif ( ! empty( $m[5] ) ) {
  477. $atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] );
  478. } elseif ( isset( $m[7] ) && strlen( $m[7] ) ) {
  479. $atts[] = stripcslashes( $m[7] );
  480. } elseif ( isset( $m[8] ) && strlen( $m[8] ) ) {
  481. $atts[] = stripcslashes( $m[8] );
  482. } elseif ( isset( $m[9] ) ) {
  483. $atts[] = stripcslashes( $m[9] );
  484. }
  485. }
  486. // Reject any unclosed HTML elements.
  487. foreach ( $atts as &$value ) {
  488. if ( false !== strpos( $value, '<' ) ) {
  489. if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
  490. $value = '';
  491. }
  492. }
  493. }
  494. } else {
  495. $atts = ltrim( $text );
  496. }
  497. return $atts;
  498. }
  499. /**
  500. * Combine user attributes with known attributes and fill in defaults when needed.
  501. *
  502. * The pairs should be considered to be all of the attributes which are
  503. * supported by the caller and given as a list. The returned attributes will
  504. * only contain the attributes in the $pairs list.
  505. *
  506. * If the $atts list has unsupported attributes, then they will be ignored and
  507. * removed from the final returned list.
  508. *
  509. * @since 2.5.0
  510. *
  511. * @param array $pairs Entire list of supported attributes and their defaults.
  512. * @param array $atts User defined attributes in shortcode tag.
  513. * @param string $shortcode Optional. The name of the shortcode, provided for context to enable filtering
  514. * @return array Combined and filtered attribute list.
  515. */
  516. function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
  517. $atts = (array) $atts;
  518. $out = array();
  519. foreach ( $pairs as $name => $default ) {
  520. if ( array_key_exists( $name, $atts ) ) {
  521. $out[ $name ] = $atts[ $name ];
  522. } else {
  523. $out[ $name ] = $default;
  524. }
  525. }
  526. if ( $shortcode ) {
  527. /**
  528. * Filters shortcode attributes.
  529. *
  530. * If the third parameter of the shortcode_atts() function is present then this filter is available.
  531. * The third parameter, $shortcode, is the name of the shortcode.
  532. *
  533. * @since 3.6.0
  534. * @since 4.4.0 Added the `$shortcode` parameter.
  535. *
  536. * @param array $out The output array of shortcode attributes.
  537. * @param array $pairs The supported attributes and their defaults.
  538. * @param array $atts The user defined shortcode attributes.
  539. * @param string $shortcode The shortcode name.
  540. */
  541. $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts, $shortcode );
  542. }
  543. return $out;
  544. }
  545. /**
  546. * Remove all shortcode tags from the given content.
  547. *
  548. * @since 2.5.0
  549. *
  550. * @global array $shortcode_tags
  551. *
  552. * @param string $content Content to remove shortcode tags.
  553. * @return string Content without shortcode tags.
  554. */
  555. function strip_shortcodes( $content ) {
  556. global $shortcode_tags;
  557. if ( false === strpos( $content, '[' ) ) {
  558. return $content;
  559. }
  560. if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
  561. return $content;
  562. }
  563. // Find all registered tag names in $content.
  564. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
  565. $tags_to_remove = array_keys( $shortcode_tags );
  566. /**
  567. * Filters the list of shortcode tags to remove from the content.
  568. *
  569. * @since 4.7.0
  570. *
  571. * @param array $tags_to_remove Array of shortcode tags to remove.
  572. * @param string $content Content shortcodes are being removed from.
  573. */
  574. $tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content );
  575. $tagnames = array_intersect( $tags_to_remove, $matches[1] );
  576. if ( empty( $tagnames ) ) {
  577. return $content;
  578. }
  579. $content = do_shortcodes_in_html_tags( $content, true, $tagnames );
  580. $pattern = get_shortcode_regex( $tagnames );
  581. $content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );
  582. // Always restore square braces so we don't break things like <!--[if IE ]>.
  583. $content = unescape_invalid_shortcodes( $content );
  584. return $content;
  585. }
  586. /**
  587. * Strips a shortcode tag based on RegEx matches against post content.
  588. *
  589. * @since 3.3.0
  590. *
  591. * @param array $m RegEx matches against post content.
  592. * @return string|false The content stripped of the tag, otherwise false.
  593. */
  594. function strip_shortcode_tag( $m ) {
  595. // Allow [[foo]] syntax for escaping a tag.
  596. if ( '[' === $m[1] && ']' === $m[6] ) {
  597. return substr( $m[0], 1, -1 );
  598. }
  599. return $m[1] . $m[6];
  600. }