[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> shortcodes.php (source)

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


Generated: Mon Jan 27 01:00:03 2020 Cross-referenced by PHPXref 0.7.1