Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user capability check during login redirects #232

Merged
merged 2 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions includes/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace NewfoldLabs\WP\Module\Onboarding;

use DateTime;
use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;

/**
Expand All @@ -13,11 +12,19 @@ class LoginRedirect {
* Handles the redirect to onboarding
*
* @param string $original_redirect The requested redirect URL
* @return string
* @return string The filtered url to redirect to
*/
public static function handle_redirect( $original_redirect ) {
// Don't redirect if user is not an admin
if ( ! current_user_can( 'manage_options' ) ) {
// Current user not always available from wp_get_current_user(), so must reference out of the global
global $user;
// Loading the login screen, or login failures set $user as a WP_Error object.
// We should only override the redirect param if we have a valid logged in user
if ( ! ( $user instanceof \WP_User ) ) {
return $original_redirect;
}

// Only admins should get the onboarding redirect
if ( ! user_can( $user, 'manage_options' ) ) {
return $original_redirect;
}

Expand Down