Skip to content

Commit

Permalink
PROD-8364 Timeline filters settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-yudhisthir committed Jan 8, 2025
1 parent 5321665 commit 755310b
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 9 deletions.
69 changes: 69 additions & 0 deletions src/bp-core/admin/bp-core-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,75 @@ function bb_admin_setting_callback_activity_filters() {
<?php
}

/**
* Enable profile timeline filters with scopes like groups, friends, mentions, following etc.
*
* @since BuddyBoss [BBVERSION]
*/
function bb_admin_setting_callback_activity_timeline_filters() {
?>
<label><?php esc_html_e( 'Allow members to filter activity posts by:', 'buddyboss' ); ?></label>
<br /><br />
<div class="bb_activity_filter_options_container bb-activity-sorting-list">
<?php
$filter_labels = bb_get_activity_timeline_filter_options_labels();

// Retrieve the saved options.
$activity_filters = bb_get_enabled_activity_timeline_filter_options();
if ( ! empty( $activity_filters ) ) {

// Sort filter labels based on the order of $activity_filters.
$sorted_filter_labels = array();
foreach ( $activity_filters as $key => $value ) {
if ( isset( $filter_labels[ $key ] ) ) {
$sorted_filter_labels[ $key ] = $filter_labels[ $key ];
}
}

// Add the remaining labels that were not part of $activity_filters.
if ( count( $filter_labels ) > count( $sorted_filter_labels ) ) {
foreach ( $filter_labels as $key => $label ) {
if ( ! isset( $sorted_filter_labels[ $key ] ) ) {
$sorted_filter_labels[ $key ] = $label;
}
}
}
} else {
$sorted_filter_labels = $filter_labels;
}

foreach ( $sorted_filter_labels as $key => $label ) :
$readonly = '';
if ( 'just-me' === $key ) {
$readonly = 'disabled';
}
?>
<div class="bb-activity-sorting-item">
<input
type="hidden"
name="bb_activity_timeline_filter_options[<?php echo esc_attr( $key ); ?>]"
value="<?php echo ( 'just-me' === $key ) ? 1 : 0; ?>"
<?php echo isset( $activity_filters[ $key ] ) && ! empty( (bool) $activity_filters[ $key ] ) && 'just-me' !== $key ? 'disabled' : ''; ?>
/>
<input
<?php echo $readonly; ?>
id="bb_activity_filter_<?php echo esc_attr( $key ); ?>"
name="bb_activity_timeline_filter_options[<?php echo esc_attr( $key ); ?>]"
type="checkbox"
value="1"
<?php checked( isset( $activity_filters[ $key ] ) && ! empty( (bool) $activity_filters[ $key ] ) ); ?>
/>
<label for="bb_activity_timeline_filter_<?php echo esc_attr( $key ); ?>">
<?php esc_html_e( $label ); ?>
</label>
</div>
<?php
endforeach;
?>
</div>
<?php
}

/**
* Enable activity sorting options.
*
Expand Down
3 changes: 3 additions & 0 deletions src/bp-core/admin/settings/bp-admin-setting-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function register_fields() {
// Activity filters.
$this->add_field( 'bb_activity_filter_options', __( 'Activity filters', 'buddyboss' ), 'bb_admin_setting_callback_activity_filters' );

// Timeline filters.
$this->add_field( 'bb_activity_timeline_filter_options', __( 'Profile Timeline filters', 'buddyboss' ), 'bb_admin_setting_callback_activity_timeline_filters' );

// Activity sorting.
$this->add_field( 'bb_activity_sorting_options', __( 'Activity sorting', 'buddyboss' ), 'bb_admin_setting_callback_activity_sorting' );

Expand Down
48 changes: 44 additions & 4 deletions src/bp-core/bp-core-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -2768,12 +2768,12 @@ function bb_is_send_ajax_request() {
function bb_get_activity_filter_options_labels() {
$filters = array(
'all' => __( 'All updates', 'buddyboss' ),
'just-me' => __( 'Created by me', 'buddyboss' ),
'favorites' => __( "I've reacted to", 'buddyboss' ),
'friends' => __( 'From my connections', 'buddyboss' ),
'groups' => __( 'From my groups', 'buddyboss' ),
'friends' => __( 'From my connections', 'buddyboss' ),
'mentions' => __( "I'm mentioned in", 'buddyboss' ),
'following' => __( "I'm following", 'buddyboss' ),
'just-me' => __( 'Created by me', 'buddyboss' ),
);
return (array) apply_filters( 'bb_get_activity_filter_options_labels', $filters );
}
Expand All @@ -2789,16 +2789,56 @@ function bb_get_activity_filter_options_labels() {
*/
function bb_get_enabled_activity_filter_options( $default = array(
'all' => 1,
'just-me' => 1,
'favorites' => 1,
'friends' => 1,
'groups' => 1,
'friends' => 1,
'mentions' => 1,
'following' => 1,
'just-me' => 1,
) ) {
return (array) apply_filters( 'bb_get_enabled_activity_filter_options', bp_get_option( 'bb_activity_filter_options', $default ) );
}

