shortcodes.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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://codex.wordpress.org/Shortcode_API
  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. foreach ( $matches as $shortcode ) {
  138. if ( $tag === $shortcode[2] ) {
  139. return true;
  140. } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. /**
  148. * Search content for shortcodes and filter shortcodes through their hooks.
  149. *
  150. * If there are no shortcode tags defined, then the content will be returned
  151. * without any filtering. This might cause issues when plugins are disabled but
  152. * the shortcode will still show up in the post or content.
  153. *
  154. * @since 2.5.0
  155. *
  156. * @global array $shortcode_tags List of shortcode tags and their callback hooks.
  157. *
  158. * @param string $content Content to search for shortcodes.
  159. * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
  160. * @return string Content with shortcodes filtered out.
  161. */
  162. function do_shortcode( $content, $ignore_html = false ) {
  163. global $shortcode_tags;
  164. if ( false === strpos( $content, '[' ) ) {
  165. return $content;
  166. }
  167. if (empty($shortcode_tags) || !is_array($shortcode_tags))
  168. return $content;
  169. // Find all registered tag names in $content.
  170. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
  171. $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
  172. if ( empty( $tagnames ) ) {
  173. return $content;
  174. }
  175. $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );
  176. $pattern = get_shortcode_regex( $tagnames );
  177. $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );
  178. // Always restore square braces so we don't break things like <!--[if IE ]>
  179. $content = unescape_invalid_shortcodes( $content );
  180. return $content;
  181. }
  182. /**
  183. * Retrieve the shortcode regular expression for searching.
  184. *
  185. * The regular expression combines the shortcode tags in the regular expression
  186. * in a regex class.
  187. *
  188. * The regular expression contains 6 different sub matches to help with parsing.
  189. *
  190. * 1 - An extra [ to allow for escaping shortcodes with double [[]]
  191. * 2 - The shortcode name
  192. * 3 - The shortcode argument list
  193. * 4 - The self closing /
  194. * 5 - The content of a shortcode when it wraps some content.
  195. * 6 - An extra ] to allow for escaping shortcodes with double [[]]
  196. *
  197. * @since 2.5.0
  198. * @since 4.4.0 Added the `$tagnames` parameter.
  199. *
  200. * @global array $shortcode_tags
  201. *
  202. * @param array $tagnames Optional. List of shortcodes to find. Defaults to all registered shortcodes.
  203. * @return string The shortcode search regular expression
  204. */
  205. function get_shortcode_regex( $tagnames = null ) {
  206. global $shortcode_tags;
  207. if ( empty( $tagnames ) ) {
  208. $tagnames = array_keys( $shortcode_tags );
  209. }
  210. $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
  211. // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
  212. // Also, see shortcode_unautop() and shortcode.js.
  213. return
  214. '\\[' // Opening bracket
  215. . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
  216. . "($tagregexp)" // 2: Shortcode name
  217. . '(?![\\w-])' // Not followed by word character or hyphen
  218. . '(' // 3: Unroll the loop: Inside the opening shortcode tag
  219. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  220. . '(?:'
  221. . '\\/(?!\\])' // A forward slash not followed by a closing bracket
  222. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  223. . ')*?'
  224. . ')'
  225. . '(?:'
  226. . '(\\/)' // 4: Self closing tag ...
  227. . '\\]' // ... and closing bracket
  228. . '|'
  229. . '\\]' // Closing bracket
  230. . '(?:'
  231. . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
  232. . '[^\\[]*+' // Not an opening bracket
  233. . '(?:'
  234. . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
  235. . '[^\\[]*+' // Not an opening bracket
  236. . ')*+'
  237. . ')'
  238. . '\\[\\/\\2\\]' // Closing shortcode tag
  239. . ')?'
  240. . ')'
  241. . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
  242. }
  243. /**
  244. * Regular Expression callable for do_shortcode() for calling shortcode hook.
  245. * @see get_shortcode_regex for details of the match array contents.
  246. *
  247. * @since 2.5.0
  248. * @access private
  249. *
  250. * @global array $shortcode_tags
  251. *
  252. * @param array $m Regular expression match array
  253. * @return string|false False on failure.
  254. */
  255. function do_shortcode_tag( $m ) {
  256. global $shortcode_tags;
  257. // allow [[foo]] syntax for escaping a tag
  258. if ( $m[1] == '[' && $m[6] == ']' ) {
  259. return substr($m[0], 1, -1);
  260. }
  261. $tag = $m[2];
  262. $attr = shortcode_parse_atts( $m[3] );
  263. if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
  264. /* translators: %s: shortcode tag */
  265. $message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
  266. _doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
  267. return $m[0];
  268. }
  269. /**
  270. * Filters whether to call a shortcode callback.
  271. *
  272. * Passing a truthy value to the filter will effectively short-circuit the
  273. * shortcode generation process, returning that value instead.
  274. *
  275. * @since 4.7.0
  276. *
  277. * @param bool|string $return Short-circuit return value. Either false or the value to replace the shortcode with.
  278. * @param string $tag Shortcode name.
  279. * @param array|string $attr Shortcode attributes array or empty string.
  280. * @param array $m Regular expression match array.
  281. */
  282. $return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m );
  283. if ( false !== $return ) {
  284. return $return;
  285. }
  286. $content = isset( $m[5] ) ? $m[5] : null;
  287. $output = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6];
  288. /**
  289. * Filters the output created by a shortcode callback.
  290. *
  291. * @since 4.7.0
  292. *
  293. * @param string $output Shortcode output.
  294. * @param string $tag Shortcode name.
  295. * @param array|string $attr Shortcode attributes array or empty string.
  296. * @param array $m Regular expression match array.
  297. */
  298. return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m );
  299. }
  300. /**
  301. * Search only inside HTML elements for shortcodes and process them.
  302. *
  303. * Any [ or ] characters remaining inside elements will be HTML encoded
  304. * to prevent interference with shortcodes that are outside the elements.
  305. * Assumes $content processed by KSES already. Users with unfiltered_html
  306. * capability may get unexpected output if angle braces are nested in tags.
  307. *
  308. * @since 4.2.3
  309. *
  310. * @param string $content Content to search for shortcodes
  311. * @param bool $ignore_html When true, all square braces inside elements will be encoded.
  312. * @param array $tagnames List of shortcodes to find.
  313. * @return string Content with shortcodes filtered out.
  314. */
  315. function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
  316. // Normalize entities in unfiltered HTML before adding placeholders.
  317. $trans = array( '&#91;' => '&#091;', '&#93;' => '&#093;' );
  318. $content = strtr( $content, $trans );
  319. $trans = array( '[' => '&#91;', ']' => '&#93;' );
  320. $pattern = get_shortcode_regex( $tagnames );
  321. $textarr = wp_html_split( $content );
  322. foreach ( $textarr as &$element ) {
  323. if ( '' == $element || '<' !== $element[0] ) {
  324. continue;
  325. }
  326. $noopen = false === strpos( $element, '[' );
  327. $noclose = false === strpos( $element, ']' );
  328. if ( $noopen || $noclose ) {
  329. // This element does not contain shortcodes.
  330. if ( $noopen xor $noclose ) {
  331. // Need to encode stray [ or ] chars.
  332. $element = strtr( $element, $trans );
  333. }
  334. continue;
  335. }
  336. if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
  337. // Encode all [ and ] chars.
  338. $element = strtr( $element, $trans );
  339. continue;
  340. }
  341. $attributes = wp_kses_attr_parse( $element );
  342. if ( false === $attributes ) {
  343. // Some plugins are doing things like [name] <[email]>.
  344. if ( 1 === preg_match( '%^<\s*\[\[?[^\[\]]+\]%', $element ) ) {
  345. $element = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $element );
  346. }
  347. // Looks like we found some crazy unfiltered HTML. Skipping it for sanity.
  348. $element = strtr( $element, $trans );
  349. continue;
  350. }
  351. // Get element name
  352. $front = array_shift( $attributes );
  353. $back = array_pop( $attributes );
  354. $matches = array();
  355. preg_match('%[a-zA-Z0-9]+%', $front, $matches);
  356. $elname = $matches[0];
  357. // Look for shortcodes in each attribute separately.
  358. foreach ( $attributes as &$attr ) {
  359. $open = strpos( $attr, '[' );
  360. $close = strpos( $attr, ']' );
  361. if ( false === $open || false === $close ) {
  362. continue; // Go to next attribute. Square braces will be escaped at end of loop.
  363. }
  364. $double = strpos( $attr, '"' );
  365. $single = strpos( $attr, "'" );
  366. if ( ( false === $single || $open < $single ) && ( false === $double || $open < $double ) ) {
  367. // $attr like '[shortcode]' or 'name = [shortcode]' implies unfiltered_html.
  368. // In this specific situation we assume KSES did not run because the input
  369. // was written by an administrator, so we should avoid changing the output
  370. // and we do not need to run KSES here.
  371. $attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr );
  372. } else {
  373. // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'"
  374. // We do not know if $content was unfiltered. Assume KSES ran before shortcodes.
  375. $count = 0;
  376. $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count );
  377. if ( $count > 0 ) {
  378. // Sanitize the shortcode output using KSES.
  379. $new_attr = wp_kses_one_attr( $new_attr, $elname );
  380. if ( '' !== trim( $new_attr ) ) {
  381. // The shortcode is safe to use now.
  382. $attr = $new_attr;
  383. }
  384. }
  385. }
  386. }
  387. $element = $front . implode( '', $attributes ) . $back;
  388. // Now encode any remaining [ or ] chars.
  389. $element = strtr( $element, $trans );
  390. }
  391. $content = implode( '', $textarr );
  392. return $content;
  393. }
  394. /**
  395. * Remove placeholders added by do_shortcodes_in_html_tags().
  396. *
  397. * @since 4.2.3
  398. *
  399. * @param string $content Content to search for placeholders.
  400. * @return string Content with placeholders removed.
  401. */
  402. function unescape_invalid_shortcodes( $content ) {
  403. // Clean up entire string, avoids re-parsing HTML.
  404. $trans = array( '&#91;' => '[', '&#93;' => ']' );
  405. $content = strtr( $content, $trans );
  406. return $content;
  407. }
  408. /**
  409. * Retrieve the shortcode attributes regex.
  410. *
  411. * @since 4.4.0
  412. *
  413. * @return string The shortcode attribute regular expression
  414. */
  415. function get_shortcode_atts_regex() {
  416. return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
  417. }
  418. /**
  419. * Retrieve all attributes from the shortcodes tag.
  420. *
  421. * The attributes list has the attribute name as the key and the value of the
  422. * attribute as the value in the key/value pair. This allows for easier
  423. * retrieval of the attributes, since all attributes have to be known.
  424. *
  425. * @since 2.5.0
  426. *
  427. * @param string $text
  428. * @return array|string List of attribute values.
  429. * Returns empty array if trim( $text ) == '""'.
  430. * Returns empty string if trim( $text ) == ''.
  431. * All other matches are checked for not empty().
  432. */
  433. function shortcode_parse_atts($text) {
  434. $atts = array();
  435. $pattern = get_shortcode_atts_regex();
  436. $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
  437. if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
  438. foreach ($match as $m) {
  439. if (!empty($m[1]))
  440. $atts[strtolower($m[1])] = stripcslashes($m[2]);
  441. elseif (!empty($m[3]))
  442. $atts[strtolower($m[3])] = stripcslashes($m[4]);
  443. elseif (!empty($m[5]))
  444. $atts[strtolower($m[5])] = stripcslashes($m[6]);
  445. elseif (isset($m[7]) && strlen($m[7]))
  446. $atts[] = stripcslashes($m[7]);
  447. elseif (isset($m[8]) && strlen($m[8]))
  448. $atts[] = stripcslashes($m[8]);
  449. elseif (isset($m[9]))
  450. $atts[] = stripcslashes($m[9]);
  451. }
  452. // Reject any unclosed HTML elements
  453. foreach( $atts as &$value ) {
  454. if ( false !== strpos( $value, '<' ) ) {
  455. if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
  456. $value = '';
  457. }
  458. }
  459. }
  460. } else {
  461. $atts = ltrim($text);
  462. }
  463. return $atts;
  464. }
  465. /**
  466. * Combine user attributes with known attributes and fill in defaults when needed.
  467. *
  468. * The pairs should be considered to be all of the attributes which are
  469. * supported by the caller and given as a list. The returned attributes will
  470. * only contain the attributes in the $pairs list.
  471. *
  472. * If the $atts list has unsupported attributes, then they will be ignored and
  473. * removed from the final returned list.
  474. *
  475. * @since 2.5.0
  476. *
  477. * @param array $pairs Entire list of supported attributes and their defaults.
  478. * @param array $atts User defined attributes in shortcode tag.
  479. * @param string $shortcode Optional. The name of the shortcode, provided for context to enable filtering
  480. * @return array Combined and filtered attribute list.
  481. */
  482. function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
  483. $atts = (array)$atts;
  484. $out = array();
  485. foreach ($pairs as $name => $default) {
  486. if ( array_key_exists($name, $atts) )
  487. $out[$name] = $atts[$name];
  488. else
  489. $out[$name] = $default;
  490. }
  491. /**
  492. * Filters a shortcode's default attributes.
  493. *
  494. * If the third parameter of the shortcode_atts() function is present then this filter is available.
  495. * The third parameter, $shortcode, is the name of the shortcode.
  496. *
  497. * @since 3.6.0
  498. * @since 4.4.0 Added the `$shortcode` parameter.
  499. *
  500. * @param array $out The output array of shortcode attributes.
  501. * @param array $pairs The supported attributes and their defaults.
  502. * @param array $atts The user defined shortcode attributes.
  503. * @param string $shortcode The shortcode name.
  504. */
  505. if ( $shortcode ) {
  506. $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts, $shortcode );
  507. }
  508. return $out;
  509. }
  510. /**
  511. * Remove all shortcode tags from the given content.
  512. *
  513. * @since 2.5.0
  514. *
  515. * @global array $shortcode_tags
  516. *
  517. * @param string $content Content to remove shortcode tags.
  518. * @return string Content without shortcode tags.
  519. */
  520. function strip_shortcodes( $content ) {
  521. global $shortcode_tags;
  522. if ( false === strpos( $content, '[' ) ) {
  523. return $content;
  524. }
  525. if (empty($shortcode_tags) || !is_array($shortcode_tags))
  526. return $content;
  527. // Find all registered tag names in $content.
  528. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
  529. $tags_to_remove = array_keys( $shortcode_tags );
  530. /**
  531. * Filters the list of shortcode tags to remove from the content.
  532. *
  533. * @since 4.7.0
  534. *
  535. * @param array $tag_array Array of shortcode tags to remove.
  536. * @param string $content Content shortcodes are being removed from.
  537. */
  538. $tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content );
  539. $tagnames = array_intersect( $tags_to_remove, $matches[1] );
  540. if ( empty( $tagnames ) ) {
  541. return $content;
  542. }
  543. $content = do_shortcodes_in_html_tags( $content, true, $tagnames );
  544. $pattern = get_shortcode_regex( $tagnames );
  545. $content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );
  546. // Always restore square braces so we don't break things like <!--[if IE ]>
  547. $content = unescape_invalid_shortcodes( $content );
  548. return $content;
  549. }
  550. /**
  551. * Strips a shortcode tag based on RegEx matches against post content.
  552. *
  553. * @since 3.3.0
  554. *
  555. * @param array $m RegEx matches against post content.
  556. * @return string|false The content stripped of the tag, otherwise false.
  557. */
  558. function strip_shortcode_tag( $m ) {
  559. // allow [[foo]] syntax for escaping a tag
  560. if ( $m[1] == '[' && $m[6] == ']' ) {
  561. return substr($m[0], 1, -1);
  562. }
  563. return $m[1] . $m[6];
  564. }