Skip to content

Commit

Permalink
Change definiton of 'is_open' filter on group directory.
Browse files Browse the repository at this point in the history
Changed previously on group profiles in #3391.

See #3470.
  • Loading branch information
boonebgorges committed Dec 16, 2024
1 parent 3606fd3 commit ec5047b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
14 changes: 7 additions & 7 deletions wp-content/themes/openlab/buddypress/groups/groups-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,8 @@

$is_open = openlab_get_current_filter( 'is_open' );
if ( $is_open ) {
$meta_query['blog_public'] = array(
'key' => 'blog_public',
'value' => [ '1', '0' ],
'operator' => 'IN',
);

$group_args['status'] = 'public';
add_filter( 'bp_groups_get_paged_groups_sql', 'openlab_is_open_group_query_callback', 10, 3 );
add_filter( 'bp_groups_get_total_groups_sql', 'openlab_is_open_group_query_callback', 10, 3 );
}

$active_status = openlab_get_current_filter( 'active-status' );
Expand Down Expand Up @@ -327,6 +322,11 @@
remove_filter( 'bp_groups_get_paged_groups_sql', 'openlab_filter_groups_query_for_active_status', 10 );
remove_filter( 'bp_groups_get_total_groups_sql', 'openlab_filter_groups_query_for_active_status', 10 );
}

if ( $is_open ) {
remove_filter( 'bp_groups_get_paged_groups_sql', 'openlab_is_open_group_query_callback', 10, 3 );

Check failure on line 327 in wp-content/themes/openlab/buddypress/groups/groups-loop.php

View workflow job for this annotation

GitHub Actions / phpstan

Function remove_filter invoked with 4 parameters, 2-3 required.
remove_filter( 'bp_groups_get_total_groups_sql', 'openlab_is_open_group_query_callback', 10, 3 );

Check failure on line 328 in wp-content/themes/openlab/buddypress/groups/groups-loop.php

View workflow job for this annotation

GitHub Actions / phpstan

Function remove_filter invoked with 4 parameters, 2-3 required.
}
?>

<?php
Expand Down
44 changes: 44 additions & 0 deletions wp-content/themes/openlab/lib/group-funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,50 @@ function openlab_filter_groups_query_for_active_status( $sql, $sql_clauses, $r )
return $sql;
}

/**
* Implementation of 'is_open' parameter for groups_get_groups().
*
* @param string $groups_sql The SQL query.
* @param array $sql_clauses The SQL clauses.
* @param array $r The query parameters.
*/
function openlab_is_open_group_query_callback( $groups_sql, $sql_clauses, $r ) {
$is_open = openlab_get_current_filter( 'is_open' );
if ( ! $is_open ) {
return $groups_sql;
}

$original_where_clause = $sql_clauses['where'];

$where_clauses = explode( 'AND', $sql_clauses['where'] );

// Remove the existing g.status clause.
$where_clauses = array_filter(
$where_clauses,
function( $clause ) {
return 0 !== strpos( $clause, 'g.status' );
}
);

$where_clauses[] = "(g.status = 'public' OR gm_blog_public.meta_value = 1)";

$groups_sql = str_replace(
$original_where_clause,
implode( ' AND ', $where_clauses ),
$groups_sql
);

$bp = buddypress();

$groups_sql = str_replace(
$sql_clauses['from'],
$sql_clauses['from'] . " LEFT JOIN {$bp->groups->table_name_groupmeta} gm_blog_public ON (g.id = gm_blog_public.group_id AND gm_blog_public.meta_key = 'blog_public')",
$groups_sql
);

return $groups_sql;
}

/**
* Unhooks group join button if it's disabled for the group.
*/
Expand Down

0 comments on commit ec5047b

Please sign in to comment.