Skip to:
Content
Pages
Categories
Search
Top
Bottom

404_template hook fires wrongly


  • Peter Raschendorfer
    Participant

    @petersplugins

    Hi,

    I’m the author of the 404page plugin, the most used plugin to create custom 404 error pages. My plugin uses the 404_template filter. Due to a user’s request I found out that this hook fires incorrectly in a particular case caused by bbPress. Of course I can bypass the problem but I wonder if you’d like to fix it because it is a bbPress issue.

    On showing the profile page of a single member bbPress changes the main query to get the topics created by that member. This causes $wp_query->is_404 is set to true because no posts are found. This does not affect bbPress because $wp_query->bbp_is_single_user is set to true which causes the bbPress template loader to load the suitable template file.

    But at the same time the WP core template loader fires the 404_template filter hook. This is fallacious because there is no 404 error.

    I could fix that in my plugin by checking $wp_query->bbp_is_single_user but this would only bypass the problem. It is definitely wrong the 404_template hook fires in that case.

    So I think it would be a good idea to correct this in bbPress. You’d only have to set $wp_query->is_404 to false after the main query was executed in case $wp_query->bbp_is_single_user is true.

    In my opinion the bbp_template_redirect hook would be the right place to do that. Adding one more small function to this hook solves the issue.

    I’m curious about your response.

    Regards,
    Peter

Viewing 6 replies - 1 through 6 (of 6 total)

  • Vinod Dalvi
    Participant

    @vinod-dalvi

    I have tested it on my test site using bbPress Version 2.6-rc-3 but i couldn’t reproduce the issue.

    The 404_template filter doesn’t get fired for me and is_404 function also returns false as shown here https://imgur.com/a/xmfiM

    Could you please describe a bit more in detail how to reproduce it?


    Peter Raschendorfer
    Participant

    @petersplugins

    Thanks for your response. The upcoming version 2.6 seems to solve the issue. I’ve tested it with 2.5.13 yet. Today I’ve tried 2.6-rc-3 and the 404 error is gone.

    My testing environment is WP 4.8.1, no other plugins than bbPress, Twenty Seventeen Theme.

    I’ve added the following lines to the Theme’s functions.php tp figure it out:

    add_filter( '404_template', function() {
      global $wp_query;
      print_r( $wp_query );
      die();
    } );

    In bbPress 2.5.13 the 404_template filter fires and is_404 is true. In 2.6-rc-3 the filter does not fire.

    Would you please do me favor and also check it with 2.5.13 just to be sure?

    Thanks,
    Peter


    Vinod Dalvi
    Participant

    @vinod-dalvi

    I have tested it with WP 4.8.1, no other plugins than bbPress, Twenty Seventeen Theme but it is working fine for me without any issue.

    Please note i am using single site installation and not multisite.


    Vinod Dalvi
    Participant

    @vinod-dalvi

    @peterparkers It is written in PHP language.

    Your question is not related to this topic so please create separate topic for it.


    Peter Raschendorfer
    Participant

    @petersplugins

    After further digging into the code I’ve found the principal reason. It makes no difference if a member has created topics or not. The problem is the main query which always queries for posts. The 404 error appears if the user has not created any posts.

    I’ve created a ticket: https://bbpress.trac.wordpress.org/ticket/3161


    Vinod Dalvi
    Participant

    @vinod-dalvi

    I tested creating new user but still couldn’t reproduce the issue.

    Let’s see what admin says in your trac ticket.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar