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