Created
May 25, 2019 06:28
-
-
Save KaineLabs/ca960e638691d6e3e7efa2564d1a3a40 to your computer and use it in GitHub Desktop.
Create Custom Activity Group Feed in The Activity Stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create Custom Activity Group Feed in The Activity Stream | |
*/ | |
function yzc_add_custom_group_activity_directory_tab() { | |
$tab_title = __( 'Custom Group', 'youzer' ); | |
?> | |
<li id="activity-custom-group"> | |
<a href="<?php echo esc_url( bp_loggedin_user_domain() . bp_get_activity_slug() . '/custom-group' ); ?>"><?php echo $tab_title; ?></a> | |
</li> | |
<?php | |
} | |
// Add Group Before All Members Tab0 | |
add_action( 'bp_before_activity_type_tab_all', 'yzc_add_custom_group_activity_directory_tab' ); | |
/** | |
* Filter Activity By Group ID. | |
*/ | |
function yzc_custom_group_filter_activity_scope( $retval = array(), $filter = array() ) { | |
// Determine Custom Groups ID. | |
$group_ids = array( 1 ); | |
// Determine the user_id. | |
if ( ! empty( $filter['user_id'] ) ) { | |
$user_id = $filter['user_id']; | |
} else { | |
$user_id = bp_displayed_user_id() | |
? bp_displayed_user_id() | |
: bp_loggedin_user_id(); | |
} | |
// Should we show all items regardless of sitewide visibility? | |
$show_hidden = array(); | |
if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) { | |
$show_hidden = array( | |
'column' => 'hide_sitewide', | |
'value' => 0 | |
); | |
} | |
$retval = array( | |
'relation' => 'AND', | |
array( | |
'relation' => 'AND', | |
array( | |
'column' => 'component', | |
'value' => buddypress()->groups->id | |
), | |
array( | |
'column' => 'item_id', | |
'compare' => 'IN', | |
'value' => (array) $group_ids | |
), | |
), | |
$show_hidden, | |
// Overrides. | |
'override' => array( | |
'filter' => array( 'user_id' => 0 ), | |
'show_hidden' => true | |
), | |
); | |
return $retval; | |
} | |
add_filter( 'bp_activity_set_custom-group_scope_args', 'yzc_custom_group_filter_activity_scope', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment