Skip to:
Content

bbPress.org

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#2831 closed task (fixed)

Duplicated code for user profile URL's

Reported by: johnjamesjacoby Owned by: johnjamesjacoby
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.1
Component: Component - Users Keywords: has-patch
Cc:

Description

While fixing #2828, I noticed we still have lots of duplicated code for generating profile URL's that do a bunch of funky string replacements. Let's update all of these to use bbp_get_user_profile_url() like their PHPDoc headers say they do.

Attachments (4)

2831.01.patch (7.7 KB) - added by johnjamesjacoby 4 years ago.
2831.02.patch (9.6 KB) - added by johnjamesjacoby 4 years ago.
2831.03.patch (2.2 KB) - added by thebrandonallen 4 years ago.
2831.03.tests.patch (12.4 KB) - added by thebrandonallen 4 years ago.

Download all attachments as: .zip

Change History (11)

#1 @johnjamesjacoby
4 years ago

This will need testing because bbPress's BuddyPress extension filters bbp_pre_get_user_profile_url

#2 @johnjamesjacoby
4 years ago

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

In 5815:

Users: Use bbp_get_user_profile_url() to avoid code duplication.

This commit removes duplicated code used to build user profile URLs & eliminates several superfluous string replacements. It works with pretty & unpretty permalinks, and plays nicely with the BuddyPress extension for linking to a member's forum sections.

Fixes #2831.

#3 @netweb
4 years ago

In 5897:

Tests: Initial unit tests for /includes/users/template.php

Props netweb. See #2831

This ticket was mentioned in Slack in #bbpress by thebrandonallen. View the logs.


4 years ago

#5 @thebrandonallen
4 years ago

New patches. Below is the description of their fixes.

attachment:2831.03.patch
The function home_url() is ignorant of it's passed data, except to make sure it's a string. So, if you take the string 'yikes' and treat it like this home_url( home_url( home_url( 'yikes' ) ) ), you'll get something like this in return http://example.org/http://example.org/http://example.org/yikes. So, I left the home_url call bbp_get_user_profile_url, and removed it from all the other places where bbp_get_user_profile_url is used as a base.

Also fixed:

  • Replaced bbp_get_user_profile_url() with bbp_get_user_profile_edit_url() in bbp_user_profile_edit_link()
  • Fixed bbp_favorites_permalink by using bbp_get_user_favorites_slug() instead of bbp_get_user_favorites_rewrite_id() for pretty permalinks

attachment:2831.03.tests.patch

  • Updates all tests for functions that use bbp_get_user_profile_url, in some form, to test for both pretty and unpretty permalinks. Also adds new tests where necessary.
  • Fixes avatar tests where get_avatar was expecting a user id and was getting a user object instead
  • Adds a private method to more easily set the permalink structure

#6 @johnjamesjacoby
4 years ago

In 5900:

Users: Remove superfluous home_url() calls introduced in r5815. Also fixed:

  • Replaced bbp_get_user_profile_url() with bbp_get_user_profile_edit_url() in bbp_user_profile_edit_link()
  • Fixed bbp_favorites_permalink() by using bbp_get_user_favorites_slug() instead of bbp_get_user_favorites_rewrite_id()

Props thebrandonallen. See #2831.

#7 @johnjamesjacoby
4 years ago

In 5902:

Users: Add tests for user permalink functions. Props thebrandonallen. See #2831.

Note: See TracTickets for help on using tickets.