Opened 12 years ago
Closed 11 years ago
#4948 closed defect (bug) (fixed)
bp_core_avatar_url() wonky in sub-sites since WP 3.5
Reported by: | r-a-y | Owned by: | r-a-y |
---|---|---|---|
Milestone: | 1.7.1 | Priority: | normal |
Severity: | normal | Version: | 1.6.4 |
Component: | Core | Keywords: | needs-unit-tests |
Cc: | mercijavier@… |
Description
WP 3.5 changed a number of things relating to uploads.
- Changes to
wp_upload_dir()
in multisite - see #WP19235. In particular, see [WP22222]. - On brand-new 3.5 installs, WP does not populate the
'upload_path'
DB option as in previous WP versions.
Point no. 2 will cause bp_core_avatar_url()
to generate the wrong URL when you're using multisite and you're not on the BP root blog:
https://buddypress.trac.wordpress.org/browser/tags/1.7/bp-core/bp-core-avatars.php#L867
To solve this, 01.patch mirrors the changes in r5897 that were made to the bp_core_avatar_upload_path()
function for bp_core_avatar_url()
.
Attachments (3)
Change History (27)
#2
@
12 years ago
I applied the patch to my MS test install and it fixes the display of missing avatar on sub-sites.
Just for reference, I was previously using the code provided by needle in this related ticket:
http://buddypress.trac.wordpress.org/ticket/4252#comment:11
#3
@
12 years ago
In 02.patch, I've created a new function - bp_core_get_upload_dir()
to grab the wp_upload_dir()
data and cache it since we were using it in both bp_core_avatar_url()
and bp_core_avatar_upload_path()
. This was done to prevent using switch_to_blog()
more than once on a page load.
This function is then used in those respective functions to get their values.
Let me know what you think.
#4
@
12 years ago
- Keywords needs-unit-tests added
This looks good at a glance, but I'm worried about breakage. Is it possible to write tests for it? I don't think our suite supports BP_ENABLE_MULTIBLOG at the moment, but at least some of the other cases should be doable.
#5
@
12 years ago
Is it possible to write tests for it?
I tried writing a unit test for this, but a few things are iffy.
1) BP (and WP core) unit tests don't properly emulate a page load for multisite. I've added some code to somewhat address this in our go_to()
method. (See unittests.patch
)
2) The other problem is BP avatar's reliance on constants like BP_AVATAR_URL
and BP_AVATAR_UPLOAD_PATH
as a fallback.
The go_to()
method usually tries to wipe out global variables to start clean and this works for the most part, but you can't wipe out defines.
By the time BP loads up in PHPUnit, the defines are already set.
This causes a problem when trying to use the go_to()
method with a sub-site URL because bp_core_avatar_url()
will just use the define instead of trying to get to the next conditional like a normal new page load would.
- Unit test will stop here - https://buddypress.trac.wordpress.org/browser/tags/1.7/bp-core/bp-core-avatars.php#L847
- And never gets a chance to parse this in multisite - https://buddypress.trac.wordpress.org/browser/tags/1.7/bp-core/bp-core-avatars.php#L865
This gives the illusion that the unit test will pass, but in reality, it should not.
#6
follow-up:
↓ 7
@
12 years ago
If the WP core unit tests don't handle a multisite situation correctly, guess where I think the fix should go ;)
The other problem is BP avatar's reliance on constants like BP_AVATAR_URL and BP_AVATAR_UPLOAD_PATH as a fallback.
Let's introduce wrapper functions for these settings in 1.8, and deprecate direct use of the constant. For the unit tests, we can then add/use a filter.
#7
in reply to:
↑ 6
@
12 years ago
Replying to DJPaul:
Let's introduce wrapper functions for these settings in 1.8, and deprecate direct use of the constant. For the unit tests, we can then add/use a filter.
I like this idea. The first patch seems fine enough for 1.7.1, and the second should work for 1.8. Then we should deprecate the constants that make sense to, and replace them with functions/filters like Paul said above.
#9
@
12 years ago
- Owner set to r-a-y
- Resolution set to fixed
- Status changed from new to closed
In 6964:
#10
@
12 years ago
Thanks for the feedback, guys.
I've:
- Added 01.patch to 1.7-branch
- Added 02.patch to trunk
- Created a new ticket to deprecate the avatar constants - #4965
#11
@
12 years ago
- Milestone changed from 1.7.1 to 1.7.2
- Resolution fixed deleted
- Status changed from closed to reopened
These changes broke avatars that were previously working on multisite installations for me. Also, returning an empty string for the upload directory is potentially dangerous. Will need to give these another look for 1.7.2.
#12
@
12 years ago
My only work-around was to manually set BP_AVATAR_URL to point to the correct location, so let's not deprecate anything completely until I/we can figure out what's happened.
#13
@
12 years ago
If the WP core unit tests don't handle a multisite situation correctly, guess where I think the fix should go ;)
Agreed in theory, but we're already overriding WP_UnitTestCase::go_to()
, so upstream fixes wouldn't help us in the short term anyway. Let's fix in our own testcase, and also suggest upstream changes, and maybe someday we'll be able to join forces with WP core tests more efficiently.
#21
@
11 years ago
- Milestone changed from 1.8.2 to 2.0
I forget what site was complaining, so moving this to 2.0.
#22
@
11 years ago
johnjamesjacoby - Would you mind chiming in here with info about what still needs to be fixed? It's not clear from the thread above just what remains broken.
#24
@
11 years ago
- Milestone changed from 2.0 to 1.7.1
- Resolution set to fixed
- Status changed from reopened to closed
Seeing as the problematic site has somehow disappeared :) I'm going to close this ticket and assume it's a fluke not caused directly by BP. If anyone experiences the problem again, please post here with details.
Thanks, r-a-y. The technique looks good.
I suggest that instead of the first block, we just do:
switch_to_blog()
bails if we attempt to switch to the current blog, so the BP-level check is redundant.