Skip to:
Content
Pages
Categories
Search
Top
Bottom

URGENT – How To Set Default Values?

  • @jamiewade

    Member

    On my activity page, I have removed the link that says “All Members (x)” so that my users can only view activity on their stream from people on their friends list. However when you log in, and click on the Activity tab, it still has the default activity filter as “All Members (x)” Although this can be resolved by clicking on “Friends (x)”, I want the friends filter to be displayed as the default? Can this be done? Many thanks.

Viewing 19 replies - 1 through 19 (of 19 total)
  • @jamiewade

    Member

    Anyone? Please??

    @hnla

    Participant

    Slightly early to be bumping. Generally please wait ~24 hours mas o menos

    when you say activity filter you do mean the select dropdown? as I thought that defaulted to ‘No Filter’ or do you mean the actual sub nav tabs in which case you will need to run filter function of some description to remove or re-order default tab

    @jamiewade

    Member

    Sorry, just really want to get this sorted before I launch the site :) I do not wish to edit the dropdown filter, but I want to set the default activity filter to (Friends (x)) which is to the left of the drop down box.

    @pcwriter

    Participant

    @JamieWade

    This thread looks like it might have a workable solution for bp-custom.php. I haven’t tried it though…
    https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/changing-default_subnav_slug-for-activity/

    @jamiewade

    Member

    Hmm I tried this with no success. Here is an image of what I wish to do, if it helps at all.

    Photobucket

    @jamiewade

    Member

    Bump.

    @boonebgorges

    Keymaster

    The most elegant way to do this is to filter bp_ajax_querystring. Detect whether you’re looking at the activity stream, and if the querystring is empty, add arguments that show friends’ activity.

    Here’s a thread with an example on how to build such a filter (yours will do a few more conditional checks first): https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/add-filters-to-if-bp_has_activities-bp_ajax_querystring-activity/#post-88068

    And here is some guidance on the arguments taken by bp_has_activity(): https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/

    @jamiewade

    Member

    I tried adding `<li class="selected"` to the tab but it only selects it for CSS purposes, the friends stream does not show?

    @boonebgorges

    Keymaster

    Right. In order to make the friends stream show, you will have to filter the arguments that go into bp_has_activities(), as described in the links above.

    @jamiewade

    Member

    Hmm I tried this, but nothing? I changed `if ( bp_has_activities( bp_ajax_querystring( ‘activity’ )) ) ?>` to `if ( bp_has_activities( bp_ajax_querystring( ‘friends’ )) ) ?>`

    Here is the code for the whole of the activity-loop.php file

    `

    <?php
    function my_query_filter_new ( $query_string ) {
    $query_string .= ‘&per_page=10’;
    return $query_string;
    }
    add_filter( ‘bp_ajax_querystring’, ‘my_query_filter_new’ );
    if ( bp_has_activities( bp_ajax_querystring( ‘friends’ )) ) ?>

    /* Show pagination if JS is not enabled, since the “Load More” link will do nothing */

    •  

    `

    @jamiewade

    Member

    I had to change the code to this because it broke the drop down menu filter. Please can you tell me what I need to change? Thanks

    `

    <?php
    function my_query_filter_new ( $query_string ) {
    $query_string .= ‘&per_page=10’;
    return $query_string; }
    add_filter( ‘bp_ajax_querystring’, ‘my_query_filter_new’ );
    if ( bp_has_activities( bp_ajax_querystring( ‘friends’ )) ) ?>

    •  

    `

    @jamiewade

    Member

    Bump.

    @jamiewade

    Member

    Second bump, really need this sorted guys! Please :)

    @boonebgorges

    Keymaster

    It looks like you need to do two things.

    1) Don’t do bp_ajax_querystring( ‘friends’ ). The function does not take arguments like ‘friends’. Just do bp_ajax_querystring() in the template file.
    2) Here is a function that, when placed in wp-content/plugins/bp-custom.php, will do what you want:
    `function bbg_my_friends_activity_default( $qs ) {
    if ( is_user_logged_in() && empty( $qs ) && empty( $_POST ) ) {
    $qs = ‘scope=friends’;
    }

    return $qs;
    }
    add_filter( ‘bp_ajax_querystring’, ‘bbg_my_friends_activity_default’, 999 );`

    The problem is that this is almost certain not to work correctly with the function you have in your template file:
    `function my_query_filter_new ( $query_string ) {
    $query_string .= ‘&per_page=10’;
    return $query_string; }
    add_filter( ‘bp_ajax_querystring’, ‘my_query_filter_new’ );`

    If you need this latter functionality, I would try to do some work to combine the functions so that the query strings are added in the proper order.

    @jamiewade

    Member

    @boonebgorges Hmmm I tried adding these codes into the files but it broke the other subnavs? Groups (x) and @username mentions only displayed the activity stream for the whole site? They didn’t show Group activity/mentions respectively.

    @jamiewade

    Member

    This is my new activity-loop.php file. This does not break the sub navs like I posted 5 minutes ago:

    `

    <?php
    if ( bp_has_activities( bp_ajax_querystring( ‘activity’ )) ) ?>

    •  

    `

    And here is my bp-custom.php file:

    `define( ‘BP_ACTIVATION_SLUG’, ‘activate’ );
    define( ‘BP_ACTIVITY_SLUG’, ‘activity’ );
    define( ‘BP_BLOGS_SLUG’, ‘blogs’ );
    define( ‘BP_FORUMS_SLUG’, ‘forums’ );
    define( ‘BP_FRIENDS_SLUG’, ‘friends’ );
    define( ‘BP_GROUPS_SLUG’, ‘groups’ );
    define( ‘BP_MEMBERS_SLUG’, ‘members’ );
    define( ‘BP_MESSAGES_SLUG’, ‘messages’ );
    define( ‘BP_REGISTER_SLUG’, ‘register’ );
    define( ‘BP_SEARCH_SLUG’, ‘search’ );
    define( ‘BP_SETTINGS_SLUG’, ‘settings’ );
    define( ‘BP_XPROFILE_SLUG’, ‘profile’ );

    /** wp-content/plugins/bp-custom.php **/
    function my_change_activity_default_subnav() {
    global $bp;
    if (bp_is_my_profile()) {
    bp_core_new_nav_default(array( ‘parent_slug’ => $bp->activity->slug, ‘screen_function’ => ‘bp_activity_screen_friends’, ‘subnav_slug’ => $bp->friends->slug));
    }
    }
    add_action( ‘bp_setup_nav’, ‘my_change_activity_default_subnav’ );

    function my_change_activity_subnav_sequence() {
    global $bp;
    if (bp_is_my_profile()) {
    // flip just-me and friends positions
    $bp->bp_options_nav = ’20’;
    $bp->bp_options_nav = ’10’;
    }
    }

    function bbg_my_friends_activity_default( $qs ) {
    if ( is_user_logged_in() && empty( $qs ) && empty( $_POST ) ) {
    $qs = ‘scope=friends’;
    }

    return $qs;
    }

    add_filter( ‘bp_ajax_querystring’, ‘bbg_my_friends_activity_default’, 999 );

    add_action( ‘bp_activity_setup_nav’, ‘my_change_activity_subnav_sequence’ );`

    The site is still functional when I have made the changes you suggested, however when I log in and click on the Activity tab, the Friends (x) box is selected, but the activity shown is from the whole site.

    @boonebgorges

    Keymaster

    It sounds like whatever you did in your second post actually made my code not work. I haven’t really got time to debug this, but I would suggest that you reinstate my suggested code the way that it was previously, and then start working with some conditionals in order to make sure that the query string only gets modified when you are looking at the Activity tab. The function `bp_is_activity_component()` may be helpful here.

    @jamiewade

    Member

    I am really sorry @boonebgorges I am such a beginner with PhP I wouldn’t know where to begin :(

    @dains

    Participant

    This approach ought to work with members and groups too I think? My need is to show the “My” tabs as default in those sections. I understand the bp_ajax_querystring approach @boonebgorges put out, but can’t find any documentation on what to throw it (or even ON it – so many undocumented things in BP :( ).

    Can I assume that in that example, ‘friends’ is the slug for that tab? If so, check me on this – I can probably just change the example to detect which main page I’m loading and throw bp_ajax_querystring the slug for the tab to load, and I’ve got my default tabs?

Viewing 19 replies - 1 through 19 (of 19 total)
  • The topic ‘URGENT – How To Set Default Values?’ is closed to new replies.
Skip to toolbar