Skip to content

Commit

Permalink
Add group setting
Browse files Browse the repository at this point in the history
  • Loading branch information
raftaar1191 committed Dec 4, 2023
1 parent 1e381cc commit b909bc3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
26 changes: 24 additions & 2 deletions includes/class-view-analytics-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function view_count_enable() {
/**
* Return the View Analytics show count
*/
public function view_count_show_view_count( $author_id = 0 ) {
public function view_count_show_view_count( $author_id = 0, $group_id = false ) {


if ( empty( $author_id ) ) {
Expand All @@ -125,7 +125,29 @@ public function view_count_show_view_count( $author_id = 0 ) {
return true;
}

return apply_filters( $this->create_filter_key( 'show_view_count' ), $this->is_author( $author_id ) );
/**
* If group id is there check for the Group Admin and Moderations
*/
if(
! empty( $group_id )
&& (
groups_is_user_admin( $author_id, $group_id )
|| groups_is_user_mod( $author_id, $group_id )
)
) {
return true;
}

/**
* If group id is there check for the Group Admin and Moderations
*/
if ( ! empty( $group_id ) ) {
$value = groups_is_user_member( $author_id, $group_id );
} else {
$value = $this->is_author( $author_id );
}

return apply_filters( $this->create_filter_key( 'show_view_count' ), $value );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/media/class-view-analytics-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function view_count_key() {
* Return the View Analytics show count
* Overwrite this for Media View Count
*/
public function view_count_show_view_count( $author_id = false ) {
public function view_count_show_view_count( $author_id = false, $group_id = false ) {

$view = false;

Expand Down
5 changes: 3 additions & 2 deletions public/partials/group/view-analytics-public-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public function __construct( $plugin_name, $version ) {
public function navigation() {

$current_group = groups_get_current_group();
$current_user_id = get_current_user_id();

/**
* Check if the curret user has access to view the Profile View Tab
*/
if ( ! empty( $current_group ) && $this->common->view_count_show_view_count() ) {
if ( ! empty( $current_group->id ) ) {

$group_link = bp_get_group_permalink( $current_group );

Expand All @@ -90,7 +91,7 @@ public function navigation() {
'parent_url' => $group_link,
'position' => 100,
'screen_function' => array( $this, 'view_manage' ),
'user_has_access' => $this->common->can_current_user_view_list() // Only the logged in user can access this on his/her profile
'user_has_access' => $this->common->view_count_show_view_count( $current_user_id, $current_group->id )
) );
}
}
Expand Down

0 comments on commit b909bc3

Please sign in to comment.