WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#16702 closed defect (bug) (fixed)

is_blog_user() bug on Multisite

Reported by: MattyRob Owned by: ryan
Milestone: 3.3 Priority: normal
Severity: normal Version: 3.0
Component: Multisite Keywords: dev-feedback
Focuses: Cc:

Description

I've just installed a fresh WordPress 3.1 with Multisite enable and configured and there seems to be a glitch in is_blog_user().

It looks for a capability with a key name of the site prefix . blog_id . _capabilties.

But, the first installed blog on an MU site is installed without the blog_id in the key name.

On my test site for example I have a the main site WPMU and 2 sub site Test1 and Test2.

In the usermeta table there are capability keynames as follows:

wpmu_capabilities (relating the my WPMU site)
wpmu_1_capabilities (relating to Test1)
wpmu_2_capabilities (relating to Test2)

So, is_blog_user() returns false for all users of WPMU as the function is looking for the wrong key name.

Attachments (6)

16702.diff (1.7 KB) - added by solarissmoke 5 years ago.
16702.patch (1.7 KB) - added by SergeyBiryukov 4 years ago.
16702.2.patch (1.8 KB) - added by SergeyBiryukov 4 years ago.
Move into ms-deprecated.php instead of deprecated.php
16702.3.patch (670 bytes) - added by SergeyBiryukov 4 years ago.
16702.4.patch (3.0 KB) - added by SergeyBiryukov 4 years ago.
16702.5.patch (3.0 KB) - added by SergeyBiryukov 4 years ago.

Download all attachments as: .zip

Change History (27)

comment:1 @nacin5 years ago

Yeah, we should be using $wpdb->get_blog_prefix() there.

It looks like it's @since MU, rather than 3.0. I'd recommending using get_blogs_of_user() then look through that, for now. We don't use this function in core and I'd be inclined to deprecate it simply for its simply horrible name.

comment:2 @nacin5 years ago

  • Version changed from 3.1 to 3.0

@solarissmoke5 years ago

comment:3 @solarissmoke5 years ago

  • Keywords has-patch added

You can also use get_users() and look through that.

comment:4 @MattyRob4 years ago

  • Keywords needs-refresh dev-feedback added

Switched to using get_blogs_of_user() as suggested, all works fine.

+1 to commit the proposed patch, deprecate is_blog_user() and close this ticket.

@SergeyBiryukov4 years ago

comment:5 @SergeyBiryukov4 years ago

  • Keywords needs-refresh removed
  • Milestone changed from Awaiting Review to 3.3

Refreshed for 3.3.

@SergeyBiryukov4 years ago

Move into ms-deprecated.php instead of deprecated.php

comment:6 follow-up: @ryan4 years ago

Let's keep this as a wrapper for get_blogs_of_user(). We can deprecate later when we are energetic enough to come up with a better name.

@SergeyBiryukov4 years ago

comment:7 in reply to: ↑ 6 @SergeyBiryukov4 years ago

Replying to ryan:

Let's keep this as a wrapper for get_blogs_of_user().

Done in 16702.3.patch.

comment:9 @ryan4 years ago

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

In [19004]:

Turn is_blog_user() into a convenience wrapper around get_blogs_of_user(). Fixes is_blog_user() for blog prefixes that do not contain a blog ID. Props SergeyBiryukov. fixes #16702

comment:10 @nacin4 years ago

In [19005]:

is_blog_user() is from MU. see #16702.

comment:11 @scribu4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

There's another function: is_user_member_of_blog() which is already a wrapper around get_blogs_of_user().

comment:12 @scribu4 years ago

  • Keywords has-patch removed

We should deprecate one or the other. is_blog_user() is shorter, but is_user_member_of_blog() is more descriptive. Coin toss?

comment:13 follow-up: @scribu4 years ago

We can make is_blog_user() a wrapper for is_user_member_of_blog(), since the later requires a user id.

comment:14 in reply to: ↑ 13 @SergeyBiryukov4 years ago

Replying to scribu:

We can make is_blog_user() a wrapper for is_user_member_of_blog()

That's what I initially was going to do, but that function seems to be only available in Multisite, while is_blog_user() is available on a single site too.

comment:15 @scribu4 years ago

Well, both functions come from MU. It's silly to have one available all the time and one only for multisite.

IMO, we should make is_user_member_of_blog() available all the time.

comment:16 @scribu4 years ago

Or just deprecate the fool, since we have a replacement.

comment:17 follow-up: @ryan4 years ago

I forgot about is_user_member_of_blog(). Move it to user.php, make is_blog_user() wrap it, and deprecate is_blog_user(). How's that sound?

@SergeyBiryukov4 years ago

comment:18 in reply to: ↑ 17 @SergeyBiryukov4 years ago

Replying to ryan:

I forgot about is_user_member_of_blog(). Move it to user.php, make is_blog_user() wrap it, and deprecate is_blog_user(). How's that sound?

Done in 16702.4.patch.

comment:19 @nacin4 years ago

Let's also make $user_id for is_user_member_of_blog() default to 0, thus the current user. Then someone could call is_user_member_of_blog() and be told about the current user's relationship to the current blog. Basically identical to is_blog_user() now but a bit more flexible in the long run.

@SergeyBiryukov4 years ago

comment:20 @ryan4 years ago

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

In [19016]:

Turn is_blog_user() into a wrapper around is_user_member_of_blog() and deprecate. Make user_id optional for is_user_member_of_blog(). Props SergeyBiryukov. fixes #16702

comment:21 @ryan4 years ago

[UT458] covers multisite. Need some single site ones.

Note: See TracTickets for help on using tickets.