Create code reference à la

In the code reference under you can find all functions, hooks, classes and methods of WordPress. For example, an entry for a function displays which parameters it expects, what return value there is and what the code looks like. Here I describe briefly how something similar can be done.

Some time ago I came up with the idea to provide a code reference for my themes, which provides similar information like the official one from WordPress (you can see the result here at the example of the Photographus theme). The corresponding plugin WP-Parser, which parses the WordPress code for the code reference and creates custom post types from it, is located on GitHub and is not very difficult to use. In addition to PHP 5.4+, Composer and WP-CLI are required.

After the plugin has been installed and activated, it can be executed with the following command:

wp parser create /path/to/source/code --user=<id|login>
Code language: HTML, XML (xml)

This parses the files and inline documentation and creates corresponding CPT entries (there are the CPTs FunctionsMethodsClasses and Hooks).

Of course, the plugin does not provide the output in the frontend. Very useful for this is the code of the theme, which is used for developer. wordpress. org (especially the functions in inc/template-tags.php) - you can get the code via SVN.

However, there is a small problem with the plugin: if you want to parse updated code again, the existing posts will not be updated, but new ones will be created. To solve the problem, I delete all old posts before re-parsing (not elegant, but it works).

Leave a Reply

Your email address will not be published. Required fields are marked *