Search

bbPress Showcase » bbPress Chat

Looking for if condition, when topic_author (starter) view his topics

RSS

  1. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 36

    offline

    Hi _ck_

    I almost done with my forums which I want to achieve, just one part is left.

    -- Currently, I want to show the threads to the author who started them. In other words, only topic starter can view his threads, not others Or simply, everybody can view their own topics. so, I need private topics only for topic_author not forums!

    Like now I created a topic "Looking for if condition, when topic starter view his thread" for my self. now when I view this topic then some message should appear for me along my topic. (Hellow topic_author, this topic is private for you, and If someone else view this topic then the following message should appear! (Hellow, you are not allowed to view this topic. You can just view your own topics.)I also removed the posts section. I mean no body can write in my topics. it makes any sense?

    -- Note: My forums is only based on topics, not posts.

    ----------------------------------
    Let me give you an example which I did on profile pages.

    In the profile section, Where just allowed logged in users to view and edit their own profiles and where nobody can view other profiles, using something the following code

    --

    <?php if ( bb_is_user_logged_in() ) : ?>

    <?php if (bb_current_user_can( 'edit_user', $user->ID )) : ?>

    My private profile data only viewable for me!

    <?php else : ?>

    Sorry, You're not allowed to view others profiles.

    <?php endif; // bb_current_user_can() ?>

    <?php else : ?>
    Please login to view your profile

    <?php endif; // bb_is_user_logged_in() ?>

    ------------

    I hope now you can guess, what I need..
    So, I'm looking the same way and code for topics pages (Topic.php)

    -- I tried it with <?php if (bb_current_user_can( 'topic_author', $user->ID )) : ?> but it doesn't work, please let me know what is proper function, thank you so much!

    Posted 5 months ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

    Fortunately each topic carries the topic starter id.

    By bypassing the api and just looking directly you can quickly determine if the current user is the topic starter.

    global $bb_current_user,$topic;    // you only need to do this once on a page
    $can_moderate=bb_current_user_can('moderate');  // faster once
    
    if ((!empty($bb_current_user->ID) &&
        !empty($topic->topic_poster) &&
        $bb_current_user->ID==$topic->topic_poster)
        || $can_moderate) {
    
    // it's their topic
    
    } else {
    
    // it's not their topic
    
    }
    Posted 5 months ago #
  3. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 36

    offline

    It works. Thanks _ck_ you are amazing lady!

    Posted 5 months ago #

RSS feed for this topic

Post a reply to “Looking for if condition, when topic_author (starter) view his topics”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
39 users online from in the past 30 minutes. 16 bots 23 guests
3,730 views today 8,638 yesterday 16,043 peak. Most at once 47 today 60 yesterday 131 peak. Visited today: qamilon, pandoracam, lvgalliera
2,288 posts in 394 topics over 66 months by 430 of 2,165 members. Latest: qwe12345100, Janvelden, watchessaleus