Changeset 55729 for branches/6.2
- Timestamp:
- 05/08/2023 07:57:47 PM (16 months ago)
- Location:
- branches/6.2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.2
-
branches/6.2/src/wp-includes/class-wp-theme-json.php
r55349 r55729 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: … … 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 * ); 2540 * 2541 * static::get_metadata_boolean( $data, false ); 2542 * // => false 2543 * 2544 * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); 2545 * // => true 2546 * ``` 2532 * $data = array( 2533 * 'color' => array( 2534 * 'defaultPalette' => true 2535 * ) 2536 * ); 2537 * 2538 * static::get_metadata_boolean( $data, false ); 2539 * // => false 2540 * 2541 * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); 2542 * // => true 2547 2543 * 2548 2544 * @since 6.0.0 -
branches/6.2/src/wp-includes/html-api/class-wp-html-tag-processor.php
r55728 r55729 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 … … 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 | … … 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; … … 100 98 * } 101 99 * } 102 * ```103 100 * 104 101 * `get_attribute()` will return `null` if the attribute wasn't present … … 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 … … 142 138 * 143 139 * Example: 144 * ```php140 * 145 141 * // from `<span>Yippee!</span>` 146 142 * // to `<span class="is-active">Yippee!</span>` … … 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 … … 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' ) ) ) { … … 204 198 * } 205 199 * } 206 * ```207 200 * 208 201 * ## Design and limitations … … 336 329 * 337 330 * Example: 338 * ``` 339 * <div id="test">... 340 * 01234 341 * - tag name starts at 1 342 * ``` 331 * 332 * <div id="test">... 333 * 01234 334 * - tag name starts at 1 343 335 * 344 336 * @since 6.2.0 … … 351 343 * 352 344 * Example: 353 * ``` 354 * <div id="test">... 355 * 01234 356 * --- tag name length is 3 357 * ``` 345 * 346 * <div id="test">... 347 * 01234 348 * --- tag name length is 3 358 349 * 359 350 * @since 6.2.0 … … 366 357 * 367 358 * Example: 368 * ``` 369 * <div id="test">... 370 * 0 1 | 371 * 01234567890123456 372 * --- tag name ends at 14 373 * ``` 359 * 360 * <div id="test">... 361 * 0 1 | 362 * 01234567890123456 363 * --- tag name ends at 14 374 364 * 375 365 * @since 6.2.0 … … 389 379 * 390 380 * Example: 391 * ```php392 * // supposing the parser is working through this content393 * // and stops after recognizing the `id` attribute 381 * 382 * // Supposing the parser is working through this content 383 * // and stops after recognizing the `id` attribute. 394 384 * // <div id="test-4" class=outline title="data:text/plain;base64=asdk3nk1j3fo8"> 395 * // ^ parsing will continue from this point 385 * // ^ parsing will continue from this point. 396 386 * $this->attributes = array( 397 387 * 'id' => new WP_HTML_Attribute_Match( 'id', null, 6, 17 ) 398 388 * ); 399 389 * 400 * // when picking up parsing again, or when asking to find the401 * // `class` attribute we will continue and add to this array 390 * // When picking up parsing again, or when asking to find the 391 * // `class` attribute we will continue and add to this array. 402 392 * $this->attributes = array( 403 393 * 'id' => new WP_HTML_Attribute_Match( 'id', null, 6, 17 ), … … 407 397 * // Note that only the `class` attribute value is stored in the index. 408 398 * // That's because it is the only value used by this class at the moment. 409 * ```410 399 * 411 400 * @since 6.2.0 … … 426 415 * 427 416 * Example: 428 * ```php417 * 429 418 * // Add the `wp-block-group` class, remove the `wp-group` class. 430 419 * $classname_updates = array( 431 * // Indexed by a comparable class name 420 * // Indexed by a comparable class name. 432 421 * 'wp-block-group' => WP_HTML_Tag_Processor::ADD_CLASS, 433 422 * 'wp-group' => WP_HTML_Tag_Processor::REMOVE_CLASS 434 423 * ); 435 * ```436 424 * 437 425 * @since 6.2.0 … … 480 468 * 481 469 * Example: 482 * ```php470 * 483 471 * // Replace an attribute stored with a new value, indices 484 472 * // sourced from the lazily-parsed HTML recognizer. … … 491 479 * WP_HTML_Text_Replacement( 14, 28, 'https://my-site.my-domain/wp-content/uploads/2014/08/kittens.jpg' ) 492 480 * ); 493 * ```494 481 * 495 482 * @since 6.2.0 … … 609 596 * 610 597 * Example: 611 * ```598 * 612 599 * <main><h2>Surprising fact you may not know!</h2></main> 613 600 * ^ ^ … … 617 604 * ^ ^ 618 605 * \-|-- it shifts with edits 619 * ```620 606 * 621 607 * Bookmarks provide the ability to seek to a previously-scanned … … 624 610 * 625 611 * Example: 626 * ```612 * 627 613 * <ul><li>One</li><li>Two</li><li>Three</li></ul> 628 614 * ^^^^ … … 651 637 * } 652 638 * } 653 * ```654 639 * 655 640 * Bookmarks intentionally hide the internal string offsets … … 728 713 * @see https://html.spec.whatwg.org/multipage/parsing.html#rcdata-state 729 714 * 730 * @param string $tag_name – the lowercase tag name which will close the RCDATA region.715 * @param string $tag_name The lowercase tag name which will close the RCDATA region. 731 716 * @return bool Whether an end to the RCDATA region was found before the end of the document. 732 717 */ … … 1616 1601 * 1617 1602 * Example: 1618 * ```1603 * 1619 1604 * $p->set_attribute( 'data-TEST-id', 'update' ); 1620 1605 * 'update' === $p->get_enqueued_attribute_value( 'data-test-id' ); 1621 * ```1622 1606 * 1623 1607 * Detect this difference based on the absence of the `=`, which _must_ exist in any … … 1650 1634 * 1651 1635 * Example: 1652 * ```php1636 * 1653 1637 * $p = new WP_HTML_Tag_Processor( '<div enabled class="test" data-test-id="14">Test</div>' ); 1654 1638 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; … … 1659 1643 * $p->next_tag() === false; 1660 1644 * $p->get_attribute( 'class' ) === null; 1661 * ```1662 1645 * 1663 1646 * @since 6.2.0 … … 1731 1714 * 1732 1715 * Example: 1733 * ```php1716 * 1734 1717 * $p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' ); 1735 1718 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; … … 1738 1721 * $p->next_tag() === false; 1739 1722 * $p->get_attribute_names_with_prefix( 'data-' ) === null; 1740 * ```1741 1723 * 1742 1724 * @since 6.2.0 … … 1767 1749 * 1768 1750 * Example: 1769 * ```php1751 * 1770 1752 * $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' ); 1771 1753 * $p->next_tag() === true; … … 1774 1756 * $p->next_tag() === false; 1775 1757 * $p->get_tag() === null; 1776 * ```1777 1758 * 1778 1759 * @since 6.2.0 … … 1794 1775 * 1795 1776 * Example: 1796 * ```php1777 * 1797 1778 * $p = new WP_HTML_Tag_Processor( '<div></div>' ); 1798 1779 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); … … 1801 1782 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); 1802 1783 * $p->is_tag_closer() === true; 1803 * ```1804 1784 * 1805 1785 * @since 6.2.0 … … 1907 1887 * 1908 1888 * Example – set attribute id to "new" in <div id="initial_id" />: 1909 * <div id="initial_id"/>1910 * ^-------------^1911 * start end1912 * replacement: `id="new"`1913 1889 * 1914 * Result: <div id="new"/> 1890 * <div id="initial_id"/> 1891 * ^-------------^ 1892 * start end 1893 * replacement: `id="new"` 1894 * 1895 * Result: <div id="new"/> 1915 1896 */ 1916 1897 $existing_attribute = $this->attributes[ $comparable_name ]; … … 1925 1906 * 1926 1907 * Example – add attribute id="new" to <div />: 1927 * <div/>1928 * ^1929 * start and end1930 * replacement: ` id="new"`1931 1908 * 1932 * Result: <div id="new"/> 1909 * <div/> 1910 * ^ 1911 * start and end 1912 * replacement: ` id="new"` 1913 * 1914 * Result: <div id="new"/> 1933 1915 */ 1934 1916 $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement(
Note: See TracChangeset
for help on using the changeset viewer.