bbPress

Simple, Fast, Elegant

bbPress support forums » Plugins

Looking for the right hook

(2 posts)
  • Started 1 year ago by davidbessler
  • Latest reply from davidbessler
  • This topic is not a support question

No tags yet.

  1. I'm REALLY new at making plugins. Let's start there.

    I'm looking to hide certain forums from a defined list of people. Or actually, I'm looking to only allow certain people to see certain forums. Anyway, I'm starting with just trying to make that happen on the front page. How do I "hijack" the page just at the point where it is about to spit out the forums on the front-page? I think this is what hooks are for right? So that I don't need to actually edit my front-page.php?

    Basically what I am looking to do, is during the "foreach" loop in front-page.php, I want to compare the upcoming forum_id with a list of usernames in an array who are allowed to see that forum. If there's a match, it shows the forum, if not, it doesn't.

    The array looks like this:
    $forum_restriction_keys = array(
    "1" => "bob, sam, jim, jane",
    "3" = > "bob",
    );

    So, to start, I need the right hook.

    Posted 1 year ago #
  2. OK look at this:

    $forum_restrict_keys = array(
    "1" => "davidbessler,testman",
    "3" => "davidbessler,",
    );
    function forum_restrict_check_name() {
    global $bb_current_user,$forum_restrict_keys;
    if ($bb_current_user){
    $allowed = strpos($forum_restrict_keys[get_forum_id()], get_user_name( $bb_current_user->ID ));
    if ($allowed == "") {
    echo "[blocked]";
    add_filter( 'get_forum_name', 'forum_restrict_blank_name');
    } else {
    echo "[Not blocked]";
    }
    }
    }
    function forum_restrict_blank_name (){
    echo "";
    }
    add_action( 'get_forum_name', 'forum_restrict_check_name');
    ?>

    That puts [blocked] instead of the forum name in a forum that user is not allowed to see, and [not blocked] on a forum he is allowed to see. How do I get the forum name back in there instead of [not blocked]?

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.