WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 20 months ago

#14787 closed enhancement (fixed)

Introduce get_edit_user_link()

Reported by: scribu Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

We should have a function for this, similar to get_edit_post_link(), get_edit_comment_link() etc.

Attachments (4)

get_edit_user_link.patch (935 bytes) - added by Ornani 4 years ago.
14787.diff (5.3 KB) - added by scribu 4 years ago.
14787.2.diff (590 bytes) - added by SergeyBiryukov 21 months ago.
14787.3.diff (472 bytes) - added by SergeyBiryukov 21 months ago.

Download all attachments as: .zip

Change History (14)

Ornani4 years ago

comment:1 Ornani4 years ago

  • Keywords needs-testing reporter-feedback added

I've made a patch but haven't tested it.

scribu4 years ago

comment:2 scribu4 years ago

  • Keywords reporter-feedback removed

I also started to make a patch, even before opening this ticket, but didn't have time to complete it.

Posting it now to avoid duplicate effort. See 14787.diff

comment:3 nacin3 years ago

  • Keywords has-patch added; needs-testing removed
  • Milestone changed from Awaiting Review to Future Release

comment:4 nacin22 months ago

  • Milestone changed from Future Release to 3.5

There's a get_edit_user_link() in #20307 as well.

comment:5 georgestephanis22 months ago

Patch merging this with #20307 is in ... you guessed it ... #20307

comment:6 ryan21 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21364]:

Introduce get_edit_user_link(). Props scribu, georgestephanis, johnbillion. fixes #14787 see #20307

SergeyBiryukov21 months ago

comment:7 SergeyBiryukov21 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Since [21364], if you try to log in as a subscriber, you'll get a blank screen.

Here's a rundown of what happens:

  1. In wp-login.php, get_edit_user_link() is called:
    http://core.trac.wordpress.org/browser/trunk/wp-login.php?rev=21421#L628
  2. In get_edit_user_link(), get_current_user_id() and current_user_can() are called: http://core.trac.wordpress.org/browser/trunk/wp-includes/link-template.php?rev=21421#L1059
  3. Since cookies are not set yet, both functions fail and an empty string is returned.
  4. There's nowhere to redirect, so exit() in line 632 leaves you with a blank screen.
  5. If you refresh the page, the user's profile appears as expected, since cookies are already set and wp_get_current_user() returns the actual user.

14787.2.diff fixes the issue by calling wp_set_current_user() before trying to get the profile link in wp-login.php. We could instead pass $user->ID to get_edit_user_link() to avoid get_current_user_id(), but current_user_can() would fail anyway.

An alternative would be to revert to admin_url( 'profile.php' ).

comment:8 georgestephanis21 months ago

Or just change the default for the value passed to be an empty string, in which case, get_current_user_id() == $user_id would evaluate to true, and return profile.php ... no?

EDIT: Ignore me, I didn't look at the trunk version, I was looking at 14787.diff

Last edited 21 months ago by georgestephanis (previous) (diff)

SergeyBiryukov21 months ago

comment:9 SergeyBiryukov21 months ago

14787.3.diff brings back admin_url() in wp-login.php (as per nacin's suggestion).

comment:10 ryan20 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In [21507]:

Use admin_url() instead of get_edit_user_link() in wp-login.php since cookies are not yet set. Props SergeyBiryukov. fixes #14787

Note: See TracTickets for help on using tickets.