Make WordPress Core


Ignore:
Timestamp:
08/13/2026 02:29:46 PM (3 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.