WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#32481 closed enhancement (fixed)

Pass the original `$user_id` to the filter in `get_the_author_meta()`

Reported by: dlh Owned by: chriscct7
Milestone: 4.3 Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch commit
Focuses: Cc:

Description

The "get_the_author_$field" filter includes $user_id, but there's no way to know whether that $user_id was provided to get_the_author_meta() or inferred from the current post.

So, I couldn't add a filter that acted only when I was sure get_the_author_meta() was called to get meta about the current post author, as opposed to a specific user (or vice versa).

The attached patch would add a parameter to the filter with the original $user_id value.

(The "the_author_$field" filter already provides this information because the_author_meta() passes the $user_id it receives straight to the filter.)

Attachments (3)

32481.patch (1.1 KB) - added by dlh 6 years ago.
32481.2.patch (1.1 KB) - added by chriscct7 6 years ago.
Switch $_old_userid to $old_value per precedence in other functions. Update since to 3.4 and match param description to other
32481.3.patch (1.1 KB) - added by chriscct7 6 years ago.
Variable name to $original_user_id

Download all attachments as: .zip

Change History (9)

@dlh
6 years ago

@chriscct7
6 years ago

Switch $_old_userid to $old_value per precedence in other functions. Update since to 3.4 and match param description to other

#1 @chriscct7
6 years ago

  • Keywords has-patch added
  • Owner set to chriscct7
  • Status changed from new to reviewing

Changed variable based on variable naming precedent from other functions, updated since and matched param comment to one above + precedent documentation for $old_value. Looks good.

#2 @chriscct7
6 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 4.3
  • Status changed from reviewing to accepted

Yep this is good to go. Solid work @dlh :)

#3 follow-up: @sc0ttkclark
6 years ago

I'd prefer $original_user_id for a better contextual variable name and for more clear filter doc purposes.

@chriscct7
6 years ago

Variable name to $original_user_id

#4 in reply to: ↑ 3 @chriscct7
6 years ago

Replying to sc0ttkclark:

I'd prefer $original_user_id for a better contextual variable name and for more clear filter doc purposes.

While I like the additional context it should be noted that we don't have any variable naming precedent for that for old userids like we do with $old_value, and also some people might not like having such a long variable name passed into a filter, particularly if they use a code editor or styling preference that limits the screen width, to say, 80 characters.

#5 @boonebgorges
6 years ago

we don't have any variable naming precedent for that for old userids like we do with $old_value

$ grep -nR "@param [a-zA-Z]\+ \$original_" src/

and similar greps show that we are pretty evenly split between $original_, $raw_, and $old_. IMO, $original_ is the clearest, so let's go with it. (In your own callback functions, you can use whatever short variable name you want.)

#6 @boonebgorges
6 years ago

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

In 32594:

Pass the original $user_id variable to the filter in get_the_author_meta().

Props dlh, chriscct7.
Fixes #32481.

Note: See TracTickets for help on using tickets.