Skip to content

Commit 749ff5d

Browse files
committed
permissions more smoothly.
1 parent 947cc2b commit 749ff5d

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/TouchPoint-WP/Auth.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use tp\TouchPointWP\Interfaces\module;
1111
use tp\TouchPointWP\Utilities\Http;
1212
use tp\TouchPointWP\Utilities\PersonQuery;
13-
use tp\TouchPointWP\Utilities\Session;
1413
use WP_Error;
1514
use WP_User;
1615

@@ -56,7 +55,7 @@ public static function init(): void
5655
add_filter('login_redirect', [self::class, 'redirectLoginCompleteMaybe'], 10, 3);
5756

5857
// If configured, prevent admin bar from appearing for subscribers
59-
add_action('after_setup_theme', [self::class, 'removeAdminBarMaybe']);
58+
self::removeAdminBarMaybe();
6059
}
6160

6261

@@ -200,7 +199,7 @@ public static function redirectLoginCompleteMaybe(string $redirect_to, ?string $
200199
}
201200

202201
$redirect = TouchPointWP::instance()->settings->auth_change_profile_urls === 'on';
203-
$redirect &= !TouchPointWP::userHasEditingPermissions();
202+
$redirect &= !TouchPointWP::userHasEditingPermissions($user);
204203

205204
/**
206205
* Controls whether to redirect to the TouchPoint login automatically.
@@ -210,7 +209,7 @@ public static function redirectLoginCompleteMaybe(string $redirect_to, ?string $
210209
$redirect = apply_filters('tp_redirect_after_login', $redirect);
211210

212211
// if there is no defined redirect page, redirect to the home page
213-
if ($redirect && (!isset($_GET['redirect_to']) || $_GET['redirect_to'] == '')) {
212+
if ($redirect && $redirect_to == '') {
214213
return home_url();
215214
}
216215

@@ -225,7 +224,7 @@ public static function removeAdminBarMaybe(): void
225224
{
226225
$removeBar = (TouchPointWP::instance()->settings->auth_prevent_admin_bar === 'on')
227226
&& !is_admin()
228-
&& !current_user_can('edit_posts');
227+
&& !TouchPointWP::userHasEditingPermissions();
229228

230229
/**
231230
* Allows for hiding the WordPress-provided Admin bar.

src/TouchPoint-WP/TouchPointWP.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,22 +629,20 @@ public static function currentUserIsAdmin(): bool
629629
/**
630630
* Determine if the current user can edit *anything* and therefore may need access to wp-admin.
631631
*
632-
* @param int|null $userId
632+
* @param ?WP_User $user
633633
*
634634
* @return bool
635635
*/
636-
public static function userHasEditingPermissions(?int $userId = null): bool
636+
public static function userHasEditingPermissions(?WP_User $user = null): bool
637637
{
638638
if (!function_exists('get_current_user_id')) {
639639
return false;
640640
}
641641

642-
if ($userId === null) {
643-
$userId = get_current_user_id();
642+
if ($user === null) {
643+
$user = get_user(get_current_user_id());
644644
}
645645

646-
$user = get_user($userId);
647-
648646
if (!$user) {
649647
return false;
650648
}

0 commit comments

Comments
 (0)