I keep all hooks in one file, and the functions are organized in their respective classes (different auto-loaded files).

Looking for a standard way to document that a function’s sole purpose is to be called on ‘init’ for example.

Currently using @see 'init'

Thanks!

Example Code

hooks.php

add_action( 'init', 'remove_image_sizes' );

functions.php

/**
  * Removes image sizes added by mistake prior to 1.6.18
  *
  * @since 1.6.18
  * @see 'init'
  * @return void
  */
function remove_image_sizes() {
  remove_image_size( 'foo' );
  remove_image_size( 'bar' );
}

3 Answers
3

Function doc block should document what it does, what it might be useful for, but not who uses it. It makes sense to document that it was designed with hook X in mind but that is it.

Think of unit testing. In that context you are likely to call the function by itself without doing the whole core initialization, which means that a description tying the function to the init hook, will be at least misleading.

The style you are trying to use will also force you to change documentation while changing irrelevant code, like if you will decide to move the call to wp_loaded instead of init

Leave a Reply

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