gocodebox / gocodebox/lifterlms

Registration reporting widgets in multisite's subsites always show all the sites registrations.

Open
#1,207 2 comments 0 reactions 0 assignees View on GitHub
good first issue hacktoberfest help wanted Type: Bug
Dominant language
PHP
Stars
212
Forks
140
Avg merge
2d 14h
Merged PRs (30d)
19

Description

### Reproduction Steps

+ Set up a multisite with 2 sites.
+ Install LifterLMS in both of them :D.
+ Register a new user into the first subsite, aside from the administrator.
+ For each subsite go to e.g. LifterLMS -> Settings and look at the Registrations widget

### Expected Behavior

+ I would expect to see 1 registration on the first subsite, and 0 on the second one.

### Actual Behavior

+ I see 1 registration for both the subsites.

### Error Messages / Logs

+ Include any relevant error messages or log files
```
n/a

```

### System and Environment Information
->
```
LifterLMS 3.41.0
```

This issue has be recreated:
+ [x] Locally
+ [ ] On a staging site
+ [x] On a production website
+ [x] With only LifterLMS and a default theme

### Browser, Device, and Operating System Information

n/a

### Related User Information
HS-124871

The solution would be to "filter" the users per subsites, by altering the query here:
with a join on the user post meta table where the meta key is something that we can link
to the current blog. E.g:

```
SELECT user_registered AS date
FROM wp_users
JOIN wp_usermeta on ID=user_id WHERE meta_key='wp_2_capabilities'
AND user_registered BETWEEN CAST( '2020-06-11 00:00:00' AS DATETIME ) AND CAST( '2020-06-18 23:23:59' AS DATETIME )
```

The join will be something like:
```php
$join = '';
if ( is_multisite() ) {
$join = "JOIN {$wpdb->usermeta} on ID=user_id WHERE meta_key='{$wpdb->prefix}capabilities'";
$where = 'AND';
} else {
$where = 'WHERE';
}

$where .= " user_registered BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME )";

$this->query_function = 'get_results';
$this->output_type = OBJECT;

$this->query = "SELECT user_registered AS date
FROM {$wpdb->users}
$join
$where
{$student_ids}
;";
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.