Skip to:
Content
Pages
Categories
Search
Top
Bottom

Editing a function in a plugin – add_action or add_filter

  • @mirce

    Member

    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 = $forum->forum_id;

    $args = 1 < $page ? $page : ”;

    $link = add_query_arg( $args, $link );

    }

    return apply_filters( ‘get_forum_link’, $link, $forum->forum_id );

    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • @mdawaffe

    Member
    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.

    @mirce

    Member

    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’ );

    @mirce

    Member

    Oh,

    Nevermind, I think that I’ve solve it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar