Changeset 55304
- Timestamp:
- 02/10/2023 10:57:20 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r55206 r55304 41 41 * ```php 42 42 * $tags = new WP_HTML_Tag_Processor( $html ); 43 * if ( $tags->next_tag( [ 'tag_name' => 'option' ]) ) {43 * if ( $tags->next_tag( array( 'tag_name' => 'option' ) ) ) { 44 44 * $tags->set_attribute( 'selected', true ); 45 45 * } … … 62 62 * |-----------------------------------------------------------|----------------------------------------------------------------------------| 63 63 * | Find any tag. | `$tags->next_tag();` | 64 * | Find next image tag. | `$tags->next_tag( [ 'tag_name' => 'img' ]);` |65 * | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( [ 'class_name' => 'fullwidth' ]);` |66 * | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( [ 'tag_name' => 'img', 'class_name' => 'fullwidth' ]);` |64 * | Find next image tag. | `$tags->next_tag( array( 'tag_name' => 'img' ) );` | 65 * | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'class_name' => 'fullwidth' ) );` | 66 * | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'tag_name' => 'img', 'class_name' => 'fullwidth' ) );` | 67 67 * 68 68 * If a tag was found meeting your criteria then `next_tag()` … … 117 117 * Example: 118 118 * ```php 119 * if ( $tags->next_tag( [ 'class' => 'wp-group-block' ]) ) {119 * if ( $tags->next_tag( array( 'class' => 'wp-group-block' ) ) ) { 120 120 * $tags->set_attribute( 'title', 'This groups the contained content.' ); 121 121 * $tags->remove_attribute( 'data-test-id' ); … … 186 186 * ```php 187 187 * $total_todos = 0; 188 * while ( $p->next_tag( [ 'tag_name' => 'UL', 'class_name' => 'todo' ]) ) {188 * while ( $p->next_tag( array( 'tag_name' => 'UL', 'class_name' => 'todo' ) ) ) { 189 189 * $p->set_bookmark( 'list-start' ); 190 * while ( $p->next_tag( [ 'tag_closers' => 'visit' ]) ) {190 * while ( $p->next_tag( array( 'tag_closers' => 'visit' ) ) ) { 191 191 * if ( 'UL' === $p->get_tag() && $p->is_tag_closer() ) { 192 192 * $p->set_bookmark( 'list-end' ); … … 425 425 * // <div id="test-4" class=outline title="data:text/plain;base64=asdk3nk1j3fo8"> 426 426 * // ^ parsing will continue from this point 427 * $this->attributes = [427 * $this->attributes = array( 428 428 * 'id' => new WP_HTML_Attribute_Match( 'id', null, 6, 17 ) 429 * ];429 * ); 430 430 * 431 431 * // when picking up parsing again, or when asking to find the 432 432 * // `class` attribute we will continue and add to this array 433 * $this->attributes = [433 * $this->attributes = array( 434 434 * 'id' => new WP_HTML_Attribute_Match( 'id', null, 6, 17 ), 435 435 * 'class' => new WP_HTML_Attribute_Match( 'class', 'outline', 18, 32 ) 436 * ];436 * ); 437 437 * 438 438 * // Note that only the `class` attribute value is stored in the index. … … 459 459 * ```php 460 460 * // Add the `wp-block-group` class, remove the `wp-group` class. 461 * $classname_updates = [461 * $classname_updates = array( 462 462 * // Indexed by a comparable class name 463 463 * 'wp-block-group' => WP_HTML_Tag_Processor::ADD_CLASS, 464 464 * 'wp-group' => WP_HTML_Tag_Processor::REMOVE_CLASS 465 * ];465 * ); 466 466 * ``` 467 467 * … … 519 519 * 520 520 * // Correspondingly, something like this will appear in this array. 521 * $lexical_updates = [521 * $lexical_updates = array( 522 522 * WP_HTML_Text_Replacement( 14, 28, 'https://my-site.my-domain/wp-content/uploads/2014/08/kittens.jpg' ) 523 * ];523 * ); 524 524 * ``` 525 525 * … … 661 661 * $p = new WP_HTML_Tag_Processor( $html ); 662 662 * $in_list = false; 663 * while ( $p->next_tag( [ 'tag_closers' => $in_list ? 'visit' : 'skip' ]) ) {663 * while ( $p->next_tag( array( 'tag_closers' => $in_list ? 'visit' : 'skip' ) ) ) { 664 664 * if ( 'UL' === $p->get_tag() ) { 665 665 * if ( $p->is_tag_closer() ) { … … 1604 1604 * ```php 1605 1605 * $p = new WP_HTML_Tag_Processor( '<div enabled class="test" data-test-id="14">Test</div>' ); 1606 * $p->next_tag( [ 'class_name' => 'test' ]) === true;1606 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; 1607 1607 * $p->get_attribute( 'data-test-id' ) === '14'; 1608 1608 * $p->get_attribute( 'enabled' ) === true; 1609 1609 * $p->get_attribute( 'aria-label' ) === null; 1610 1610 * 1611 * $p->next_tag( []) === false;1611 * $p->next_tag( array() ) === false; 1612 1612 * $p->get_attribute( 'class' ) === null; 1613 1613 * ``` … … 1687 1687 * ```php 1688 1688 * $p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' ); 1689 * $p->next_tag( [ 'class_name' => 'test' ]) === true;1689 * $p->next_tag( array( 'class_name' => 'test' ) ) === true; 1690 1690 * $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' ); 1691 1691 * 1692 * $p->next_tag( []) === false;1692 * $p->next_tag( array() ) === false; 1693 1693 * $p->get_attribute_names_with_prefix( 'data-' ) === null; 1694 1694 * ``` … … 1721 1721 * ```php 1722 1722 * $p = new WP_HTML_Tag_Processor( '<DIV CLASS="test">Test</DIV>' ); 1723 * $p->next_tag( []) === true;1723 * $p->next_tag( array() ) === true; 1724 1724 * $p->get_tag() === 'DIV'; 1725 1725 * 1726 * $p->next_tag( []) === false;1726 * $p->next_tag( array() ) === false; 1727 1727 * $p->get_tag() === null; 1728 1728 * ``` … … 1748 1748 * ```php 1749 1749 * $p = new WP_HTML_Tag_Processor( '<div></div>' ); 1750 * $p->next_tag( [ 'tag_name' => 'div', 'tag_closers' => 'visit' ]);1750 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); 1751 1751 * $p->is_tag_closer() === false; 1752 1752 * 1753 * $p->next_tag( [ 'tag_name' => 'div', 'tag_closers' => 'visit' ]);1753 * $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) ); 1754 1754 * $p->is_tag_closer() === true; 1755 1755 * ```
Note: See TracChangeset
for help on using the changeset viewer.