Info
- 4 posts
- 2 voices
- Started 5 years ago by Mirce
- Latest reply from Mirce
- This topic is not resolved
Editing a function in a plugin - add_action or add_filter
-
- Posted 5 years ago #
Hi,
I am trying to write a plugin and I do not know how can I do it properly.The plugin I am working on requires the editing of the "get_forum_link" function, specifically the "$link " vatiable.
I have the code done in php but do not know how to make a plugin out of it. What and how should I use add_action or add_filter?
Thanx.
function get_forum_link( $forum_id = 0, $page = 1 ) {
global $forum;if ( $forum_id )
$forum = get_forum( $forum_id );
if ( bb_get_option( 'mod_rewrite' ) )
$link = bb_get_option( 'uri' ) . "forum/$forum->forum_id" . ( 1 < $page ? "/page/$page" : '' );
else {
$args = array();
$link = bb_get_option( 'uri' ) . 'forum.php';
$args['id'] = $forum->forum_id;
$args['page'] = 1 < $page ? $page : '';
$link = add_query_arg( $args, $link );
}return apply_filters( 'get_forum_link', $link, $forum->forum_id );
} -
- Posted 5 years ago #
function my_get_forum_link_filter( $link ) { $link = 'yay'; // Whatever you want to do with the link return $link; // Very important line! } add_filter( 'get_forum_link', 'my_get_forum_link_filter' );That last line adds your custom filter function to the get_forum_link filters.
-
- Posted 5 years ago #
Thanx.
I do not know if I've did it right but it does not works. Am I doing something wrong?
The new $link should be
$link = bb_get_option('uri') . "$forum->forum_name" . ( 1 < $page ? "/page/$page" : '' );it all should look like:
function my_get_forum_link_filter( $link ) {
$link = bb_get_option('uri') . "$forum->forum_name" . ( 1 < $page ? "/page/$page" : '' );; // Whatever you want to do with the link
return $link; // Very important line!
}add_filter( 'get_forum_link', 'my_get_forum_link_filter' );
-
- Posted 5 years ago #
Oh,
Nevermind, I think that I've solve it. -
You must log in to post.