Make WordPress Core


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.

File:
1 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.
Note: See TracChangeset for help on using the changeset viewer.