Skip to:
Content
Pages
Categories
Search
Top
Bottom

New filter request for bp_is_single_activity()


  • digitman2
    Participant

    @digitman2

    In /wp-content/plugins/buddypress/bp-core.php, there’s the function bp_is_single_activity() which returns true if viewing a single activity (such as through a permalink to an activity), and false otherwise.

    However, the output of this function controls the layout of the page. If it returns true, then the permalink layout (with the bigger avatar and thought bubbles) is used for showing activities, and if false, then the regular layout is used.

    A client liked the permalink layout better, and he wanted, in certain cases, to have the activities shown in the permalink layout. The only way to do that was by getting this function to return true, however there was no clean way of doing it, and I had to insert an “if ($condition) return true;” in this function to get it to work.

    Can there be a filter added here so in special cases, when required, it can return true?

Viewing 24 replies - 1 through 24 (of 24 total)

  • shanebp
    Moderator

    @shanebp

    Did you try using the existing filter for the function that calls bp_is_single_activity() ?

    bp-core-template.php ->
    bp_get_the_body_class ->
    return apply_filters( ‘bp_get_the_body_class’, $classes, $bp_classes, $wp_classes, $custom_classes );

    btw- what version of BP are you using?
    /wp-content/plugins/buddypress/bp-core.php hasn’t existed for quite awhile


    digitman2
    Participant

    @digitman2

    The function is called from multiple places though, not just once. Its also called when checking the size of the avatar (if single activity, a bigger avatar is shown, otherwise a smaller one).


    modemlooper
    Moderator

    @modemlooper

    Are you wanting a bigger avatar in the activity loop?


    digitman2
    Participant

    @digitman2

    I want the layout for permalinks of activities to be duplicated in other places, including the bigger avatar, thought bubbles, and everything else


    modemlooper
    Moderator

    @modemlooper

    Forcing a function true when it’s not is bad. In the members loop it calls the single activty file you can duplicate that file, rename it and then change the markup. Avatars take arguments to specify size.


    digitman2
    Participant

    @digitman2

    Are you referring to bp-themes/members/single/activity.php? I have already tried copying that file and using it, but even within that file it calls on bp_is_single_activity() to determine which layout to show, and without having it return true it shows the group layout instead. Therefore I’m requesting for a filter to be put in this function. 🙂


    modemlooper
    Moderator

    @modemlooper

    You need to explain better what you want to accomplish because the only difference of a permalink activity and one in a loop is avatar size. You can make the avatar any size you want using defines or passing arguments to avatar

    `define ( ‘BP_AVATAR_THUMB_WIDTH’, 50 );
    define ( ‘BP_AVATAR_THUMB_HEIGHT’, 50 );
    define ( ‘BP_AVATAR_FULL_WIDTH’, 150 );
    define ( ‘BP_AVATAR_FULL_HEIGHT’, 150 );
    define ( ‘BP_AVATAR_ORIGINAL_MAX_WIDTH’, 640 );
    define ( ‘BP_AVATAR_ORIGINAL_MAX_FILESIZE’, $max_in_kb );`


    digitman2
    Participant

    @digitman2

    > the only difference of a permalink activity and one in a loop is avatar size.

    That’s not correct. The entire layout is different for permalink and loop activities, including avatar size, size of the activity box itself, size of buttons and text, etc.


    digitman2
    Participant

    @digitman2

    The only way to control which layout is shown (whether single or loop) is to get bp_is_single_activity() to return true, the functions in the loop which govern the layout + avatar size all check this function to decide which avatar size/layout to show.


    modemlooper
    Moderator

    @modemlooper

    Well, I leave you to break it then 😉


    digitman2
    Participant

    @digitman2

    Well, I was hoping my request for a filter is considered. This seems like a reasonable place to add a filter to.


    modemlooper
    Moderator

    @modemlooper

    The different look of single activity is nothing more than css specified by a body class. This function will show you how to add the single css class to different activity streams.

    `function my_custom_class() {

    if( bp_is_activity_component() ) {

    $class = array(‘activity-permalink’);

    return $class;

    }

    }
    add_filter( ‘bp_get_the_body_class’, ‘my_custom_class’);`


    digitman2
    Participant

    @digitman2

    That’s not the only thing though, as I said the avatar is sized differently on the permalink page and regular activity loop. I don’t see why you can’t add a filter to this function? It seems to be needed, users can have other ways of showing a single activity and should have control over whether it is a single activity page or not.

    Are you part of the buddypress team?


    modemlooper
    Moderator

    @modemlooper

    That function can not have filter because it is true or mot based on one thing. You can alter the avatar size by using the define I mentioned above or editing the entry.php file and give the avatar an argument.


    digitman2
    Participant

    @digitman2

    > That function can not have filter because it is true or mot based on one thing.

    Yes, and with a filter, that one thing can be expanded. If someone wants to create their own page for displaying a single activity, they should have a filter here so they can perform their own checks if needed. There are many other boolean functions in wordpress as well as buddypress which have filters.


    modemlooper
    Moderator

    @modemlooper

    The function is not to to test if it’s a single activity item. It’s true if its the permalink for it. There is a difference. But whst you want to accomplish is based on body class easily filterable as I shown. Avatar size easily changed as well. I’m giving you options that you can use now. You can always hack the core and write in your own filter and if it’s solid then submit it has an enhancement to the core.


    digitman2
    Participant

    @digitman2

    Again, its not just the body class, as I said its the avatar as well, plus in future there might be other changes introduced which I’d like to be introduced in my custom pages as well. I don’t see why there can’t be a hook added to this function, it will be a one line change and its consistent with all the other hooks that are added.

    Is it your decision to add/not add a hook?


    modemlooper
    Moderator

    @modemlooper

    Post a request for an enhancement on the trac and it may or may not get added. It’s a trivial request when there are already methods to accomplish what you want. If users want enhancements the best way is to code it youself and submit a patch. That is how open source software works. Anyone can contribute.


    digitman2
    Participant

    @digitman2

    Those methods are not future proof and are hackish, if in future they decide to move the css class from the body to somewhere else, my code will break.

    Thanks for your help though. How can I submit a patch?


    modemlooper
    Moderator

    @modemlooper

    Those classes are not moving. It’s a function that attaches to WordPress core css body classes.

    http://buddypress.trac.wordpress.org


    modemlooper
    Moderator

    @modemlooper

    And I may add it is not hackish at all. It’s the correct way.


    digitman2
    Participant

    @digitman2

    We can agree to disagree on that. There’s a concept in software development called close coupling and loose coupling that you might like to read up on.

    Could I get your comments on this topic?
    https://buddypress.org/support/topic/how-to-restrict-non-logged-in-users-from-viewing-profiles/


    modemlooper
    Moderator

    @modemlooper

    Google it. It’s been posted here so many times with a myriad of solutions.


    digitman2
    Participant

    @digitman2

    I tried googling it before I made an account to ask here! I haven’t been able to find a solution

Viewing 24 replies - 1 through 24 (of 24 total)
  • The topic ‘New filter request for bp_is_single_activity()’ is closed to new replies.
Skip to toolbar