At Human Made‘s pre WordCamp UK retreat this week at Coniston Water, Herb Miller ( bobbing wide / oik-plugins ) asked Joe Hoyle ( Human Made ) to write some simple PHP to demonstrate the [bw_api] shortcode, from the oik-shortcodes plugin, to create dynamic API documentation of some code.
Joes’s example – a PHP API
Herb’s example – an oik base API
$id = bw_array_get( $atts, "id", null );
When asked how it worked I simply said “magic”. Actually, it uses a standard PHP function to parse the code, token_get_all(), then some other functions to process these. If you can read PHP code and can click on links then you can find out for yourself. Just follow through the APIs. The really hard work is in the loading of all the APIs for each of the plugins; a batch process that’s run twice for each new plugin version. It’s run twice in order to be able to produce the “called by” list.
- bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
- oikai_apiref() – Implement the [bw_api] shortcode
- oikai_handle_token_T_STRING() – Handle a T_STRING token