bbPress

Simple, Fast, Elegant

bbPress support forums » Plugins

Editing a function in a plugin - add_action or add_filter

(4 posts)
  • Started 1 year ago by Mirce
  • Latest reply from Mirce
  • This topic is not resolved

Tags:

  1. 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 1 year ago #
  2. 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 1 year ago #
  3. 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 1 year ago #
  4. Oh,
    Nevermind, I think that I've solve it.

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.