[wp-trac] [WordPress Trac] #11312: Add 'handle_404' hook to allow plugins to route URLs

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 4 19:21:22 UTC 2010


#11312: Add 'handle_404' hook to allow plugins to route URLs
---------------------------+------------------------------------------------
 Reporter:  mikeschinkel   |       Owner:  ryan                    
     Type:  enhancement    |      Status:  new                     
 Priority:  normal         |   Milestone:  Future Release          
Component:  Rewrite Rules  |     Version:  2.9                     
 Severity:  normal         |    Keywords:  needs-patch dev-feedback
---------------------------+------------------------------------------------

Comment(by mikeschinkel):

 '''@Otto24 "Not if you have properly set $wp_query->is_404 to false. Then
 that handle_404() function will set a 200 header status."'''

 How does one '''''properly''''' set $wp_query->is_404 to false?  AFAICT
 that's exactly what I did, still doesn't work.

 '''@Otto42 "Another way to work around it is simply to set your own 200
 header before producing any output. Again, headers are *not* sent until
 output is produced. Check it yourself, use the headers_sent() function to
 determine if the headers have been sent or not at any point in
 execution."'''

 That's a dirty, ugly hack.

 Basically you are letting WordPress go through and set 404 even though
 it's not a 404. That creates potential undefined cases for other plugins
 that may cause them to operate incorrectly.  Your answer is essentially
 "''Just let WordPress think everything is wrong during the entire
 bootstrap process and then fix it at the last second''."  What if some
 other plugin that monitors 404 has already sent data after the headers?

 Sorry, but I don't see how your suggestion can amount to anything other
 than bad software engineering.

 '''@I understand your the problem, I'm just not certain how you're
 experiencing it or why you need to resort to this odd trickery to do what
 you want...'''

 Trickery?  How else am I going to get WordPress to let me have control of
 a URL?  Trickery is reissuing a status header.

 Reissuing a status header is not a problem per se within code you control.
 But the problem here is that WordPress is allowed to run with its state
 variables representing a state which is other than the real state. That's
 a problem and can lead to unexpected errors.  It's like not testing edge
 cases; it works most of the time but not always.

 FYI, routing a simple URL is so hard for most people who are not immersed
 in exactly how WordPress work (such as yourself and maybe 10 other people
 in the world) just throw up their hands and give up.  Case in point, I was
 just hired by a seasoned PHP developer and paid $300 to write a plugin
 that simply routes a set of URLs, nothing more!  It should '''''NOT'''''
 be this hard. I'd rather it be easy and have not made that money, btw.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11312#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list