| @@ -17,8 +17,30 @@ | ||
| 17 | 17 | |
| 18 | 18 | const DEPRECATION_RANGE = 0.4; |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | + * A list of safe tage for `validate_html_tag` method. | |
| 22 | + */ | |
| 23 | + const ALLOWED_HTML_WRAPPER_TAGS = [ | |
| 24 | + 'article', | |
| 25 | + 'aside', | |
| 26 | + 'div', | |
| 27 | + 'footer', | |
| 28 | + 'h1', | |
| 29 | + 'h2', | |
| 30 | + 'h3', | |
| 31 | + 'h4', | |
| 32 | + 'h5', | |
| 33 | + 'h6', | |
| 34 | + 'header', | |
| 35 | + 'main', | |
| 36 | + 'nav', | |
| 37 | + 'p', | |
| 38 | + 'section', | |
| 39 | + 'span', | |
| 40 | + ]; | |
| 41 | + | |
| 42 | + /** | |
| 21 | 43 | * Is ajax. |
| 22 | 44 | * |
| 23 | 45 | * Whether the current request is a WordPress ajax request. |
| 24 | 46 | * |
| @@ -621,6 +643,17 @@ | ||
| 621 | 643 | // @codingStandardsIgnoreStart |
| 622 | 644 | $submenu[ $menu_slug ][0][0] = $new_label; |
| 623 | 645 | // @codingStandardsIgnoreEnd |
| 624 | 646 | } |
| 647 | + } | |
| 648 | + | |
| 649 | + /** | |
| 650 | + * Validate an HTML tag against a safe allowed list. | |
| 651 | + * | |
| 652 | + * @param string $tag | |
| 653 | + * | |
| 654 | + * @return string | |
| 655 | + */ | |
| 656 | + public static function validate_html_tag( $tag ) { | |
| 657 | + return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 625 | 658 | } |
| 626 | 659 | } |