Please can somebody for once explain how Filters ? Actions work ?
-
I’ve look at it a few times in the WordPress Codex and it probably explains GREATLY how it works and what it does but maybe I just don’t get it.
I understand the concept of taking a function that exists <—> edit it <—> return it to WP Core but how!
Lets say I just simply want to replace the text inside a HTML “… class=”bbp-topic-spam-link”> ” of the spam link.
First step I do is search for the function: bbp_topic_spam_link()
Second step found it inside plugins/bbpress/includes/topics/template.php [ line 2832 ]
Third step copy the entire function to my functions.php file or plugins functions file.
Fourth step, edit the code that you want to edit but after that, how do you add the filter to this function to make it a new or your function.
/** * Output the spam link of the topic * @uses bbp_get_topic_spam_link() Topic spam link */ function bbp_topic_spam_link( $args = '' ) { echo bbp_get_topic_spam_link( $args ); } /** * Return the spam link of the topic */ function bbp_get_topic_spam_link( $args = '' ) { // Parse arguments against default values $r = bbp_parse_args( $args, array( 'id' => 0, 'link_before' => '', 'link_after' => '', 'sep' => ' | ', 'spam_text' => esc_html__( 'Spam', 'bbpress' ), 'unspam_text' => esc_html__( 'Unspam', 'bbpress' ) ), 'get_topic_spam_link' ); $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) return; $display = bbp_is_topic_spam( $topic->ID ) ? $r['unspam_text'] : $r['spam_text']; $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) ); $uri = wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ); $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-spam-link">' . $display . '</a>' . $r['link_after']; return apply_filters( 'bbp_get_topic_spam_link', $retval, $r ); }
Thanks.
- You must be logged in to reply to this topic.