php - How to create an "add_filter" function if "filter name" is in the form of "$filter" in apply_filters? -
in 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 change "$replies" using filters. since there "apply_filters" above, think it's possible add "add_filter". seems filter name "$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 case, how can create "add_filter" function?
thanks help.
the filter name, based on methods second parameter $integer
, either bbp_get_topic_post_count_int
(when $integer
true
) or bbp_get_topic_post_count
(when $integer
false
, default parameter value of $integer
, if there isn't value @ method call).
the value of $filter
assigned here:
$filter = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';
therefore, don't need modify method, should search usage of method see input parameter $integer given.
to use filter $integer = true, use:
add_filter( 'bbp_get_topic_post_count_int', 'bbp_get_topic_post_count', 10, 2 );
to use filter $integer = false, use:
add_filter( 'bbp_get_topic_post_count', 'bbp_get_topic_post_count', 10, 2 );
Comments
Post a Comment