WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14382 closed defect (bug) (invalid)

extra pages loading unnecessarily

Reported by: zengy Owned by:
Milestone: Priority: normal
Severity: major Version: 3.0
Component: Rewrite Rules Keywords: regression
Focuses: Cc:

Description (last modified by scribu)

I have a WP3 issue that I came across and I thought it should be posted here. I apologize if this has been posted previously. Please let me know if this issue exists as a current known bug.

I am coding a plugin that needs to do something on 'wp_head'. I was noticing that it was executing my code twice. I am now using error_log() to display the post ID and it is displaying the ID of the page I am loading plus another page ID.

This only happens when loading pages that have subpages associated with them. This bug occurs when a custom permalink structure is chosen. It does not happen when using the default permalink structure.

Here are steps to reproduce this issue:

1) Create a new WP3 site and create a .htaccess file.

2) Install and activate this plugin:

<?php

/*
* Plugin Name: Post ID Test
*/

function display_post_id() {
	global $post;
	error_log('post id: ' . $post->ID . ' | post title: ' . $post->post_title);
}

add_action('wp_head', 'display_post_id');

?>

3) Create the following page hierarchy:

Page 1
  Page 1.1
  Page 1.2
Page 2

4) Change the permalink settings to "Day and Name".

5) Visit the front end for Page 2. Your error log will be something like this:

	[21-Jul-2010 19:59:04] post id: 10 | post title: Page 2

6) Now visit the front end for Page 1. Your error log will be something like this:

	[21-Jul-2010 20:00:46] post id: 4 | post title: Page 1
	[21-Jul-2010 20:00:47] post id: 6 | post title: Page 1.1

7) Page 1.1 generates the following:

	[21-Jul-2010 20:00:58] post id: 6 | post title: Page 1.1
	[21-Jul-2010 20:00:58] post id: 8 | post title: Page 1.2

I tried this in W 2.9.2 and the issue does not exist.

Change History (25)

comment:1 scribu4 years ago

  • Component changed from General to Query
  • Description modified (diff)

comment:2 follow-up: scribu4 years ago

  • Keywords reporter-feedback added; permalinks wp_head pages removed

This is probably a theme issue. Does it happen with Twentyten also?

comment:3 scribu4 years ago

  • Description modified (diff)

comment:4 in reply to: ↑ 2 zengy4 years ago

Replying to scribu:

This is probably a theme issue. Does it happen with Twentyten also?

I thought it may have been a theme issue as well, but it isn't. It happens in Twentyten as well. To make sure, I tested this with a new install of WP3.

comment:5 zengy4 years ago

  • Cc zengy added

comment:6 scribu4 years ago

Instead of error_log(), use debug_print_backtrace() and see what you get.

comment:7 scribu4 years ago

  • Component changed from Query to Rewrite Rules
  • Keywords regression added; reporter-feedback removed
  • Milestone changed from Awaiting Review to 3.1

Bug confirmed. The backtrace is identical in both cases.

comment:8 scribu4 years ago

It seems WP is simply loaded twice.

comment:9 scribu4 years ago

By the way, I'm on ngnix.

comment:10 zengy4 years ago

Glad to see this is happening for you as well. I have a project that is broken currently due to this bug. Is there any early insight as to what might be causing this? If so, I can go make a patch to the WP core to fix it for now.

I am using MAMP.

comment:11 ericmann4 years ago

  • Cc eric@… added

comment:12 zengy4 years ago

  • Severity changed from normal to major

comment:13 azizur4 years ago

  • Cc prodevstudio+wordpress@… added

comment:14 freddyware4 years ago

  • Cc frederick.ding@… added

comment:15 follow-up: dd324 years ago

I cant reproduce this.

Have you disabled all plugins?

What widgets do you have active?

Do the posts have anything in them other than Text? Images? Links?

Beef up the code a bit:

function display_post_id() {
	global $post;
	error_log('post id: ' . $post->ID . ' | post title: ' . $post->post_title . ' | Time:' . $_SERVER['REQUEST_TIME'] . ' | UserAgent:' . $_SERVER['HTTP_USER_AGENT']);
}

add_action('wp_head', 'display_post_id');

See if the User agent reveals anything, If its "WordPress.*" then its likely a HTTP callback, if its the browser, It could be a HTTP Accelerator which caches pages you're likely to visit

comment:16 in reply to: ↑ 15 zengy4 years ago

OK, odd. Now I am not able to replicate it. I am wondering if this was some error in Apache?

comment:17 blepoxp4 years ago

I cannot reproduce this on 3.0.1 with PHP4 or PHP5 on apache.

comment:18 scribu4 years ago

Still there:

post id: 747 | post title: Page 1 | Time:1280697910 | UserAgent:Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8

post id: 749 | post title: Page 1.1 | Time:1280697911 | UserAgent:Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8

comment:19 scribu4 years ago

Just noticed that the problem does not appear if I use curl from the command line. I think Firefox prefetches the URL pointed to by the <link rel='next'> tag.

comment:20 scribu4 years ago

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

Also, the issue doesn not appear in Chrome.

comment:21 scribu4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Oups...

comment:22 scribu4 years ago

  • Milestone 3.1 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

I don't think there's much we can do here.

If somebody does comes up with a patch for this, feel free to reopen.

comment:23 blepoxp4 years ago

Ah. I was testing in Chrome. I can confirm the issue in FF as well.

comment:24 WraithKenny4 years ago

The description for this ticket says that he tested on WP 2.9.2 (presumably with the latest FF) and didn't replicate the bug... so doesn't that mean something changed in WP between 2.9.2 and 3.0?

comment:25 scribu4 years ago

Yes, the thing that probably changed was the addition of the <link rel='next'> tag. I might be wrong though.

Note: See TracTickets for help on using tickets.