Where do the action or filter parameters come from?

advertisements

Here is simple filter function in WordPress.
I have understood the main course of this code, but one thing is not clear. I did't pass $content parameter in add_filter function but where did it come from?

If WordPress support default parameter, it's ok then how to know what parameters are possible for specific filter or action event?

<?php
  add_filter( 'the_content', 'prowp_profanity_filter' );
   function prowp_profanity_filter( $content ) {
     $profanities = array( 'sissy', 'dummy' );
     $content = str_ireplace( $profanities, '[censored]', $content );
     return $content;
 }
?>

Thanks.


the_content filter hook is located inside the_content() function which code is defined in wp-includes/post-template.php core file (starting at line 222):

/**
 * Display the post content.
 *
 * @since 0.71
 *
 * @param string $more_link_text Optional. Content for when there is more text.
 * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
 */
function the_content( $more_link_text = null, $strip_teaser = false) {
    $content = get_the_content( $more_link_text, $strip_teaser );
    /**
     * Filters the post content.
     *
     * @since 0.71
     *
     * @param string $content Content of the current post.
     */
    $content = apply_filters( 'the_content', $content );
    $content = str_replace( ']]>', ']]&gt;', $content );
    echo $content;
}

If you have a look to the code you will understand that $content parameter used in the filter hook is used also used as a variable in that function to manipulate the data passed through it, before outputting it.

Each action and filter hooks have their own parameter defined in the core code files or templates, as they are a way to change default behaviors, without changing the source code of that core files or templates.

I hope that this is answering to your question.

Also searching on internet, you will easily find a list of all existing filter hooks and action hooks with their respective parameters.