Opened 8 years ago
Closed 7 years ago
#6694 closed enhancement (fixed)
filter for $after_member_slug in bp-core-catchuri.php
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.6 | Priority: | normal |
Severity: | normal | Version: | 2.3.3 |
Component: | Route Parser | Keywords: | has-patch reporter-feedback |
Cc: |
Description
Hi,
one can modify the user_domain with the filter "bp_core_get_user_domain".
But there is no way to map this back, so I need a patch like this:
+++ wp-content/plugins/bp-custom.php @@ -265,6 +265,8 @@ function bp_core_set_uri_globals() { // Are we viewing a specific user? if ( $after_member_slug ) { + $after_member_slug = apply_filters( 'bp_core_catchuri_after_member_slug', $after_member_slug); + // Switch the displayed_user based on compatibility mode if ( bp_is_username_compatibility_mode() ) { $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) );
The reason behind this:
I need to create "anonymous" URLs for selected members. The next code-snipped is an example on how to do this.
But be aware, this is just a test to create URLs based on the member-id - not a real anonymizer.
function TEST_anonymize_url($domain, $user_id, $user_nicename, $user_login) { $after_domain = bp_core_enable_root_profiles() ? $user_id : bp_get_members_root_slug() . '/' . $user_id; $domain = trailingslashit( bp_get_root_domain() . '/' . $after_domain ); return $domain; } add_action('bp_core_get_user_domain', 'TEST_anonymize_url', 20, 4); function TEST_de_anonymize_url($after_member_slug) { return bp_members_get_user_nicename($after_member_slug); } add_action('bp_core_catchuri_after_member_slug', 'TEST_de_anonymize_url', 20);
Would be nice, if you could include this in 2.5.
thanks
Klaus
Attachments (3)
Change History (14)
#1
@
8 years ago
- Component changed from Component - Core to API - Rewrite Rules
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 2.5
This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.
7 years ago
#5
@
7 years ago
- Keywords 2nd-opinion added
@boonebgorges or @r-a-y - any concerns with adding this in?
@
7 years ago
In bp_core_set_uri_globals()
add a filter for $after_member_slug
, the portion of the URI immediately following /members/
.
#6
@
7 years ago
- Keywords has-patch reporter-feedback added; good-first-bug needs-patch 2nd-opinion removed
I don't have a problem adding a filter, but putting it inside this conditional block seems like it limits its functionality (and has the potential to introduce bugs). See 6694.diff. This will make callbacks somewhat more complicated; in the situation described by @kmb@…, there may have to be an additional if ( false !== $after_member_slug )
check inside TEST_de_anonymize_url()
. But this seems like a reasonable trade-off for a much more flexible filter.
This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.
7 years ago
#8
@
7 years ago
02.patch
adds the filter to root profile lookups as well. I've also renamed the filter to 'bp_core_set_uri_globals_member_slug'
.
One thing to note is for root profiles, we do a check for a WP User with get_user_by()
. For regular member lookups, we use bp_core_get_userid()
/ bp_core_get_userid_from_nicename()
.
We should probably switch to one method instead of using two different types of lookups here. Might be better to switch to using our BP functions since we have filters in those functions and get_user_by()
doesn't.
This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.
7 years ago
#10
@
7 years ago
6694.02.patch looks good to me!
One thing to note is for root profiles, we do a check for a WP User with get_user_by(). For regular member lookups, we use bp_core_get_userid() / bp_core_get_userid_from_nicename().
Yeah. Let's look at that in a separate ticket. I would like to see that there is test coverage of root profile routing before it happens. (I think there is, but it should be verified.)
Hi @kmb@…
I can't see any immediate problem with adding a filter here! We'll definitely take a look.
I think this is your third trac ticket for BuddyPress, so thank you for contributing!