[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
   4   * Copyright (C) 2002, 2003, 2005  Ulf Harnhammar
   5   *
   6   * This program is free software and open source software; you can redistribute
   7   * it and/or modify it under the terms of the GNU General Public License as
   8   * published by the Free Software Foundation; either version 2 of the License,
   9   * or (at your option) any later version.
  10   *
  11   * This program is distributed in the hope that it will be useful, but WITHOUT
  12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14   * more details.
  15   *
  16   * You should have received a copy of the GNU General Public License along
  17   * with this program; if not, write to the Free Software Foundation, Inc.,
  18   * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19   * http://www.gnu.org/licenses/gpl.html
  20   *
  21   * [kses strips evil scripts!]
  22   *
  23   * Added wp_ prefix to avoid conflicts with existing kses users
  24   *
  25   * @version 0.2.2
  26   * @copyright (C) 2002, 2003, 2005
  27   * @author Ulf Harnhammar <http://advogato.org/person/metaur/>
  28   *
  29   * @package External
  30   * @subpackage KSES
  31   */
  32  
  33  /**
  34   * Specifies the default allowable HTML tags.
  35   *
  36   * Using `CUSTOM_TAGS` is not recommended and should be considered deprecated. The
  37   * {@see 'wp_kses_allowed_html'} filter is more powerful and supplies context.
  38   *
  39   * @see wp_kses_allowed_html()
  40   * @since 1.2.0
  41   *
  42   * @var array[]|bool Array of default allowable HTML tags, or false to use the defaults.
  43   */
  44  if ( ! defined( 'CUSTOM_TAGS' ) ) {
  45      define( 'CUSTOM_TAGS', false );
  46  }
  47  
  48  // Ensure that these variables are added to the global namespace
  49  // (e.g. if using namespaces / autoload in the current PHP environment).
  50  global $allowedposttags, $allowedtags, $allowedentitynames, $allowedxmlentitynames;
  51  
  52  if ( ! CUSTOM_TAGS ) {
  53      /**
  54       * KSES global for default allowable HTML tags.
  55       *
  56       * Can be overridden with the `CUSTOM_TAGS` constant.
  57       *
  58       * @var array[] $allowedposttags Array of default allowable HTML tags.
  59       * @since 2.0.0
  60       */
  61      $allowedposttags = array(
  62          'address'    => array(),
  63          'a'          => array(
  64              'href'     => true,
  65              'rel'      => true,
  66              'rev'      => true,
  67              'name'     => true,
  68              'target'   => true,
  69              'download' => array(
  70                  'valueless' => 'y',
  71              ),
  72          ),
  73          'abbr'       => array(),
  74          'acronym'    => array(),
  75          'area'       => array(
  76              'alt'    => true,
  77              'coords' => true,
  78              'href'   => true,
  79              'nohref' => true,
  80              'shape'  => true,
  81              'target' => true,
  82          ),
  83          'article'    => array(
  84              'align'    => true,
  85              'dir'      => true,
  86              'lang'     => true,
  87              'xml:lang' => true,
  88          ),
  89          'aside'      => array(
  90              'align'    => true,
  91              'dir'      => true,
  92              'lang'     => true,
  93              'xml:lang' => true,
  94          ),
  95          'audio'      => array(
  96              'autoplay' => true,
  97              'controls' => true,
  98              'loop'     => true,
  99              'muted'    => true,
 100              'preload'  => true,
 101              'src'      => true,
 102          ),
 103          'b'          => array(),
 104          'bdo'        => array(
 105              'dir' => true,
 106          ),
 107          'big'        => array(),
 108          'blockquote' => array(
 109              'cite'     => true,
 110              'lang'     => true,
 111              'xml:lang' => true,
 112          ),
 113          'br'         => array(),
 114          'button'     => array(
 115              'disabled' => true,
 116              'name'     => true,
 117              'type'     => true,
 118              'value'    => true,
 119          ),
 120          'caption'    => array(
 121              'align' => true,
 122          ),
 123          'cite'       => array(
 124              'dir'  => true,
 125              'lang' => true,
 126          ),
 127          'code'       => array(),
 128          'col'        => array(
 129              'align'   => true,
 130              'char'    => true,
 131              'charoff' => true,
 132              'span'    => true,
 133              'dir'     => true,
 134              'valign'  => true,
 135              'width'   => true,
 136          ),
 137          'colgroup'   => array(
 138              'align'   => true,
 139              'char'    => true,
 140              'charoff' => true,
 141              'span'    => true,
 142              'valign'  => true,
 143              'width'   => true,
 144          ),
 145          'del'        => array(
 146              'datetime' => true,
 147          ),
 148          'dd'         => array(),
 149          'dfn'        => array(),
 150          'details'    => array(
 151              'align'    => true,
 152              'dir'      => true,
 153              'lang'     => true,
 154              'open'     => true,
 155              'xml:lang' => true,
 156          ),
 157          'div'        => array(
 158              'align'    => true,
 159              'dir'      => true,
 160              'lang'     => true,
 161              'xml:lang' => true,
 162          ),
 163          'dl'         => array(),
 164          'dt'         => array(),
 165          'em'         => array(),
 166          'fieldset'   => array(),
 167          'figure'     => array(
 168              'align'    => true,
 169              'dir'      => true,
 170              'lang'     => true,
 171              'xml:lang' => true,
 172          ),
 173          'figcaption' => array(
 174              'align'    => true,
 175              'dir'      => true,
 176              'lang'     => true,
 177              'xml:lang' => true,
 178          ),
 179          'font'       => array(
 180              'color' => true,
 181              'face'  => true,
 182              'size'  => true,
 183          ),
 184          'footer'     => array(
 185              'align'    => true,
 186              'dir'      => true,
 187              'lang'     => true,
 188              'xml:lang' => true,
 189          ),
 190          'h1'         => array(
 191              'align' => true,
 192          ),
 193          'h2'         => array(
 194              'align' => true,
 195          ),
 196          'h3'         => array(
 197              'align' => true,
 198          ),
 199          'h4'         => array(
 200              'align' => true,
 201          ),
 202          'h5'         => array(
 203              'align' => true,
 204          ),
 205          'h6'         => array(
 206              'align' => true,
 207          ),
 208          'header'     => array(
 209              'align'    => true,
 210              'dir'      => true,
 211              'lang'     => true,
 212              'xml:lang' => true,
 213          ),
 214          'hgroup'     => array(
 215              'align'    => true,
 216              'dir'      => true,
 217              'lang'     => true,
 218              'xml:lang' => true,
 219          ),
 220          'hr'         => array(
 221              'align'   => true,
 222              'noshade' => true,
 223              'size'    => true,
 224              'width'   => true,
 225          ),
 226          'i'          => array(),
 227          'img'        => array(
 228              'alt'      => true,
 229              'align'    => true,
 230              'border'   => true,
 231              'height'   => true,
 232              'hspace'   => true,
 233              'longdesc' => true,
 234              'vspace'   => true,
 235              'src'      => true,
 236              'usemap'   => true,
 237              'width'    => true,
 238          ),
 239          'ins'        => array(
 240              'datetime' => true,
 241              'cite'     => true,
 242          ),
 243          'kbd'        => array(),
 244          'label'      => array(
 245              'for' => true,
 246          ),
 247          'legend'     => array(
 248              'align' => true,
 249          ),
 250          'li'         => array(
 251              'align' => true,
 252              'value' => true,
 253          ),
 254          'map'        => array(
 255              'name' => true,
 256          ),
 257          'mark'       => array(),
 258          'menu'       => array(
 259              'type' => true,
 260          ),
 261          'nav'        => array(
 262              'align'    => true,
 263              'dir'      => true,
 264              'lang'     => true,
 265              'xml:lang' => true,
 266          ),
 267          'p'          => array(
 268              'align'    => true,
 269              'dir'      => true,
 270              'lang'     => true,
 271              'xml:lang' => true,
 272          ),
 273          'pre'        => array(
 274              'width' => true,
 275          ),
 276          'q'          => array(
 277              'cite' => true,
 278          ),
 279          's'          => array(),
 280          'samp'       => array(),
 281          'span'       => array(
 282              'dir'      => true,
 283              'align'    => true,
 284              'lang'     => true,
 285              'xml:lang' => true,
 286          ),
 287          'section'    => array(
 288              'align'    => true,
 289              'dir'      => true,
 290              'lang'     => true,
 291              'xml:lang' => true,
 292          ),
 293          'small'      => array(),
 294          'strike'     => array(),
 295          'strong'     => array(),
 296          'sub'        => array(),
 297          'summary'    => array(
 298              'align'    => true,
 299              'dir'      => true,
 300              'lang'     => true,
 301              'xml:lang' => true,
 302          ),
 303          'sup'        => array(),
 304          'table'      => array(
 305              'align'       => true,
 306              'bgcolor'     => true,
 307              'border'      => true,
 308              'cellpadding' => true,
 309              'cellspacing' => true,
 310              'dir'         => true,
 311              'rules'       => true,
 312              'summary'     => true,
 313              'width'       => true,
 314          ),
 315          'tbody'      => array(
 316              'align'   => true,
 317              'char'    => true,
 318              'charoff' => true,
 319              'valign'  => true,
 320          ),
 321          'td'         => array(
 322              'abbr'    => true,
 323              'align'   => true,
 324              'axis'    => true,
 325              'bgcolor' => true,
 326              'char'    => true,
 327              'charoff' => true,
 328              'colspan' => true,
 329              'dir'     => true,
 330              'headers' => true,
 331              'height'  => true,
 332              'nowrap'  => true,
 333              'rowspan' => true,
 334              'scope'   => true,
 335              'valign'  => true,
 336              'width'   => true,
 337          ),
 338          'textarea'   => array(
 339              'cols'     => true,
 340              'rows'     => true,
 341              'disabled' => true,
 342              'name'     => true,
 343              'readonly' => true,
 344          ),
 345          'tfoot'      => array(
 346              'align'   => true,
 347              'char'    => true,
 348              'charoff' => true,
 349              'valign'  => true,
 350          ),
 351          'th'         => array(
 352              'abbr'    => true,
 353              'align'   => true,
 354              'axis'    => true,
 355              'bgcolor' => true,
 356              'char'    => true,
 357              'charoff' => true,
 358              'colspan' => true,
 359              'headers' => true,
 360              'height'  => true,
 361              'nowrap'  => true,
 362              'rowspan' => true,
 363              'scope'   => true,
 364              'valign'  => true,
 365              'width'   => true,
 366          ),
 367          'thead'      => array(
 368              'align'   => true,
 369              'char'    => true,
 370              'charoff' => true,
 371              'valign'  => true,
 372          ),
 373          'title'      => array(),
 374          'tr'         => array(
 375              'align'   => true,
 376              'bgcolor' => true,
 377              'char'    => true,
 378              'charoff' => true,
 379              'valign'  => true,
 380          ),
 381          'track'      => array(
 382              'default' => true,
 383              'kind'    => true,
 384              'label'   => true,
 385              'src'     => true,
 386              'srclang' => true,
 387          ),
 388          'tt'         => array(),
 389          'u'          => array(),
 390          'ul'         => array(
 391              'type' => true,
 392          ),
 393          'ol'         => array(
 394              'start'    => true,
 395              'type'     => true,
 396              'reversed' => true,
 397          ),
 398          'var'        => array(),
 399          'video'      => array(
 400              'autoplay'    => true,
 401              'controls'    => true,
 402              'height'      => true,
 403              'loop'        => true,
 404              'muted'       => true,
 405              'playsinline' => true,
 406              'poster'      => true,
 407              'preload'     => true,
 408              'src'         => true,
 409              'width'       => true,
 410          ),
 411      );
 412  
 413      /**
 414       * @var array[] $allowedtags Array of KSES allowed HTML elements.
 415       * @since 1.0.0
 416       */
 417      $allowedtags = array(
 418          'a'          => array(
 419              'href'  => true,
 420              'title' => true,
 421          ),
 422          'abbr'       => array(
 423              'title' => true,
 424          ),
 425          'acronym'    => array(
 426              'title' => true,
 427          ),
 428          'b'          => array(),
 429          'blockquote' => array(
 430              'cite' => true,
 431          ),
 432          'cite'       => array(),
 433          'code'       => array(),
 434          'del'        => array(
 435              'datetime' => true,
 436          ),
 437          'em'         => array(),
 438          'i'          => array(),
 439          'q'          => array(
 440              'cite' => true,
 441          ),
 442          's'          => array(),
 443          'strike'     => array(),
 444          'strong'     => array(),
 445      );
 446  
 447      /**
 448       * @var string[] $allowedentitynames Array of KSES allowed HTML entitity names.
 449       * @since 1.0.0
 450       */
 451      $allowedentitynames = array(
 452          'nbsp',
 453          'iexcl',
 454          'cent',
 455          'pound',
 456          'curren',
 457          'yen',
 458          'brvbar',
 459          'sect',
 460          'uml',
 461          'copy',
 462          'ordf',
 463          'laquo',
 464          'not',
 465          'shy',
 466          'reg',
 467          'macr',
 468          'deg',
 469          'plusmn',
 470          'acute',
 471          'micro',
 472          'para',
 473          'middot',
 474          'cedil',
 475          'ordm',
 476          'raquo',
 477          'iquest',
 478          'Agrave',
 479          'Aacute',
 480          'Acirc',
 481          'Atilde',
 482          'Auml',
 483          'Aring',
 484          'AElig',
 485          'Ccedil',
 486          'Egrave',
 487          'Eacute',
 488          'Ecirc',
 489          'Euml',
 490          'Igrave',
 491          'Iacute',
 492          'Icirc',
 493          'Iuml',
 494          'ETH',
 495          'Ntilde',
 496          'Ograve',
 497          'Oacute',
 498          'Ocirc',
 499          'Otilde',
 500          'Ouml',
 501          'times',
 502          'Oslash',
 503          'Ugrave',
 504          'Uacute',
 505          'Ucirc',
 506          'Uuml',
 507          'Yacute',
 508          'THORN',
 509          'szlig',
 510          'agrave',
 511          'aacute',
 512          'acirc',
 513          'atilde',
 514          'auml',
 515          'aring',
 516          'aelig',
 517          'ccedil',
 518          'egrave',
 519          'eacute',
 520          'ecirc',
 521          'euml',
 522          'igrave',
 523          'iacute',
 524          'icirc',
 525          'iuml',
 526          'eth',
 527          'ntilde',
 528          'ograve',
 529          'oacute',
 530          'ocirc',
 531          'otilde',
 532          'ouml',
 533          'divide',
 534          'oslash',
 535          'ugrave',
 536          'uacute',
 537          'ucirc',
 538          'uuml',
 539          'yacute',
 540          'thorn',
 541          'yuml',
 542          'quot',
 543          'amp',
 544          'lt',
 545          'gt',
 546          'apos',
 547          'OElig',
 548          'oelig',
 549          'Scaron',
 550          'scaron',
 551          'Yuml',
 552          'circ',
 553          'tilde',
 554          'ensp',
 555          'emsp',
 556          'thinsp',
 557          'zwnj',
 558          'zwj',
 559          'lrm',
 560          'rlm',
 561          'ndash',
 562          'mdash',
 563          'lsquo',
 564          'rsquo',
 565          'sbquo',
 566          'ldquo',
 567          'rdquo',
 568          'bdquo',
 569          'dagger',
 570          'Dagger',
 571          'permil',
 572          'lsaquo',
 573          'rsaquo',
 574          'euro',
 575          'fnof',
 576          'Alpha',
 577          'Beta',
 578          'Gamma',
 579          'Delta',
 580          'Epsilon',
 581          'Zeta',
 582          'Eta',
 583          'Theta',
 584          'Iota',
 585          'Kappa',
 586          'Lambda',
 587          'Mu',
 588          'Nu',
 589          'Xi',
 590          'Omicron',
 591          'Pi',
 592          'Rho',
 593          'Sigma',
 594          'Tau',
 595          'Upsilon',
 596          'Phi',
 597          'Chi',
 598          'Psi',
 599          'Omega',
 600          'alpha',
 601          'beta',
 602          'gamma',
 603          'delta',
 604          'epsilon',
 605          'zeta',
 606          'eta',
 607          'theta',
 608          'iota',
 609          'kappa',
 610          'lambda',
 611          'mu',
 612          'nu',
 613          'xi',
 614          'omicron',
 615          'pi',
 616          'rho',
 617          'sigmaf',
 618          'sigma',
 619          'tau',
 620          'upsilon',
 621          'phi',
 622          'chi',
 623          'psi',
 624          'omega',
 625          'thetasym',
 626          'upsih',
 627          'piv',
 628          'bull',
 629          'hellip',
 630          'prime',
 631          'Prime',
 632          'oline',
 633          'frasl',
 634          'weierp',
 635          'image',
 636          'real',
 637          'trade',
 638          'alefsym',
 639          'larr',
 640          'uarr',
 641          'rarr',
 642          'darr',
 643          'harr',
 644          'crarr',
 645          'lArr',
 646          'uArr',
 647          'rArr',
 648          'dArr',
 649          'hArr',
 650          'forall',
 651          'part',
 652          'exist',
 653          'empty',
 654          'nabla',
 655          'isin',
 656          'notin',
 657          'ni',
 658          'prod',
 659          'sum',
 660          'minus',
 661          'lowast',
 662          'radic',
 663          'prop',
 664          'infin',
 665          'ang',
 666          'and',
 667          'or',
 668          'cap',
 669          'cup',
 670          'int',
 671          'sim',
 672          'cong',
 673          'asymp',
 674          'ne',
 675          'equiv',
 676          'le',
 677          'ge',
 678          'sub',
 679          'sup',
 680          'nsub',
 681          'sube',
 682          'supe',
 683          'oplus',
 684          'otimes',
 685          'perp',
 686          'sdot',
 687          'lceil',
 688          'rceil',
 689          'lfloor',
 690          'rfloor',
 691          'lang',
 692          'rang',
 693          'loz',
 694          'spades',
 695          'clubs',
 696          'hearts',
 697          'diams',
 698          'sup1',
 699          'sup2',
 700          'sup3',
 701          'frac14',
 702          'frac12',
 703          'frac34',
 704          'there4',
 705      );
 706  
 707      /**
 708       * @var string[] $allowedxmlentitynames Array of KSES allowed XML entitity names.
 709       * @since 5.5.0
 710       */
 711      $allowedxmlnamedentities = array(
 712          'amp',
 713          'lt',
 714          'gt',
 715          'apos',
 716          'quot',
 717      );
 718  
 719      $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags );
 720  } else {
 721      $allowedtags     = wp_kses_array_lc( $allowedtags );
 722      $allowedposttags = wp_kses_array_lc( $allowedposttags );
 723  }
 724  
 725  /**
 726   * Filters text content and strips out disallowed HTML.
 727   *
 728   * This function makes sure that only the allowed HTML element names, attribute
 729   * names, attribute values, and HTML entities will occur in the given text string.
 730   *
 731   * This function expects unslashed data.
 732   *
 733   * @see wp_kses_post() for specifically filtering post content and fields.
 734   * @see wp_allowed_protocols() for the default allowed protocols in link URLs.
 735   *
 736   * @since 1.0.0
 737   *
 738   * @param string         $string            Text content to filter.
 739   * @param array[]|string $allowed_html      An array of allowed HTML elements and attributes, or a
 740   *                                          context name such as 'post'.
 741   * @param string[]       $allowed_protocols Array of allowed URL protocols.
 742   * @return string Filtered content containing only the allowed HTML.
 743   */
 744  function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) {
 745      if ( empty( $allowed_protocols ) ) {
 746          $allowed_protocols = wp_allowed_protocols();
 747      }
 748      $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
 749      $string = wp_kses_normalize_entities( $string );
 750      $string = wp_kses_hook( $string, $allowed_html, $allowed_protocols );
 751      return wp_kses_split( $string, $allowed_html, $allowed_protocols );
 752  }
 753  
 754  /**
 755   * Filters one HTML attribute and ensures its value is allowed.
 756   *
 757   * This function can escape data in some situations where `wp_kses()` must strip the whole attribute.
 758   *
 759   * @since 4.2.3
 760   *
 761   * @param string $string  The 'whole' attribute, including name and value.
 762   * @param string $element The HTML element name to which the attribute belongs.
 763   * @return string Filtered attribute.
 764   */
 765  function wp_kses_one_attr( $string, $element ) {
 766      $uris              = wp_kses_uri_attributes();
 767      $allowed_html      = wp_kses_allowed_html( 'post' );
 768      $allowed_protocols = wp_allowed_protocols();
 769      $string            = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
 770  
 771      // Preserve leading and trailing whitespace.
 772      $matches = array();
 773      preg_match( '/^\s*/', $string, $matches );
 774      $lead = $matches[0];
 775      preg_match( '/\s*$/', $string, $matches );
 776      $trail = $matches[0];
 777      if ( empty( $trail ) ) {
 778          $string = substr( $string, strlen( $lead ) );
 779      } else {
 780          $string = substr( $string, strlen( $lead ), -strlen( $trail ) );
 781      }
 782  
 783      // Parse attribute name and value from input.
 784      $split = preg_split( '/\s*=\s*/', $string, 2 );
 785      $name  = $split[0];
 786      if ( count( $split ) == 2 ) {
 787          $value = $split[1];
 788  
 789          // Remove quotes surrounding $value.
 790          // Also guarantee correct quoting in $string for this one attribute.
 791          if ( '' === $value ) {
 792              $quote = '';
 793          } else {
 794              $quote = $value[0];
 795          }
 796          if ( '"' === $quote || "'" === $quote ) {
 797              if ( substr( $value, -1 ) != $quote ) {
 798                  return '';
 799              }
 800              $value = substr( $value, 1, -1 );
 801          } else {
 802              $quote = '"';
 803          }
 804  
 805          // Sanitize quotes, angle braces, and entities.
 806          $value = esc_attr( $value );
 807  
 808          // Sanitize URI values.
 809          if ( in_array( strtolower( $name ), $uris, true ) ) {
 810              $value = wp_kses_bad_protocol( $value, $allowed_protocols );
 811          }
 812  
 813          $string = "$name=$quote$value$quote";
 814          $vless  = 'n';
 815      } else {
 816          $value = '';
 817          $vless = 'y';
 818      }
 819  
 820      // Sanitize attribute by name.
 821      wp_kses_attr_check( $name, $value, $string, $vless, $element, $allowed_html );
 822  
 823      // Restore whitespace.
 824      return $lead . $string . $trail;
 825  }
 826  
 827  /**
 828   * Returns an array of allowed HTML tags and attributes for a given context.
 829   *
 830   * @since 3.5.0
 831   * @since 5.0.1 `form` removed as allowable HTML tag.
 832   *
 833   * @global array $allowedposttags
 834   * @global array $allowedtags
 835   * @global array $allowedentitynames
 836   *
 837   * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
 838   *                              'strip', 'data', 'entities', or the name of a field filter such as
 839   *                              'pre_user_description'.
 840   * @return array Array of allowed HTML tags and their allowed attributes.
 841   */
 842  function wp_kses_allowed_html( $context = '' ) {
 843      global $allowedposttags, $allowedtags, $allowedentitynames;
 844  
 845      if ( is_array( $context ) ) {
 846          /**
 847           * Filters the HTML that is allowed for a given context.
 848           *
 849           * @since 3.5.0
 850           *
 851           * @param array[]|string $context      Context to judge allowed tags by.
 852           * @param string         $context_type Context name.
 853           */
 854          return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' );
 855      }
 856  
 857      switch ( $context ) {
 858          case 'post':
 859              /** This filter is documented in wp-includes/kses.php */
 860              $tags = apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context );
 861  
 862              // 5.0.1 removed the `<form>` tag, allow it if a filter is allowing it's sub-elements `<input>` or `<select>`.
 863              if ( ! CUSTOM_TAGS && ! isset( $tags['form'] ) && ( isset( $tags['input'] ) || isset( $tags['select'] ) ) ) {
 864                  $tags = $allowedposttags;
 865  
 866                  $tags['form'] = array(
 867                      'action'         => true,
 868                      'accept'         => true,
 869                      'accept-charset' => true,
 870                      'enctype'        => true,
 871                      'method'         => true,
 872                      'name'           => true,
 873                      'target'         => true,
 874                  );
 875  
 876                  /** This filter is documented in wp-includes/kses.php */
 877                  $tags = apply_filters( 'wp_kses_allowed_html', $tags, $context );
 878              }
 879  
 880              return $tags;
 881  
 882          case 'user_description':
 883          case 'pre_user_description':
 884              $tags             = $allowedtags;
 885              $tags['a']['rel'] = true;
 886              /** This filter is documented in wp-includes/kses.php */
 887              return apply_filters( 'wp_kses_allowed_html', $tags, $context );
 888  
 889          case 'strip':
 890              /** This filter is documented in wp-includes/kses.php */
 891              return apply_filters( 'wp_kses_allowed_html', array(), $context );
 892  
 893          case 'entities':
 894              /** This filter is documented in wp-includes/kses.php */
 895              return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context );
 896  
 897          case 'data':
 898          default:
 899              /** This filter is documented in wp-includes/kses.php */
 900              return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context );
 901      }
 902  }
 903  
 904  /**
 905   * You add any KSES hooks here.
 906   *
 907   * There is currently only one KSES WordPress hook, {@see 'pre_kses'}, and it is called here.
 908   * All parameters are passed to the hooks and expected to receive a string.
 909   *
 910   * @since 1.0.0
 911   *
 912   * @param string          $string            Content to filter through KSES.
 913   * @param array[]|string  $allowed_html      List of allowed HTML elements.
 914   * @param string[]        $allowed_protocols Array of allowed URL protocols.
 915   * @return string Filtered content through {@see 'pre_kses'} hook.
 916   */
 917  function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) {
 918      /**
 919       * Filters content to be run through kses.
 920       *
 921       * @since 2.3.0
 922       *
 923       * @param string          $string            Content to run through KSES.
 924       * @param array[]|string  $allowed_html      Allowed HTML elements.
 925       * @param string[]        $allowed_protocols Array of allowed URL protocols.
 926       */
 927      return apply_filters( 'pre_kses', $string, $allowed_html, $allowed_protocols );
 928  }
 929  
 930  /**
 931   * Returns the version number of KSES.
 932   *
 933   * @since 1.0.0
 934   *
 935   * @return string KSES version number.
 936   */
 937  function wp_kses_version() {
 938      return '0.2.2';
 939  }
 940  
 941  /**
 942   * Searches for HTML tags, no matter how malformed.
 943   *
 944   * It also matches stray `>` characters.
 945   *
 946   * @since 1.0.0
 947   *
 948   * @global array $pass_allowed_html
 949   * @global array $pass_allowed_protocols
 950   *
 951   * @param string   $string            Content to filter.
 952   * @param array    $allowed_html      Allowed HTML elements.
 953   * @param string[] $allowed_protocols Array of allowed URL protocols.
 954   * @return string Content with fixed HTML tags
 955   */
 956  function wp_kses_split( $string, $allowed_html, $allowed_protocols ) {
 957      global $pass_allowed_html, $pass_allowed_protocols;
 958      $pass_allowed_html      = $allowed_html;
 959      $pass_allowed_protocols = $allowed_protocols;
 960      return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string );
 961  }
 962  
 963  /**
 964   * Returns an array of HTML attribute names whose value contains a URL.
 965   *
 966   * This function returns a list of all HTML attributes that must contain
 967   * a URL according to the HTML specification.
 968   *
 969   * This list includes URI attributes both allowed and disallowed by KSES.
 970   *
 971   * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
 972   *
 973   * @since 5.0.1
 974   *
 975   * @return string[] HTML attribute names whose value contains a URL.
 976   */
 977  function wp_kses_uri_attributes() {
 978      $uri_attributes = array(
 979          'action',
 980          'archive',
 981          'background',
 982          'cite',
 983          'classid',
 984          'codebase',
 985          'data',
 986          'formaction',
 987          'href',
 988          'icon',
 989          'longdesc',
 990          'manifest',
 991          'poster',
 992          'profile',
 993          'src',
 994          'usemap',
 995          'xmlns',
 996      );
 997  
 998      /**
 999       * Filters the list of attributes that are required to contain a URL.
1000       *
1001       * Use this filter to add any `data-` attributes that are required to be
1002       * validated as a URL.
1003       *
1004       * @since 5.0.1
1005       *
1006       * @param string[] $uri_attributes HTML attribute names whose value contains a URL.
1007       */
1008      $uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );
1009  
1010      return $uri_attributes;
1011  }
1012  
1013  /**
1014   * Callback for `wp_kses_split()`.
1015   *
1016   * @since 3.1.0
1017   * @access private
1018   * @ignore
1019   *
1020   * @global array $pass_allowed_html
1021   * @global array $pass_allowed_protocols
1022   *
1023   * @return string
1024   */
1025  function _wp_kses_split_callback( $match ) {
1026      global $pass_allowed_html, $pass_allowed_protocols;
1027      return wp_kses_split2( $match[0], $pass_allowed_html, $pass_allowed_protocols );
1028  }
1029  
1030  /**
1031   * Callback for `wp_kses_split()` for fixing malformed HTML tags.
1032   *
1033   * This function does a lot of work. It rejects some very malformed things like
1034   * `<:::>`. It returns an empty string, if the element isn't allowed (look ma, no
1035   * `strip_tags()`!). Otherwise it splits the tag into an element and an attribute
1036   * list.
1037   *
1038   * After the tag is split into an element and an attribute list, it is run
1039   * through another filter which will remove illegal attributes and once that is
1040   * completed, will be returned.
1041   *
1042   * @access private
1043   * @ignore
1044   * @since 1.0.0
1045   *
1046   * @param string   $string            Content to filter.
1047   * @param array    $allowed_html      Allowed HTML elements.
1048   * @param string[] $allowed_protocols Array of allowed URL protocols.
1049   * @return string Fixed HTML element
1050   */
1051  function wp_kses_split2( $string, $allowed_html, $allowed_protocols ) {
1052      $string = wp_kses_stripslashes( $string );
1053  
1054      // It matched a ">" character.
1055      if ( '<' !== substr( $string, 0, 1 ) ) {
1056          return '&gt;';
1057      }
1058  
1059      // Allow HTML comments.
1060      if ( '<!--' === substr( $string, 0, 4 ) ) {
1061          $string = str_replace( array( '<!--', '-->' ), '', $string );
1062          while ( ( $newstring = wp_kses( $string, $allowed_html, $allowed_protocols ) ) != $string ) {
1063              $string = $newstring;
1064          }
1065          if ( '' === $string ) {
1066              return '';
1067          }
1068          // Prevent multiple dashes in comments.
1069          $string = preg_replace( '/--+/', '-', $string );
1070          // Prevent three dashes closing a comment.
1071          $string = preg_replace( '/-$/', '', $string );
1072          return "<!--{$string}-->";
1073      }
1074  
1075      // It's seriously malformed.
1076      if ( ! preg_match( '%^<\s*(/\s*)?([a-zA-Z0-9-]+)([^>]*)>?$%', $string, $matches ) ) {
1077          return '';
1078      }
1079  
1080      $slash    = trim( $matches[1] );
1081      $elem     = $matches[2];
1082      $attrlist = $matches[3];
1083  
1084      if ( ! is_array( $allowed_html ) ) {
1085          $allowed_html = wp_kses_allowed_html( $allowed_html );
1086      }
1087  
1088      // They are using a not allowed HTML element.
1089      if ( ! isset( $allowed_html[ strtolower( $elem ) ] ) ) {
1090          return '';
1091      }
1092  
1093      // No attributes are allowed for closing elements.
1094      if ( '' !== $slash ) {
1095          return "</$elem>";
1096      }
1097  
1098      return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols );
1099  }
1100  
1101  /**
1102   * Removes all attributes, if none are allowed for this element.
1103   *
1104   * If some are allowed it calls `wp_kses_hair()` to split them further, and then
1105   * it builds up new HTML code from the data that `kses_hair()` returns. It also
1106   * removes `<` and `>` characters, if there are any left. One more thing it does
1107   * is to check if the tag has a closing XHTML slash, and if it does, it puts one
1108   * in the returned code as well.
1109   *
1110   * @since 1.0.0
1111   *
1112   * @param string   $element           HTML element/tag.
1113   * @param string   $attr              HTML attributes from HTML element to closing HTML element tag.
1114   * @param array    $allowed_html      Allowed HTML elements.
1115   * @param string[] $allowed_protocols Array of allowed URL protocols.
1116   * @return string Sanitized HTML element.
1117   */
1118  function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
1119      if ( ! is_array( $allowed_html ) ) {
1120          $allowed_html = wp_kses_allowed_html( $allowed_html );
1121      }
1122  
1123      // Is there a closing XHTML slash at the end of the attributes?
1124      $xhtml_slash = '';
1125      if ( preg_match( '%\s*/\s*$%', $attr ) ) {
1126          $xhtml_slash = ' /';
1127      }
1128  
1129      // Are any attributes allowed at all for this element?
1130      $element_low = strtolower( $element );
1131      if ( empty( $allowed_html[ $element_low ] ) || true === $allowed_html[ $element_low ] ) {
1132          return "<$element$xhtml_slash>";
1133      }
1134  
1135      // Split it.
1136      $attrarr = wp_kses_hair( $attr, $allowed_protocols );
1137  
1138      // Go through $attrarr, and save the allowed attributes for this element
1139      // in $attr2.
1140      $attr2 = '';
1141      foreach ( $attrarr as $arreach ) {
1142          if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) {
1143              $attr2 .= ' ' . $arreach['whole'];
1144          }
1145      }
1146  
1147      // Remove any "<" or ">" characters.
1148      $attr2 = preg_replace( '/[<>]/', '', $attr2 );
1149  
1150      return "<$element$attr2$xhtml_slash>";
1151  }
1152  
1153  /**
1154   * Determines whether an attribute is allowed.
1155   *
1156   * @since 4.2.3
1157   * @since 5.0.0 Add support for `data-*` wildcard attributes.
1158   *
1159   * @param string $name         The attribute name. Passed by reference. Returns empty string when not allowed.
1160   * @param string $value        The attribute value. Passed by reference. Returns a filtered value.
1161   * @param string $whole        The `name=value` input. Passed by reference. Returns filtered input.
1162   * @param string $vless        Whether the attribute is valueless. Use 'y' or 'n'.
1163   * @param string $element      The name of the element to which this attribute belongs.
1164   * @param array  $allowed_html The full list of allowed elements and attributes.
1165   * @return bool Whether or not the attribute is allowed.
1166   */
1167  function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
1168      $name_low    = strtolower( $name );
1169      $element_low = strtolower( $element );
1170  
1171      if ( ! isset( $allowed_html[ $element_low ] ) ) {
1172          $name  = '';
1173          $value = '';
1174          $whole = '';
1175          return false;
1176      }
1177  
1178      $allowed_attr = $allowed_html[ $element_low ];
1179  
1180      if ( ! isset( $allowed_attr[ $name_low ] ) || '' === $allowed_attr[ $name_low ] ) {
1181          /*
1182           * Allow `data-*` attributes.
1183           *
1184           * When specifying `$allowed_html`, the attribute name should be set as
1185           * `data-*` (not to be mixed with the HTML 4.0 `data` attribute, see
1186           * https://www.w3.org/TR/html40/struct/objects.html#adef-data).
1187           *
1188           * Note: the attribute name should only contain `A-Za-z0-9_-` chars,
1189           * double hyphens `--` are not accepted by WordPress.
1190           */
1191          if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] ) && preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match ) ) {
1192              /*
1193               * Add the whole attribute name to the allowed attributes and set any restrictions
1194               * for the `data-*` attribute values for the current element.
1195               */
1196              $allowed_attr[ $match[0] ] = $allowed_attr['data-*'];
1197          } else {
1198              $name  = '';
1199              $value = '';
1200              $whole = '';
1201              return false;
1202          }
1203      }
1204  
1205      if ( 'style' === $name_low ) {
1206          $new_value = safecss_filter_attr( $value );
1207  
1208          if ( empty( $new_value ) ) {
1209              $name  = '';
1210              $value = '';
1211              $whole = '';
1212              return false;
1213          }
1214  
1215          $whole = str_replace( $value, $new_value, $whole );
1216          $value = $new_value;
1217      }
1218  
1219      if ( is_array( $allowed_attr[ $name_low ] ) ) {
1220          // There are some checks.
1221          foreach ( $allowed_attr[ $name_low ] as $currkey => $currval ) {
1222              if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) {
1223                  $name  = '';
1224                  $value = '';
1225                  $whole = '';
1226                  return false;
1227              }
1228          }
1229      }
1230  
1231      return true;
1232  }
1233  
1234  /**
1235   * Builds an attribute list from string containing attributes.
1236   *
1237   * This function does a lot of work. It parses an attribute list into an array
1238   * with attribute data, and tries to do the right thing even if it gets weird
1239   * input. It will add quotes around attribute values that don't have any quotes
1240   * or apostrophes around them, to make it easier to produce HTML code that will
1241   * conform to W3C's HTML specification. It will also remove bad URL protocols
1242   * from attribute values. It also reduces duplicate attributes by using the
1243   * attribute defined first (`foo='bar' foo='baz'` will result in `foo='bar'`).
1244   *
1245   * @since 1.0.0
1246   *
1247   * @param string   $attr              Attribute list from HTML element to closing HTML element tag.
1248   * @param string[] $allowed_protocols Array of allowed URL protocols.
1249   * @return array[] Array of attribute information after parsing.
1250   */
1251  function wp_kses_hair( $attr, $allowed_protocols ) {
1252      $attrarr  = array();
1253      $mode     = 0;
1254      $attrname = '';
1255      $uris     = wp_kses_uri_attributes();
1256  
1257      // Loop through the whole attribute list.
1258  
1259      while ( strlen( $attr ) != 0 ) {
1260          $working = 0; // Was the last operation successful?
1261  
1262          switch ( $mode ) {
1263              case 0:
1264                  if ( preg_match( '/^([_a-zA-Z][-_a-zA-Z0-9:.]*)/', $attr, $match ) ) {
1265                      $attrname = $match[1];
1266                      $working  = 1;
1267                      $mode     = 1;
1268                      $attr     = preg_replace( '/^[_a-zA-Z][-_a-zA-Z0-9:.]*/', '', $attr );
1269                  }
1270  
1271                  break;
1272  
1273              case 1:
1274                  if ( preg_match( '/^\s*=\s*/', $attr ) ) { // Equals sign.
1275                      $working = 1;
1276                      $mode    = 2;
1277                      $attr    = preg_replace( '/^\s*=\s*/', '', $attr );
1278                      break;
1279                  }
1280  
1281                  if ( preg_match( '/^\s+/', $attr ) ) { // Valueless.
1282                      $working = 1;
1283                      $mode    = 0;
1284                      if ( false === array_key_exists( $attrname, $attrarr ) ) {
1285                          $attrarr[ $attrname ] = array(
1286                              'name'  => $attrname,
1287                              'value' => '',
1288                              'whole' => $attrname,
1289                              'vless' => 'y',
1290                          );
1291                      }
1292                      $attr = preg_replace( '/^\s+/', '', $attr );
1293                  }
1294  
1295                  break;
1296  
1297              case 2:
1298                  if ( preg_match( '%^"([^"]*)"(\s+|/?$)%', $attr, $match ) ) {
1299                      // "value"
1300                      $thisval = $match[1];
1301                      if ( in_array( strtolower( $attrname ), $uris, true ) ) {
1302                          $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
1303                      }
1304  
1305                      if ( false === array_key_exists( $attrname, $attrarr ) ) {
1306                          $attrarr[ $attrname ] = array(
1307                              'name'  => $attrname,
1308                              'value' => $thisval,
1309                              'whole' => "$attrname=\"$thisval\"",
1310                              'vless' => 'n',
1311                          );
1312                      }
1313                      $working = 1;
1314                      $mode    = 0;
1315                      $attr    = preg_replace( '/^"[^"]*"(\s+|$)/', '', $attr );
1316                      break;
1317                  }
1318  
1319                  if ( preg_match( "%^'([^']*)'(\s+|/?$)%", $attr, $match ) ) {
1320                      // 'value'
1321                      $thisval = $match[1];
1322                      if ( in_array( strtolower( $attrname ), $uris, true ) ) {
1323                          $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
1324                      }
1325  
1326                      if ( false === array_key_exists( $attrname, $attrarr ) ) {
1327                          $attrarr[ $attrname ] = array(
1328                              'name'  => $attrname,
1329                              'value' => $thisval,
1330                              'whole' => "$attrname='$thisval'",
1331                              'vless' => 'n',
1332                          );
1333                      }
1334                      $working = 1;
1335                      $mode    = 0;
1336                      $attr    = preg_replace( "/^'[^']*'(\s+|$)/", '', $attr );
1337                      break;
1338                  }
1339  
1340                  if ( preg_match( "%^([^\s\"']+)(\s+|/?$)%", $attr, $match ) ) {
1341                      // value
1342                      $thisval = $match[1];
1343                      if ( in_array( strtolower( $attrname ), $uris, true ) ) {
1344                          $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
1345                      }
1346  
1347                      if ( false === array_key_exists( $attrname, $attrarr ) ) {
1348                          $attrarr[ $attrname ] = array(
1349                              'name'  => $attrname,
1350                              'value' => $thisval,
1351                              'whole' => "$attrname=\"$thisval\"",
1352                              'vless' => 'n',
1353                          );
1354                      }
1355                      // We add quotes to conform to W3C's HTML spec.
1356                      $working = 1;
1357                      $mode    = 0;
1358                      $attr    = preg_replace( "%^[^\s\"']+(\s+|$)%", '', $attr );
1359                  }
1360  
1361                  break;
1362          } // End switch.
1363  
1364          if ( 0 == $working ) { // Not well-formed, remove and try again.
1365              $attr = wp_kses_html_error( $attr );
1366              $mode = 0;
1367          }
1368      } // End while.
1369  
1370      if ( 1 == $mode && false === array_key_exists( $attrname, $attrarr ) ) {
1371          // Special case, for when the attribute list ends with a valueless
1372          // attribute like "selected".
1373          $attrarr[ $attrname ] = array(
1374              'name'  => $attrname,
1375              'value' => '',
1376              'whole' => $attrname,
1377              'vless' => 'y',
1378          );
1379      }
1380  
1381      return $attrarr;
1382  }
1383  
1384  /**
1385   * Finds all attributes of an HTML element.
1386   *
1387   * Does not modify input.  May return "evil" output.
1388   *
1389   * Based on `wp_kses_split2()` and `wp_kses_attr()`.
1390   *
1391   * @since 4.2.3
1392   *
1393   * @param string $element HTML element.
1394   * @return array|bool List of attributes found in the element. Returns false on failure.
1395   */
1396  function wp_kses_attr_parse( $element ) {
1397      $valid = preg_match( '%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches );
1398      if ( 1 !== $valid ) {
1399          return false;
1400      }
1401  
1402      $begin  = $matches[1];
1403      $slash  = $matches[2];
1404      $elname = $matches[3];
1405      $attr   = $matches[4];
1406      $end    = $matches[5];
1407  
1408      if ( '' !== $slash ) {
1409          // Closing elements do not get parsed.
1410          return false;
1411      }
1412  
1413      // Is there a closing XHTML slash at the end of the attributes?
1414      if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) {
1415          $xhtml_slash = $matches[0];
1416          $attr        = substr( $attr, 0, -strlen( $xhtml_slash ) );
1417      } else {
1418          $xhtml_slash = '';
1419      }
1420  
1421      // Split it.
1422      $attrarr = wp_kses_hair_parse( $attr );
1423      if ( false === $attrarr ) {
1424          return false;
1425      }
1426  
1427      // Make sure all input is returned by adding front and back matter.
1428      array_unshift( $attrarr, $begin . $slash . $elname );
1429      array_push( $attrarr, $xhtml_slash . $end );
1430  
1431      return $attrarr;
1432  }
1433  
1434  /**
1435   * Builds an attribute list from string containing attributes.
1436   *
1437   * Does not modify input.  May return "evil" output.
1438   * In case of unexpected input, returns false instead of stripping things.
1439   *
1440   * Based on `wp_kses_hair()` but does not return a multi-dimensional array.
1441   *
1442   * @since 4.2.3
1443   *
1444   * @param string $attr Attribute list from HTML element to closing HTML element tag.
1445   * @return array|bool List of attributes found in $attr. Returns false on failure.
1446   */
1447  function wp_kses_hair_parse( $attr ) {
1448      if ( '' === $attr ) {
1449          return array();
1450      }
1451  
1452      // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
1453      $regex =
1454          '(?:'
1455          .     '[_a-zA-Z][-_a-zA-Z0-9:.]*' // Attribute name.
1456          . '|'
1457          .     '\[\[?[^\[\]]+\]\]?'        // Shortcode in the name position implies unfiltered_html.
1458          . ')'
1459          . '(?:'               // Attribute value.
1460          .     '\s*=\s*'       // All values begin with '='.
1461          .     '(?:'
1462          .         '"[^"]*"'   // Double-quoted.
1463          .     '|'
1464          .         "'[^']*'"   // Single-quoted.
1465          .     '|'
1466          .         '[^\s"\']+' // Non-quoted.
1467          .         '(?:\s|$)'  // Must have a space.
1468          .     ')'
1469          . '|'
1470          .     '(?:\s|$)'      // If attribute has no value, space is required.
1471          . ')'
1472          . '\s*';              // Trailing space is optional except as mentioned above.
1473      // phpcs:enable
1474  
1475      // Although it is possible to reduce this procedure to a single regexp,
1476      // we must run that regexp twice to get exactly the expected result.
1477  
1478      $validation = "%^($regex)+$%";
1479      $extraction = "%$regex%";
1480  
1481      if ( 1 === preg_match( $validation, $attr ) ) {
1482          preg_match_all( $extraction, $attr, $attrarr );
1483          return $attrarr[0];
1484      } else {
1485          return false;
1486      }
1487  }
1488  
1489  /**
1490   * Performs different checks for attribute values.
1491   *
1492   * The currently implemented checks are "maxlen", "minlen", "maxval", "minval",
1493   * and "valueless".
1494   *
1495   * @since 1.0.0
1496   *
1497   * @param string $value      Attribute value.
1498   * @param string $vless      Whether the attribute is valueless. Use 'y' or 'n'.
1499   * @param string $checkname  What $checkvalue is checking for.
1500   * @param mixed  $checkvalue What constraint the value should pass.
1501   * @return bool Whether check passes.
1502   */
1503  function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) {
1504      $ok = true;
1505  
1506      switch ( strtolower( $checkname ) ) {
1507          case 'maxlen':
1508              /*
1509               * The maxlen check makes sure that the attribute value has a length not
1510               * greater than the given value. This can be used to avoid Buffer Overflows
1511               * in WWW clients and various Internet servers.
1512               */
1513  
1514              if ( strlen( $value ) > $checkvalue ) {
1515                  $ok = false;
1516              }
1517              break;
1518  
1519          case 'minlen':
1520              /*
1521               * The minlen check makes sure that the attribute value has a length not
1522               * smaller than the given value.
1523               */
1524  
1525              if ( strlen( $value ) < $checkvalue ) {
1526                  $ok = false;
1527              }
1528              break;
1529  
1530          case 'maxval':
1531              /*
1532               * The maxval check does two things: it checks that the attribute value is
1533               * an integer from 0 and up, without an excessive amount of zeroes or
1534               * whitespace (to avoid Buffer Overflows). It also checks that the attribute
1535               * value is not greater than the given value.
1536               * This check can be used to avoid Denial of Service attacks.
1537               */
1538  
1539              if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) {
1540                  $ok = false;
1541              }
1542              if ( $value > $checkvalue ) {
1543                  $ok = false;
1544              }
1545              break;
1546  
1547          case 'minval':
1548              /*
1549               * The minval check makes sure that the attribute value is a positive integer,
1550               * and that it is not smaller than the given value.
1551               */
1552  
1553              if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) {
1554                  $ok = false;
1555              }
1556              if ( $value < $checkvalue ) {
1557                  $ok = false;
1558              }
1559              break;
1560  
1561          case 'valueless':
1562              /*
1563               * The valueless check makes sure if the attribute has a value
1564               * (like `<a href="blah">`) or not (`<option selected>`). If the given value
1565               * is a "y" or a "Y", the attribute must not have a value.
1566               * If the given value is an "n" or an "N", the attribute must have a value.
1567               */
1568  
1569              if ( strtolower( $checkvalue ) != $vless ) {
1570                  $ok = false;
1571              }
1572              break;
1573      } // End switch.
1574  
1575      return $ok;
1576  }
1577  
1578  /**
1579   * Sanitizes a string and removed disallowed URL protocols.
1580   *
1581   * This function removes all non-allowed protocols from the beginning of the
1582   * string. It ignores whitespace and the case of the letters, and it does
1583   * understand HTML entities. It does its work recursively, so it won't be
1584   * fooled by a string like `javascript:javascript:alert(57)`.
1585   *
1586   * @since 1.0.0
1587   *
1588   * @param string   $string            Content to filter bad protocols from.
1589   * @param string[] $allowed_protocols Array of allowed URL protocols.
1590   * @return string Filtered content.
1591   */
1592  function wp_kses_bad_protocol( $string, $allowed_protocols ) {
1593      $string     = wp_kses_no_null( $string );
1594      $iterations = 0;
1595  
1596      do {
1597          $original_string = $string;
1598          $string          = wp_kses_bad_protocol_once( $string, $allowed_protocols );
1599      } while ( $original_string != $string && ++$iterations < 6 );
1600  
1601      if ( $original_string != $string ) {
1602          return '';
1603      }
1604  
1605      return $string;
1606  }
1607  
1608  /**
1609   * Removes any invalid control characters in a text string.
1610   *
1611   * Also removes any instance of the `\0` string.
1612   *
1613   * @since 1.0.0
1614   *
1615   * @param string $string  Content to filter null characters from.
1616   * @param array  $options Set 'slash_zero' => 'keep' when '\0' is allowed. Default is 'remove'.
1617   * @return string Filtered content.
1618   */
1619  function wp_kses_no_null( $string, $options = null ) {
1620      if ( ! isset( $options['slash_zero'] ) ) {
1621          $options = array( 'slash_zero' => 'remove' );
1622      }
1623  
1624      $string = preg_replace( '/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string );
1625      if ( 'remove' === $options['slash_zero'] ) {
1626          $string = preg_replace( '/\\\\+0+/', '', $string );
1627      }
1628  
1629      return $string;
1630  }
1631  
1632  /**
1633   * Strips slashes from in front of quotes.
1634   *
1635   * This function changes the character sequence `\"` to just `"`. It leaves all other
1636   * slashes alone. The quoting from `preg_replace(//e)` requires this.
1637   *
1638   * @since 1.0.0
1639   *
1640   * @param string $string String to strip slashes from.
1641   * @return string Fixed string with quoted slashes.
1642   */
1643  function wp_kses_stripslashes( $string ) {
1644      return preg_replace( '%\\\\"%', '"', $string );
1645  }
1646  
1647  /**
1648   * Converts the keys of an array to lowercase.
1649   *
1650   * @since 1.0.0
1651   *
1652   * @param array $inarray Unfiltered array.
1653   * @return array Fixed array with all lowercase keys.
1654   */
1655  function wp_kses_array_lc( $inarray ) {
1656      $outarray = array();
1657  
1658      foreach ( (array) $inarray as $inkey => $inval ) {
1659          $outkey              = strtolower( $inkey );
1660          $outarray[ $outkey ] = array();
1661  
1662          foreach ( (array) $inval as $inkey2 => $inval2 ) {
1663              $outkey2                         = strtolower( $inkey2 );
1664              $outarray[ $outkey ][ $outkey2 ] = $inval2;
1665          }
1666      }
1667  
1668      return $outarray;
1669  }
1670  
1671  /**
1672   * Handles parsing errors in `wp_kses_hair()`.
1673   *
1674   * The general plan is to remove everything to and including some whitespace,
1675   * but it deals with quotes and apostrophes as well.
1676   *
1677   * @since 1.0.0
1678   *
1679   * @param string $string
1680   * @return string
1681   */
1682  function wp_kses_html_error( $string ) {
1683      return preg_replace( '/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string );
1684  }
1685  
1686  /**
1687   * Sanitizes content from bad protocols and other characters.
1688   *
1689   * This function searches for URL protocols at the beginning of the string, while
1690   * handling whitespace and HTML entities.
1691   *
1692   * @since 1.0.0
1693   *
1694   * @param string   $string            Content to check for bad protocols.
1695   * @param string[] $allowed_protocols Array of allowed URL protocols.
1696   * @return string Sanitized content.
1697   */
1698  function wp_kses_bad_protocol_once( $string, $allowed_protocols, $count = 1 ) {
1699      $string  = preg_replace( '/(&#0*58(?![;0-9])|&#x0*3a(?![;a-f0-9]))/i', '$1;', $string );
1700      $string2 = preg_split( '/:|&#0*58;|&#x0*3a;|&colon;/i', $string, 2 );
1701      if ( isset( $string2[1] ) && ! preg_match( '%/\?%', $string2[0] ) ) {
1702          $string   = trim( $string2[1] );
1703          $protocol = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols );
1704          if ( 'feed:' === $protocol ) {
1705              if ( $count > 2 ) {
1706                  return '';
1707              }
1708              $string = wp_kses_bad_protocol_once( $string, $allowed_protocols, ++$count );
1709              if ( empty( $string ) ) {
1710                  return $string;
1711              }
1712          }
1713          $string = $protocol . $string;
1714      }
1715  
1716      return $string;
1717  }
1718  
1719  /**
1720   * Callback for `wp_kses_bad_protocol_once()` regular expression.
1721   *
1722   * This function processes URL protocols, checks to see if they're in the
1723   * list of allowed protocols or not, and returns different data depending
1724   * on the answer.
1725   *
1726   * @access private
1727   * @ignore
1728   * @since 1.0.0
1729   *
1730   * @param string   $string            URI scheme to check against the list of allowed protocols.
1731   * @param string[] $allowed_protocols Array of allowed URL protocols.
1732   * @return string Sanitized content.
1733   */
1734  function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) {
1735      $string2 = wp_kses_decode_entities( $string );
1736      $string2 = preg_replace( '/\s/', '', $string2 );
1737      $string2 = wp_kses_no_null( $string2 );
1738      $string2 = strtolower( $string2 );
1739  
1740      $allowed = false;
1741      foreach ( (array) $allowed_protocols as $one_protocol ) {
1742          if ( strtolower( $one_protocol ) == $string2 ) {
1743              $allowed = true;
1744              break;
1745          }
1746      }
1747  
1748      if ( $allowed ) {
1749          return "$string2:";
1750      } else {
1751          return '';
1752      }
1753  }
1754  
1755  /**
1756   * Converts and fixes HTML entities.
1757   *
1758   * This function normalizes HTML entities. It will convert `AT&T` to the correct
1759   * `AT&amp;T`, `&#00058;` to `&#58;`, `&#XYZZY;` to `&amp;#XYZZY;` and so on.
1760   *
1761   * When `$context` is set to 'xml', HTML entities are converted to their code points.  For
1762   * example, `AT&T&hellip;&#XYZZY;` is converted to `AT&amp;T…&amp;#XYZZY;`.
1763   *
1764   * @since 1.0.0
1765   * @since 5.5.0 Added `$context` parameter.
1766   *
1767   * @param string $string  Content to normalize entities.
1768   * @param string $context Context for normalization. Can be either 'html' or 'xml'.
1769   *                        Default 'html'.
1770   * @return string Content with normalized entities.
1771   */
1772  function wp_kses_normalize_entities( $string, $context = 'html' ) {
1773      // Disarm all entities by converting & to &amp;
1774      $string = str_replace( '&', '&amp;', $string );
1775  
1776      // Change back the allowed entities in our list of allowed entities.
1777      if ( 'xml' === $context ) {
1778          $string = preg_replace_callback( '/&amp;([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_xml_named_entities', $string );
1779      } else {
1780          $string = preg_replace_callback( '/&amp;([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string );
1781      }
1782      $string = preg_replace_callback( '/&amp;#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string );
1783      $string = preg_replace_callback( '/&amp;#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string );
1784  
1785      return $string;
1786  }
1787  
1788  /**
1789   * Callback for `wp_kses_normalize_entities()` regular expression.
1790   *
1791   * This function only accepts valid named entity references, which are finite,
1792   * case-sensitive, and highly scrutinized by HTML and XML validators.
1793   *
1794   * @since 3.0.0
1795   *
1796   * @global array $allowedentitynames
1797   *
1798   * @param array $matches preg_replace_callback() matches array.
1799   * @return string Correctly encoded entity.
1800   */
1801  function wp_kses_named_entities( $matches ) {
1802      global $allowedentitynames;
1803  
1804      if ( empty( $matches[1] ) ) {
1805          return '';
1806      }
1807  
1808      $i = $matches[1];
1809      return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&amp;$i;" : "&$i;";
1810  }
1811  
1812  /**
1813   * Callback for `wp_kses_normalize_entities()` regular expression.
1814   *
1815   * This function only accepts valid named entity references, which are finite,
1816   * case-sensitive, and highly scrutinized by XML validators.  HTML named entity
1817   * references are converted to their code points.
1818   *
1819   * @since 5.5.0
1820   *
1821   * @global array $allowedentitynames
1822   * @global array $allowedxmlnamedentities
1823   *
1824   * @param array $matches preg_replace_callback() matches array.
1825   * @return string Correctly encoded entity.
1826   */
1827  function wp_kses_xml_named_entities( $matches ) {
1828      global $allowedentitynames, $allowedxmlnamedentities;
1829  
1830      if ( empty( $matches[1] ) ) {
1831          return '';
1832      }
1833  
1834      $i = $matches[1];
1835  
1836      if ( in_array( $i, $allowedxmlnamedentities, true ) ) {
1837          return "&$i;";
1838      } elseif ( in_array( $i, $allowedentitynames, true ) ) {
1839          return html_entity_decode( "&$i;", ENT_HTML5 );
1840      }
1841  
1842      return "&amp;$i;";
1843  }
1844  
1845  /**
1846   * Callback for `wp_kses_normalize_entities()` regular expression.
1847   *
1848   * This function helps `wp_kses_normalize_entities()` to only accept 16-bit
1849   * values and nothing more for `&#number;` entities.
1850   *
1851   * @access private
1852   * @ignore
1853   * @since 1.0.0
1854   *
1855   * @param array $matches `preg_replace_callback()` matches array.
1856   * @return string Correctly encoded entity.
1857   */
1858  function wp_kses_normalize_entities2( $matches ) {
1859      if ( empty( $matches[1] ) ) {
1860          return '';
1861      }
1862  
1863      $i = $matches[1];
1864      if ( valid_unicode( $i ) ) {
1865          $i = str_pad( ltrim( $i, '0' ), 3, '0', STR_PAD_LEFT );
1866          $i = "&#$i;";
1867      } else {
1868          $i = "&amp;#$i;";
1869      }
1870  
1871      return $i;
1872  }
1873  
1874  /**
1875   * Callback for `wp_kses_normalize_entities()` for regular expression.
1876   *
1877   * This function helps `wp_kses_normalize_entities()` to only accept valid Unicode
1878   * numeric entities in hex form.
1879   *
1880   * @since 2.7.0
1881   * @access private
1882   * @ignore
1883   *
1884   * @param array $matches `preg_replace_callback()` matches array.
1885   * @return string Correctly encoded entity.
1886   */
1887  function wp_kses_normalize_entities3( $matches ) {
1888      if ( empty( $matches[1] ) ) {
1889          return '';
1890      }
1891  
1892      $hexchars = $matches[1];
1893      return ( ! valid_unicode( hexdec( $hexchars ) ) ) ? "&amp;#x$hexchars;" : '&#x' . ltrim( $hexchars, '0' ) . ';';
1894  }
1895  
1896  /**
1897   * Determines if a Unicode codepoint is valid.
1898   *
1899   * @since 2.7.0
1900   *
1901   * @param int $i Unicode codepoint.
1902   * @return bool Whether or not the codepoint is a valid Unicode codepoint.
1903   */
1904  function valid_unicode( $i ) {
1905      return ( 0x9 == $i || 0xa == $i || 0xd == $i ||
1906              ( 0x20 <= $i && $i <= 0xd7ff ) ||
1907              ( 0xe000 <= $i && $i <= 0xfffd ) ||
1908              ( 0x10000 <= $i && $i <= 0x10ffff ) );
1909  }
1910  
1911  /**
1912   * Converts all numeric HTML entities to their named counterparts.
1913   *
1914   * This function decodes numeric HTML entities (`&#65;` and `&#x41;`).
1915   * It doesn't do anything with named entities like `&auml;`, but we don't
1916   * need them in the allowed URL protocols system anyway.
1917   *
1918   * @since 1.0.0
1919   *
1920   * @param string $string Content to change entities.
1921   * @return string Content after decoded entities.
1922   */
1923  function wp_kses_decode_entities( $string ) {
1924      $string = preg_replace_callback( '/&#([0-9]+);/', '_wp_kses_decode_entities_chr', $string );
1925      $string = preg_replace_callback( '/&#[Xx]([0-9A-Fa-f]+);/', '_wp_kses_decode_entities_chr_hexdec', $string );
1926  
1927      return $string;
1928  }
1929  
1930  /**
1931   * Regex callback for `wp_kses_decode_entities()`.
1932   *
1933   * @since 2.9.0
1934   * @access private
1935   * @ignore
1936   *
1937   * @param array $match preg match
1938   * @return string
1939   */
1940  function _wp_kses_decode_entities_chr( $match ) {
1941      return chr( $match[1] );
1942  }
1943  
1944  /**
1945   * Regex callback for `wp_kses_decode_entities()`.
1946   *
1947   * @since 2.9.0
1948   * @access private
1949   * @ignore
1950   *
1951   * @param array $match preg match
1952   * @return string
1953   */
1954  function _wp_kses_decode_entities_chr_hexdec( $match ) {
1955      return chr( hexdec( $match[1] ) );
1956  }
1957  
1958  /**
1959   * Sanitize content with allowed HTML KSES rules.
1960   *
1961   * This function expects slashed data.
1962   *
1963   * @since 1.0.0
1964   *
1965   * @param string $data Content to filter, expected to be escaped with slashes.
1966   * @return string Filtered content.
1967   */
1968  function wp_filter_kses( $data ) {
1969      return addslashes( wp_kses( stripslashes( $data ), current_filter() ) );
1970  }
1971  
1972  /**
1973   * Sanitize content with allowed HTML KSES rules.
1974   *
1975   * This function expects unslashed data.
1976   *
1977   * @since 2.9.0
1978   *
1979   * @param string $data Content to filter, expected to not be escaped.
1980   * @return string Filtered content.
1981   */
1982  function wp_kses_data( $data ) {
1983      return wp_kses( $data, current_filter() );
1984  }
1985  
1986  /**
1987   * Sanitizes content for allowed HTML tags for post content.
1988   *
1989   * Post content refers to the page contents of the 'post' type and not `$_POST`
1990   * data from forms.
1991   *
1992   * This function expects slashed data.
1993   *
1994   * @since 2.0.0
1995   *
1996   * @param string $data Post content to filter, expected to be escaped with slashes.
1997   * @return string Filtered post content with allowed HTML tags and attributes intact.
1998   */
1999  function wp_filter_post_kses( $data ) {
2000      return addslashes( wp_kses( stripslashes( $data ), 'post' ) );
2001  }
2002  
2003  /**
2004   * Sanitizes content for allowed HTML tags for post content.
2005   *
2006   * Post content refers to the page contents of the 'post' type and not `$_POST`
2007   * data from forms.
2008   *
2009   * This function expects unslashed data.
2010   *
2011   * @since 2.9.0
2012   *
2013   * @param string $data Post content to filter.
2014   * @return string Filtered post content with allowed HTML tags and attributes intact.
2015   */
2016  function wp_kses_post( $data ) {
2017      return wp_kses( $data, 'post' );
2018  }
2019  
2020  /**
2021   * Navigates through an array, object, or scalar, and sanitizes content for
2022   * allowed HTML tags for post content.
2023   *
2024   * @since 4.4.2
2025   *
2026   * @see map_deep()
2027   *
2028   * @param mixed $data The array, object, or scalar value to inspect.
2029   * @return mixed The filtered content.
2030   */
2031  function wp_kses_post_deep( $data ) {
2032      return map_deep( $data, 'wp_kses_post' );
2033  }
2034  
2035  /**
2036   * Strips all HTML from a text string.
2037   *
2038   * This function expects slashed data.
2039   *
2040   * @since 2.1.0
2041   *
2042   * @param string $data Content to strip all HTML from.
2043   * @return string Filtered content without any HTML.
2044   */
2045  function wp_filter_nohtml_kses( $data ) {
2046      return addslashes( wp_kses( stripslashes( $data ), 'strip' ) );
2047  }
2048  
2049  /**
2050   * Adds all KSES input form content filters.
2051   *
2052   * All hooks have default priority. The `wp_filter_kses()` function is added to
2053   * the 'pre_comment_content' and 'title_save_pre' hooks.
2054   *
2055   * The `wp_filter_post_kses()` function is added to the 'content_save_pre',
2056   * 'excerpt_save_pre', and 'content_filtered_save_pre' hooks.
2057   *
2058   * @since 2.0.0
2059   */
2060  function kses_init_filters() {
2061      // Normal filtering.
2062      add_filter( 'title_save_pre', 'wp_filter_kses' );
2063  
2064      // Comment filtering.
2065      if ( current_user_can( 'unfiltered_html' ) ) {
2066          add_filter( 'pre_comment_content', 'wp_filter_post_kses' );
2067      } else {
2068          add_filter( 'pre_comment_content', 'wp_filter_kses' );
2069      }
2070  
2071      // Post filtering.
2072      add_filter( 'content_save_pre', 'wp_filter_post_kses' );
2073      add_filter( 'excerpt_save_pre', 'wp_filter_post_kses' );
2074      add_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
2075  }
2076  
2077  /**
2078   * Removes all KSES input form content filters.
2079   *
2080   * A quick procedural method to removing all of the filters that KSES uses for
2081   * content in WordPress Loop.
2082   *
2083   * Does not remove the `kses_init()` function from {@see 'init'} hook (priority is
2084   * default). Also does not remove `kses_init()` function from {@see 'set_current_user'}
2085   * hook (priority is also default).
2086   *
2087   * @since 2.0.6
2088   */
2089  function kses_remove_filters() {
2090      // Normal filtering.
2091      remove_filter( 'title_save_pre', 'wp_filter_kses' );
2092  
2093      // Comment filtering.
2094      remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
2095      remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2096  
2097      // Post filtering.
2098      remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
2099      remove_filter( 'excerpt_save_pre', 'wp_filter_post_kses' );
2100      remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
2101  }
2102  
2103  /**
2104   * Sets up most of the KSES filters for input form content.
2105   *
2106   * First removes all of the KSES filters in case the current user does not need
2107   * to have KSES filter the content. If the user does not have `unfiltered_html`
2108   * capability, then KSES filters are added.
2109   *
2110   * @since 2.0.0
2111   */
2112  function kses_init() {
2113      kses_remove_filters();
2114  
2115      if ( ! current_user_can( 'unfiltered_html' ) ) {
2116          kses_init_filters();
2117      }
2118  }
2119  
2120  /**
2121   * Filters an inline style attribute and removes disallowed rules.
2122   *
2123   * @since 2.8.1
2124   *
2125   * @param string $css        A string of CSS rules.
2126   * @param string $deprecated Not used.
2127   * @return string Filtered string of CSS rules.
2128   */
2129  function safecss_filter_attr( $css, $deprecated = '' ) {
2130      if ( ! empty( $deprecated ) ) {
2131          _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented.
2132      }
2133  
2134      $css = wp_kses_no_null( $css );
2135      $css = str_replace( array( "\n", "\r", "\t" ), '', $css );
2136  
2137      $allowed_protocols = wp_allowed_protocols();
2138  
2139      $css_array = explode( ';', trim( $css ) );
2140  
2141      /**
2142       * Filters list of allowed CSS attributes.
2143       *
2144       * @since 2.8.1
2145       * @since 4.4.0 Added support for `min-height`, `max-height`, `min-width`, and `max-width`.
2146       * @since 4.6.0 Added support for `list-style-type`.
2147       * @since 5.0.0 Added support for `background-image`.
2148       * @since 5.1.0 Added support for `text-transform`.
2149       * @since 5.2.0 Added support for `background-position` and `grid-template-columns`.
2150       * @since 5.3.0 Added support for `grid`, `flex` and `column` layout properties.
2151       *              Extend `background-*` support of individual properties.
2152       * @since 5.3.1 Added support for gradient backgrounds.
2153       *
2154       * @param string[] $attr Array of allowed CSS attributes.
2155       */
2156      $allowed_attr = apply_filters(
2157          'safe_style_css',
2158          array(
2159              'background',
2160              'background-color',
2161              'background-image',
2162              'background-position',
2163              'background-size',
2164              'background-attachment',
2165              'background-blend-mode',
2166  
2167              'border',
2168              'border-radius',
2169              'border-width',
2170              'border-color',
2171              'border-style',
2172              'border-right',
2173              'border-right-color',
2174              'border-right-style',
2175              'border-right-width',
2176              'border-bottom',
2177              'border-bottom-color',
2178              'border-bottom-style',
2179              'border-bottom-width',
2180              'border-left',
2181              'border-left-color',
2182              'border-left-style',
2183              'border-left-width',
2184              'border-top',
2185              'border-top-color',
2186              'border-top-style',
2187              'border-top-width',
2188  
2189              'border-spacing',
2190              'border-collapse',
2191              'caption-side',
2192  
2193              'columns',
2194              'column-count',
2195              'column-fill',
2196              'column-gap',
2197              'column-rule',
2198              'column-span',
2199              'column-width',
2200  
2201              'color',
2202              'font',
2203              'font-family',
2204              'font-size',
2205              'font-style',
2206              'font-variant',
2207              'font-weight',
2208              'letter-spacing',
2209              'line-height',
2210              'text-align',
2211              'text-decoration',
2212              'text-indent',
2213              'text-transform',
2214  
2215              'height',
2216              'min-height',
2217              'max-height',
2218  
2219              'width',
2220              'min-width',
2221              'max-width',
2222  
2223              'margin',
2224              'margin-right',
2225              'margin-bottom',
2226              'margin-left',
2227              'margin-top',
2228  
2229              'padding',
2230              'padding-right',
2231              'padding-bottom',
2232              'padding-left',
2233              'padding-top',
2234  
2235              'flex',
2236              'flex-basis',
2237              'flex-direction',
2238              'flex-flow',
2239              'flex-grow',
2240              'flex-shrink',
2241  
2242              'grid-template-columns',
2243              'grid-auto-columns',
2244              'grid-column-start',
2245              'grid-column-end',
2246              'grid-column-gap',
2247              'grid-template-rows',
2248              'grid-auto-rows',
2249              'grid-row-start',
2250              'grid-row-end',
2251              'grid-row-gap',
2252              'grid-gap',
2253  
2254              'justify-content',
2255              'justify-items',
2256              'justify-self',
2257              'align-content',
2258              'align-items',
2259              'align-self',
2260  
2261              'clear',
2262              'cursor',
2263              'direction',
2264              'float',
2265              'list-style-type',
2266              'overflow',
2267              'vertical-align',
2268          )
2269      );
2270  
2271      /*
2272       * CSS attributes that accept URL data types.
2273       *
2274       * This is in accordance to the CSS spec and unrelated to
2275       * the sub-set of supported attributes above.
2276       *
2277       * See: https://developer.mozilla.org/en-US/docs/Web/CSS/url
2278       */
2279      $css_url_data_types = array(
2280          'background',
2281          'background-image',
2282  
2283          'cursor',
2284  
2285          'list-style',
2286          'list-style-image',
2287      );
2288  
2289      /*
2290       * CSS attributes that accept gradient data types.
2291       *
2292       */
2293      $css_gradient_data_types = array(
2294          'background',
2295          'background-image',
2296      );
2297  
2298      if ( empty( $allowed_attr ) ) {
2299          return $css;
2300      }
2301  
2302      $css = '';
2303      foreach ( $css_array as $css_item ) {
2304          if ( '' === $css_item ) {
2305              continue;
2306          }
2307  
2308          $css_item        = trim( $css_item );
2309          $css_test_string = $css_item;
2310          $found           = false;
2311          $url_attr        = false;
2312          $gradient_attr   = false;
2313  
2314          if ( strpos( $css_item, ':' ) === false ) {
2315              $found = true;
2316          } else {
2317              $parts        = explode( ':', $css_item, 2 );
2318              $css_selector = trim( $parts[0] );
2319  
2320              if ( in_array( $css_selector, $allowed_attr, true ) ) {
2321                  $found         = true;
2322                  $url_attr      = in_array( $css_selector, $css_url_data_types, true );
2323                  $gradient_attr = in_array( $css_selector, $css_gradient_data_types, true );
2324              }
2325          }
2326  
2327          if ( $found && $url_attr ) {
2328              // Simplified: matches the sequence `url(*)`.
2329              preg_match_all( '/url\([^)]+\)/', $parts[1], $url_matches );
2330  
2331              foreach ( $url_matches[0] as $url_match ) {
2332                  // Clean up the URL from each of the matches above.
2333                  preg_match( '/^url\(\s*([\'\"]?)(.*)(\g1)\s*\)$/', $url_match, $url_pieces );
2334  
2335                  if ( empty( $url_pieces[2] ) ) {
2336                      $found = false;
2337                      break;
2338                  }
2339  
2340                  $url = trim( $url_pieces[2] );
2341  
2342                  if ( empty( $url ) || wp_kses_bad_protocol( $url, $allowed_protocols ) !== $url ) {
2343                      $found = false;
2344                      break;
2345                  } else {
2346                      // Remove the whole `url(*)` bit that was matched above from the CSS.
2347                      $css_test_string = str_replace( $url_match, '', $css_test_string );
2348                  }
2349              }
2350          }
2351  
2352          if ( $found && $gradient_attr ) {
2353              $css_value = trim( $parts[1] );
2354              if ( preg_match( '/^(repeating-)?(linear|radial|conic)-gradient\(([^()]|rgb[a]?\([^()]*\))*\)$/', $css_value ) ) {
2355                  // Remove the whole `gradient` bit that was matched above from the CSS.
2356                  $css_test_string = str_replace( $css_value, '', $css_test_string );
2357              }
2358          }
2359  
2360          if ( $found ) {
2361              // Check for any CSS containing \ ( & } = or comments, except for url() usage checked above.
2362              $allow_css = ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string );
2363  
2364              /**
2365               * Filters the check for unsafe CSS in `safecss_filter_attr`.
2366               *
2367               * Enables developers to determine whether a section of CSS should be allowed or discarded.
2368               * By default, the value will be false if the part contains \ ( & } = or comments.
2369               * Return true to allow the CSS part to be included in the output.
2370               *
2371               * @since 5.5.0
2372               *
2373               * @param bool   $allow_css       Whether the CSS in the test string is considered safe.
2374               * @param string $css_test_string The CSS string to test.
2375               */
2376              $allow_css = apply_filters( 'safecss_filter_attr_allow_css', $allow_css, $css_test_string );
2377  
2378               // Only add the CSS part if it passes the regex check.
2379              if ( $allow_css ) {
2380                  if ( '' !== $css ) {
2381                      $css .= ';';
2382                  }
2383  
2384                  $css .= $css_item;
2385              }
2386          }
2387      }
2388  
2389      return $css;
2390  }
2391  
2392  /**
2393   * Helper function to add global attributes to a tag in the allowed HTML list.
2394   *
2395   * @since 3.5.0
2396   * @since 5.0.0 Add support for `data-*` wildcard attributes.
2397   * @access private
2398   * @ignore
2399   *
2400   * @param array $value An array of attributes.
2401   * @return array The array of attributes with global attributes added.
2402   */
2403  function _wp_add_global_attributes( $value ) {
2404      $global_attributes = array(
2405          'aria-describedby' => true,
2406          'aria-details'     => true,
2407          'aria-label'       => true,
2408          'aria-labelledby'  => true,
2409          'aria-hidden'      => true,
2410          'class'            => true,
2411          'id'               => true,
2412          'style'            => true,
2413          'title'            => true,
2414          'role'             => true,
2415          'data-*'           => true,
2416      );
2417  
2418      if ( true === $value ) {
2419          $value = array();
2420      }
2421  
2422      if ( is_array( $value ) ) {
2423          return array_merge( $value, $global_attributes );
2424      }
2425  
2426      return $value;
2427  }


Generated: Sun Jul 5 01:00:04 2020 Cross-referenced by PHPXref 0.7.1