Runnable code examples are now live in the Code Reference

WordPress 7.1 shipped the first two runnable code examples in the Code Reference. They are powered by WordPress Playground, and more are coming in 7.2.

On the WP_HTML_Processor::class_list() Code Reference page, select Run button in the code snippet and the code example will run right there, in your browser.

Runnable snippets can be defined in the DocBlock of each method directly in the WordPress codebase. They use a slightly different syntax from the regular code examples:

<?php
/**
 * Generator for a foreach loop to step through each class name for the matched tag.
 *
 * ```php interactive
 * $p = new WP_HTML_Tag_Processor( "<div class='free &lt;egg&gt;\tlang-en'>" );
 * $p->next_tag();
 * foreach ( $p->class_list() as $class_name ) {
 *   echo "{$class_name} ";
 * }
 * // Outputs: "free <egg> lang-en "
 * ```
 */
public function class_list() {}

The part that makes it interactive is the ```php interactive language tagtag A directory in Subversion. WordPress uses tags to store a single snapshot of a version (3.6, 3.6.1, etc.), the common convention of tags in version control systems. (Not to be confused with post tags.) on the code fence. A handbook page with all the details and instructions for authoring interactive code snippets will be published shortly.

Props to @jonsurrell, @dmsnell, @westonruter.

+make.wordpress.org/docs/

+make.wordpress.org/playground/