Make WordPress Core

Changeset 63293


Ignore:
Timestamp:
08/13/2026 02:29:46 PM (2 months ago)
Author:
zieladam
Message:

HTML API: Make class_list() examples interactive.

Converts the WP_HTML_Processor::class_list() and WP_HTML_Tag_Processor::class_list() examples to runnable WordPress Playground snippets. Corrects the encoded closing angle bracket so the expected output matches the parsed class name.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13034.

Props jonsurrell.
See #64896.

Location:
trunk/src/wp-includes/html-api
Files:
2 edited

Legend:

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

    r62716 r63293  
    54325432         * This generator function is designed to be used inside a "foreach" loop.
    54335433         *
    5434          * Example:
    5435          *
    5436          *     $p = WP_HTML_Processor::create_fragment( "<div class='free &lt;egg&lt;\tlang-en'>" );
    5437          *     $p->next_tag();
    5438          *     foreach ( $p->class_list() as $class_name ) {
    5439          *         echo "{$class_name} ";
    5440          *     }
    5441          *     // Outputs: "free <egg> lang-en "
     5434         * ```php interactive
     5435         * <?php
     5436         * require '/wordpress/wp-load.php';
     5437         * $p = WP_HTML_Processor::create_fragment( "<div class='free &lt;egg&gt;\tlang-en'>" );
     5438         * $p->next_tag();
     5439         * foreach ( $p->class_list() as $class_name ) {
     5440         *   var_dump( $class_name );
     5441         * }
     5442         * ```
     5443         * ```expected-output
     5444         * string(4) "free"
     5445         * string(5) "<egg>"
     5446         * string(7) "lang-en"
     5447         * ```
    54425448         *
    54435449         * @since 6.6.0 Subclassed for the HTML Processor.
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r63179 r63293  
    11791179         * This generator function is designed to be used inside a "foreach" loop.
    11801180         *
    1181          * Example:
    1182          *
    1183          *     $p = new WP_HTML_Tag_Processor( "<div class='free &lt;egg&lt;\tlang-en'>" );
    1184          *     $p->next_tag();
    1185          *     foreach ( $p->class_list() as $class_name ) {
    1186          *         echo "{$class_name} ";
    1187          *     }
    1188          *     // Outputs: "free <egg> lang-en "
     1181         * ```php interactive
     1182         * <?php
     1183         * require '/wordpress/wp-load.php';
     1184         * $p = new WP_HTML_Tag_Processor( "<div class='free &lt;egg&gt;\tlang-en'>" );
     1185         * $p->next_tag();
     1186         * foreach ( $p->class_list() as $class_name ) {
     1187         *   var_dump( $class_name );
     1188         * }
     1189         * ```
     1190         * ```expected-output
     1191         * string(4) "free"
     1192         * string(5) "<egg>"
     1193         * string(7) "lang-en"
     1194         * ```
    11891195         *
    11901196         * @since 6.4.0
Note: See TracChangeset for help on using the changeset viewer.