Ticket #58028: 58028.diff
File 58028.diff, 8.0 KB (added by , 19 months ago) |
---|
-
src/wp-includes/class-wp-theme-json.php
66 66 * 67 67 * They are a unkeyed array of values such as: 68 68 * 69 * ```php 70 * array( 71 * array( 72 * 'slug' => 'unique-name-within-the-set', 73 * 'name' => 'Name for the UI', 74 * <value_key> => 'value' 75 * ), 76 * ) 77 * ``` 69 * array( 70 * array( 71 * 'slug' => 'unique-name-within-the-set', 72 * 'name' => 'Name for the UI', 73 * <value_key> => 'value' 74 * ), 75 * ) 78 76 * 79 77 * This contains the necessary metadata to process them: 80 78 * … … 2531 2529 /** 2532 2530 * For metadata values that can either be booleans or paths to booleans, gets the value. 2533 2531 * 2534 * ```php 2535 * $data = array( 2536 * 'color' => array( 2537 * 'defaultPalette' => true 2538 * ) 2539 * ); 2532 * $data = array( 2533 * 'color' => array( 2534 * 'defaultPalette' => true 2535 * ) 2536 * ); 2540 2537 * 2541 * static::get_metadata_boolean( $data, false );2542 * // => false2538 * static::get_metadata_boolean( $data, false ); 2539 * // => false 2543 2540 * 2544 * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); 2545 * // => true 2546 * ``` 2541 * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); 2542 * // => true 2547 2543 * 2548 2544 * @since 6.0.0 2549 2545 * -
src/wp-includes/html-api/class-wp-html-tag-processor.php
38 38 * 3. Request changes to the attributes in those tag(s). 39 39 * 40 40 * Example: 41 * ```php41 * 42 42 * $tags = new WP_HTML_Tag_Processor( $html ); 43 43 * if ( $tags->next_tag( 'option' ) ) { 44 44 * $tags->set_attribute( 'selected', true ); 45 45 * } 46 * ```47 46 * 48 47 * ### Finding tags 49 48 * … … 54 53 * regardless of what kind it is. 55 54 * 56 55 * If you want to _find whatever the next tag is_: 57 * ```php56 * 58 57 * $tags->next_tag(); 59 * ```60 58 * 61 59 * | Goal | Query | 62 60 * |-----------------------------------------------------------|---------------------------------------------------------------------------------| … … 87 85 * provided by the processor or external state or variables. 88 86 * 89 87 * Example: 90 * ```php88 * 91 89 * // Paint up to the first five DIV or SPAN tags marked with the "jazzy" style. 92 90 * $remaining_count = 5; 93 91 * while ( $remaining_count > 0 && $tags->next_tag() ) { … … 99 97 * $remaining_count--; 100 98 * } 101 99 * } 102 * ```103 100 * 104 101 * `get_attribute()` will return `null` if the attribute wasn't present 105 102 * on the tag when it was called. It may return `""` (the empty string) … … 116 113 * nothing and move on to the next opening tag. 117 114 * 118 115 * Example: 119 * ```php116 * 120 117 * if ( $tags->next_tag( array( 'class' => 'wp-group-block' ) ) ) { 121 118 * $tags->set_attribute( 'title', 'This groups the contained content.' ); 122 119 * $tags->remove_attribute( 'data-test-id' ); 123 120 * } 124 * ```125 121 * 126 122 * If `set_attribute()` is called for an existing attribute it will 127 123 * overwrite the existing value. Similarly, calling `remove_attribute()` … … 141 137 * entire `class` attribute will be removed. 142 138 * 143 139 * Example: 144 * ```php140 * 145 141 * // from `<span>Yippee!</span>` 146 142 * // to `<span class="is-active">Yippee!</span>` 147 143 * $tags->add_class( 'is-active' ); … … 165 161 * // from `<input type="text" length="24">` 166 162 * // to `<input type="text" length="24"> 167 163 * $tags->remove_class( 'rugby' ); 168 * ```169 164 * 170 165 * When class changes are enqueued but a direct change to `class` is made via 171 166 * `set_attribute` then the changes to `set_attribute` (or `remove_attribute`) … … 184 179 * and so on. It's fine from a performance standpoint to create a 185 180 * bookmark and update it frequently, such as within a loop. 186 181 * 187 * ```php188 182 * $total_todos = 0; 189 183 * while ( $p->next_tag( array( 'tag_name' => 'UL', 'class_name' => 'todo' ) ) ) { 190 184 * $p->set_bookmark( 'list-start' ); … … 203 197 * } 204 198 * } 205 199 * } 206 * ```207 200 * 208 201 * ## Design and limitations 209 202 * … … 420 413 * Lazily-built index of attributes found within an HTML tag, keyed by the attribute name. 421 414 * 422 415 * Example: 423 * ```php416 * 424 417 * // supposing the parser is working through this content 425 418 * // and stops after recognizing the `id` attribute 426 419 * // <div id="test-4" class=outline title="data:text/plain;base64=asdk3nk1j3fo8"> … … 438 431 * 439 432 * // Note that only the `class` attribute value is stored in the index. 440 433 * // That's because it is the only value used by this class at the moment. 441 * ```442 434 * 443 435 * @since 6.2.0 444 436 * @var WP_HTML_Attribute_Token[] … … 457 449 * into a single `set_attribute( 'class', $changes )` call. 458 450 * 459 451 * Example: 460 * ```php452 * 461 453 * // Add the `wp-block-group` class, remove the `wp-group` class. 462 454 * $classname_updates = array( 463 455 * // Indexed by a comparable class name … … 464 456 * 'wp-block-group' => WP_HTML_Tag_Processor::ADD_CLASS, 465 457 * 'wp-group' => WP_HTML_Tag_Processor::REMOVE_CLASS 466 458 * ); 467 * ```468 459 * 469 460 * @since 6.2.0 470 461 * @var bool[] … … 511 502 * copies when applying many updates to a single document. 512 503 * 513 504 * Example: 514 * ```php505 * 515 506 * // Replace an attribute stored with a new value, indices 516 507 * // sourced from the lazily-parsed HTML recognizer. 517 508 * $start = $attributes['src']->start; … … 522 513 * $lexical_updates = array( 523 514 * WP_HTML_Text_Replacement( 14, 28, 'https://my-site.my-domain/wp-content/uploads/2014/08/kittens.jpg' ) 524 515 * ); 525 * ```526 516 * 527 517 * @since 6.2.0 528 518 * @var WP_HTML_Text_Replacement[] … … 1619 1609 * Returns the value of a requested attribute from a matched tag opener if that attribute exists. 1620 1610 * 1621 1611 * Example: 1622 * ```php1612 * 1623 1613 * $p = new WP_HTML_Tag_Processor( '<div enabled class="test" data-test-id="14">Test</div>' ); 1624 1614 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; 1625 1615 * $p->get_attribute( 'data-test-id' ) === '14'; … … 1628 1618 * 1629 1619 * $p->next_tag() === false; 1630 1620 * $p->get_attribute( 'class' ) === null; 1631 * ```1632 1621 * 1633 1622 * @since 6.2.0 1634 1623 * … … 1702 1691 * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2:ascii-case-insensitive 1703 1692 * 1704 1693 * Example: 1705 * ```php1694 * 1706 1695 * $p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' ); 1707 1696 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; 1708 1697 * $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' ); … … 1709 1698 * 1710 1699 * $p->next_tag() === false; 1711 1700 * $p->get_attribute_names_with_prefix( 'data-' ) === null; 1712 * ```1713 1701 * 1714 1702 * @since 6.2.0 1715 1703 * … … 1736 1724 * Returns the uppercase name of the matched tag. 1737 1725 * 1738 1726 * Example: 1739 * ```php1727 * 1740 1728 * $p = new WP_HTML_Tag_Processor( '<DIV CLASS="test">Test</DIV>' ); 1741 1729 * $p->next_tag() === true; 1742 1730 * $p->get_tag() === 'DIV'; … … 1743 1731 * 1744 1732 * $p->next_tag() === false; 1745 1733 * $p->get_tag() === null; 1746 * ```1747 1734 * 1748 1735 * @since 6.2.0 1749 1736 * … … 1788 1775 * Indicates if the current tag token is a tag closer. 1789 1776 * 1790 1777 * Example: 1791 * ```php1778 * 1792 1779 * $p = new WP_HTML_Tag_Processor( '<div></div>' ); 1793 1780 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); 1794 1781 * $p->is_tag_closer() === false; … … 1795 1782 * 1796 1783 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); 1797 1784 * $p->is_tag_closer() === true; 1798 * ```1799 1785 * 1800 1786 * @since 6.2.0 1801 1787 *