Search code examples
phpwordpresswordpress-themingdocstring

Are docstrings in wordpress of any use?


/**
 * Retrieves the post excerpt.
 *
 * @since 0.71
 * @since 4.5.0 Introduced the `$post` parameter.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string Post excerpt.
 */
function get_content_excerpt( $post = null ) {

I found these docstrings on top of a function in "functions.php" of my Wordpress website. Firstly, are these called "docstrings"?. Secondly, does removing this cause any issue in the functioning. Please explain its importance. I have found no resources that answer my question.


Solution

  • What you're referring to are DocBlocks and are a part of WordPress' PHP Documentation Standards: https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/

    You can read more about the system that it's based on here: https://phpdoc.org/

    In short, they're a standardised form of code documentation that can be interpreted and used in a number of ways. Your IDE for instance may be capable of displaying that information as part of its intellisense.

    Secondly, does removing this cause any issue in the functioning.

    Removing DocBlocks shouldn't cause anything to break but I can't see a valid reason for doing so.