Opened 14 years ago
Closed 12 years ago
#1478 closed defect (bug) (fixed)
Profile pages have body class "error404"
Reported by: | Nightgunner5 | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 2.3 | Priority: | normal |
Severity: | normal | Version: | 2.0 |
Component: | Component - Users | Keywords: | |
Cc: | jfarthing84, wordpress@… |
Description
This makes it very hard to theme profile pages. In addition, to make theming easier, and to follow the style of "pork" produced by government bills, we should have a body class for bbPress pages. (How about bbp?)
Change History (17)
#2
@
12 years ago
- Cc jfarthing84 added
- Keywords dev-feedback added
- Priority changed from lowest to normal
- Resolution fixed deleted
- Severity changed from trivial to normal
- Status changed from closed to reopened
- Version set to 2.0
This is actually not fixed. The "error404" class is still appended.
The "error404" class is only appended if is_404
returns true. So, somewhere along the line, BBP is not properly setting the is_404
flag to false.
With the Twenty Eleven theme, the "error404" body class severely messes up the page when using a sidebar.
#4
@
12 years ago
- Cc wordpress@… added
Related #1973. I can confirm this is still happening in trunk. I'm pretty sure I fixed this in one of my sites. Will check.
#5
@
12 years ago
- Milestone changed from 2.0 to 2.3
The problem is that for user profile queries we're not setting any is_xxxx so, as @jfarthing84 said, WP::handle_404 is setting is_404. Interestingly, if the query gets any results, WP::handle_404 will set is_404 to false. But the query we are running in this page is:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (wp_posts.post_author = 822) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'closed' OR wp_posts.post_status = 'spam' OR wp_posts.post_status = 'private' OR wp_posts.post_status = 'hidden') ORDER BY wp_posts.menu_order, wp_posts.post_date DESC LIMIT 0, 10
So, only users with posts type 'post' won't get is_404 = true.
I can think of a few diff ways of fixing this, but the easiest (and less hacky-est IMHO) is: in bbp_parse_query, just where we set (line 381)
$posts_query->bbp_is_single_user = true;
we should also set
$posts_query->is_author = true;
#6
follow-up:
↓ 8
@
12 years ago
The problem with the above approach is we're incorrectly setting is_author, when we're not actually viewing the blog author's index. I'd rather we override is_404 and set it back to false, so as not to confuse any other plugin that might be looking for legitimate author pages.
#7
@
12 years ago
Just for reference, here is the method I am using on my own installation:
function fix_bbp_404() { global $wp_query; if ( $wp_query->bbp_is_single_user || $wp_query->bbp_is_single_user_edit || $wp_query->bbp_is_view ) { $wp_query->is_404 = false; // Unset nocache_headers foreach( wp_get_nocache_headers() as $name => $field_value ) { @header( "{$name}: " ); } // Set status 200 status_header( 200 ); } } add_action( 'wp', 'fix_bbp_404' );
#8
in reply to:
↑ 6
@
12 years ago
- Keywords dev-feedback removed
Replying to johnjamesjacoby:
The problem with the above approach is we're incorrectly setting is_author, when we're not actually viewing the blog author's index.
True. I never use the standard user profile page. I always add two loops of topics / replies, so I totally forgot that's not really the profile functionality.
Considering that, @jfarthing84 snippet seems to do the trick.
#9
@
12 years ago
Since the 404 happens after parse_query, is there value in having a brute-force bbp_no_404() action similar to above in core?
#10
@
12 years ago
A lot of themes actually style differently using the 404 body class. Not to mention the 404 template. So, yes, it is necessary.
#13
@
12 years ago
I'm not seeing 404's on the user profile pages or in the title tags in any theme on trunk. Someone able to include detailed reproduction steps?
For what it's worth, bbp_parse_query() sets is_404 to false if a user is found at the URL. That should be sufficient to prevent loading a 404 template or feeding a 404 class into the body element.
#14
follow-up:
↓ 15
@
12 years ago
So, I've concluded that this only happens when a single-user.php template exists. Not sure why though.
#15
in reply to:
↑ 14
@
12 years ago
Replying to jfarthing84:
So, I've concluded that this only happens when a single-user.php template exists. Not sure why though.
That's exactly the information we've been missing. Fix incoming.
(In [2926]) Add specific classes to body_class. Fixes #1478.