如果“过滤器名称”在apply_filters中以“$ filter”的形式创建“add_filter”函数?

In the following WP php code:

function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
        $topic_id = bbp_get_topic_id( $topic_id );
        $replies  = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1;
        $filter   = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';

        return apply_filters( $filter, $replies, $topic_id );
    }

I would like to change "$replies" by using filters. Since there is "apply_filters" above, I think it's possible to add "add_filter". But it seems that the filter name is "$filter"

function bbp_reply_count_modified( $replies, $topic_id ) {
            $topic_id = bbp_get_topic_id( $topic_id );
            $replies  = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ); // deleted '+ 1'
            return $replies;
add_filter( '___________________', 'bbp_reply_count_modified', 10, 2 );

In this case, how can I create an "add_filter" function?

Thanks for your help.

The filter name, based on the methods second parameter $integer, is either bbp_get_topic_post_count_int (when $integer is true) or bbp_get_topic_post_count (when $integer is false, which is the default parameter value of $integer, if there isn't a value for it at method call).

The value of $filter is assigned here:

$filter = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';

Therefore, you don't need to modify the method, but should search for usage of the method to see which input parameter for $integer is given.

To use the filter for $integer = true, use:

add_filter( 'bbp_get_topic_post_count_int', 'bbp_get_topic_post_count', 10, 2 );

To use the filter for $integer = false, use:

add_filter( 'bbp_get_topic_post_count', 'bbp_get_topic_post_count', 10, 2 );