Make WordPress Core

Changeset 55304


Ignore:
Timestamp:
02/10/2023 10:57:20 AM (18 months ago)
Author:
SergeyBiryukov
Message:

Docs: Replace short array syntax in WP_HTML_Tag_Processor documentation.

Per WordPress PHP Coding Standards:

Using long array syntax ( array( 1, 2, 3 ) ) for declaring arrays is generally more readable than short array syntax ( [ 1, 2, 3 ] ), particularly for those with vision difficulties. Additionally, it’s much more descriptive for beginners.

Arrays must be declared using long array syntax.

Original PR from Gutenberg repository:

Follow-up to [55203], [55206].

Props aristath, poena.
Fixes #57691.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r55206 r55304  
    4141 * ```php
    4242 *     $tags = new WP_HTML_Tag_Processor( $html );
    43  *     if ( $tags->next_tag( [ 'tag_name' => 'option' ] ) ) {
     43 *     if ( $tags->next_tag( array( 'tag_name' => 'option' ) ) ) {
    4444 *         $tags->set_attribute( 'selected', true );
    4545 *     }
     
    6262 * |-----------------------------------------------------------|----------------------------------------------------------------------------|
    6363 * | 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' ) );` |
    6767 *
    6868 * If a tag was found meeting your criteria then `next_tag()`
     
    117117 * Example:
    118118 * ```php
    119  *     if ( $tags->next_tag( [ 'class' => 'wp-group-block' ] ) ) {
     119 *     if ( $tags->next_tag( array( 'class' => 'wp-group-block' ) ) ) {
    120120 *         $tags->set_attribute( 'title', 'This groups the contained content.' );
    121121 *         $tags->remove_attribute( 'data-test-id' );
     
    186186 * ```php
    187187 *     $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' ) ) ) {
    189189 *         $p->set_bookmark( 'list-start' );
    190  *         while ( $p->next_tag( [ 'tag_closers' => 'visit' ] ) ) {
     190 *         while ( $p->next_tag( array( 'tag_closers' => 'visit' ) ) ) {
    191191 *             if ( 'UL' === $p->get_tag() && $p->is_tag_closer() ) {
    192192 *                 $p->set_bookmark( 'list-end' );
     
    425425     *     // <div id="test-4" class=outline title="data:text/plain;base64=asdk3nk1j3fo8">
    426426     *     //                 ^ parsing will continue from this point
    427      *     $this->attributes = [
     427     *     $this->attributes = array(
    428428     *         'id' => new WP_HTML_Attribute_Match( 'id', null, 6, 17 )
    429      *     ];
     429     *     );
    430430     *
    431431     *     // when picking up parsing again, or when asking to find the
    432432     *     // `class` attribute we will continue and add to this array
    433      *     $this->attributes = [
     433     *     $this->attributes = array(
    434434     *         'id'    => new WP_HTML_Attribute_Match( 'id', null, 6, 17 ),
    435435     *         'class' => new WP_HTML_Attribute_Match( 'class', 'outline', 18, 32 )
    436      *     ];
     436     *     );
    437437     *
    438438     *     // Note that only the `class` attribute value is stored in the index.
     
    459459     * ```php
    460460     *     // Add the `wp-block-group` class, remove the `wp-group` class.
    461      *     $classname_updates = [
     461     *     $classname_updates = array(
    462462     *         // Indexed by a comparable class name
    463463     *         'wp-block-group' => WP_HTML_Tag_Processor::ADD_CLASS,
    464464     *         'wp-group'       => WP_HTML_Tag_Processor::REMOVE_CLASS
    465      *     ];
     465     *     );
    466466     * ```
    467467     *
     
    519519     *
    520520     *     // Correspondingly, something like this will appear in this array.
    521      *     $lexical_updates = [
     521     *     $lexical_updates = array(
    522522     *         WP_HTML_Text_Replacement( 14, 28, 'https://my-site.my-domain/wp-content/uploads/2014/08/kittens.jpg' )
    523      *     ];
     523     *     );
    524524     * ```
    525525     *
     
    661661     *     $p = new WP_HTML_Tag_Processor( $html );
    662662     *     $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' ) ) ) {
    664664     *         if ( 'UL' === $p->get_tag() ) {
    665665     *             if ( $p->is_tag_closer() ) {
     
    16041604     * ```php
    16051605     *     $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;
    16071607     *     $p->get_attribute( 'data-test-id' ) === '14';
    16081608     *     $p->get_attribute( 'enabled' ) === true;
    16091609     *     $p->get_attribute( 'aria-label' ) === null;
    16101610     *
    1611      *     $p->next_tag( [] ) === false;
     1611     *     $p->next_tag( array() ) === false;
    16121612     *     $p->get_attribute( 'class' ) === null;
    16131613     * ```
     
    16871687     * ```php
    16881688     *     $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;
    16901690     *     $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );
    16911691     *
    1692      *     $p->next_tag( [] ) === false;
     1692     *     $p->next_tag( array() ) === false;
    16931693     *     $p->get_attribute_names_with_prefix( 'data-' ) === null;
    16941694     * ```
     
    17211721     * ```php
    17221722     *     $p = new WP_HTML_Tag_Processor( '<DIV CLASS="test">Test</DIV>' );
    1723      *     $p->next_tag( [] ) === true;
     1723     *     $p->next_tag( array() ) === true;
    17241724     *     $p->get_tag() === 'DIV';
    17251725     *
    1726      *     $p->next_tag( [] ) === false;
     1726     *     $p->next_tag( array() ) === false;
    17271727     *     $p->get_tag() === null;
    17281728     * ```
     
    17481748     * ```php
    17491749     *     $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' ) );
    17511751     *     $p->is_tag_closer() === false;
    17521752     *
    1753      *     $p->next_tag( [ 'tag_name' => 'div', 'tag_closers' => 'visit' ] );
     1753     *     $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) );
    17541754     *     $p->is_tag_closer() === true;
    17551755     * ```
Note: See TracChangeset for help on using the changeset viewer.