/**
* Get all activity timeline filters option labels.
*
* @since BuddyBoss [BBVERSION}
*
* @return array Array of all activity timeline filters option labels.
*/
function bb_get_activity_timeline_filter_options_labels() {
$filters = array(
'just-me' => __( 'Personal posts', 'buddyboss' ),
'favorites' => __( 'Reacted to', 'buddyboss' ),
'groups' => __( 'From groups', 'buddyboss' ),
'friends' => __( 'From connections', 'buddyboss' ),
'mentions' => __( 'Mentioned in', 'buddyboss' ),
'following' => __( 'Following', 'buddyboss' ),

);
return (array) apply_filters( 'bb_get_activity_timeline_filter_options_labels', $filters );
}

/**
* Get enabled activity timeline filters options.
*
* @since BuddyBoss [BBVERSION}
*
* @param array $default Array of default activity timeline filter options.
*
* @return array Array of enabled activity timeline filters options.
*/
function bb_get_enabled_activity_timeline_filter_options( $default = array(
'just-me' => 1,
'favorites' => 1,
'groups' => 1,
'friends' => 1,
'mentions' => 1,
'following' => 1,
) ) {
return (array) apply_filters( 'bb_get_enabled_activity_timeline_filter_options', bp_get_option( 'bb_activity_timeline_filter_options', $default ) );
}

/**
* Get all activity sorting options labels.
*
Expand Down
1 change: 1 addition & 0 deletions src/bp-core/bp-core-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -3892,6 +3892,7 @@ function bb_update_to_2_6_80() {
// Migrate activity tabs settings to filters.
if ( ! bp_is_activity_tabs_active() ) {
bp_update_option( 'bb_activity_filter_options', array( 'all' => 1 ) );
bp_update_option( 'bb_activity_timeline_filter_options', array( 'just-me' => 1 ) );
}

set_transient( 'bb_update_to_2_6_80', 'yes', HOUR_IN_SECONDS );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,18 @@
?>
</div><!-- search & filters -->
</div>
<?php if ( bp_is_activity_directory() ) {
$activity_filters = bb_get_enabled_activity_filter_options();
$filters_labels = bb_get_activity_filter_options_labels();
<?php
if ( bp_is_activity_directory() || ( bp_is_user() && bp_is_current_component( 'activity' ) ) ) {

// Timeline filters.
if ( bp_is_user() && bp_is_current_component( 'activity' ) ) {
$activity_filters = bb_get_enabled_activity_timeline_filter_options();
$filters_labels = bb_get_activity_timeline_filter_options_labels();
} else {
$activity_filters = bb_get_enabled_activity_filter_options();
$filters_labels = bb_get_activity_filter_options_labels();
}

arsort( $activity_filters );
$default_selected = key( $activity_filters );
?>
Expand Down Expand Up @@ -111,10 +120,10 @@
continue;
}

if ( 'all' !== $key && ! is_user_logged_in() ) {
if ( bp_is_activity_directory() && 'all' !== $key && ! is_user_logged_in() ) {
continue;
}

if ( isset( $skip_conditions[ $key ] ) && $skip_conditions[ $key ] ) {
continue;
}
Expand Down

0 comments on commit 755310b

Please sign in to comment.