Is there a way I can fetch the WordPress Developer Code References with an API?

It seems to be accessible from:

https://developer.wordpress.org/wp-json/wp/v2/wp-parser-class

https://developer.wordpress.org/wp-json/wp/v2/wp-parser-method

https://developer.wordpress.org/wp-json/wp/v2/wp-parser-hook

https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function

and search with e.g.

https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function?search=get_post_embed

but it’s probably best to generate your own with the WP Parser here:

https://github.com/WordPress/phpdoc-parser

This will create custom post types for

  • wp-parser-hook
  • wp-parser-function
  • wp-parser-class
  • wp-parser-method

and related post meta (to e.g. store function input arguments, line numbers, class type, hook type and namespace) and taxonomies (to store info on files, package, since, namespaces) in your own WP install.

Here’s the theme that runs on the code reference’s site:

https://github.com/WordPress/wordpress.org/tree/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer

There we can see how it displays e.g. a function’s source code and a
list of a input parameters, using the theme’s helper functions get_source() and get_params().

I ran a test with:

cd wp-content
cd plugins
git clone https://github.com/WordPress/phpdoc-parser.git
cd phpdoc-parser/
composer install
wp plugin activate phpdoc-parser
wp parser create /path/to/source/ --user=test

Here’s a screenshot from my test install:

enter image description here

Also more DevHub info here:

https://make.wordpress.org/docs/handbook/devhub/