[wp-hackers] Possible bug with endpoints

Jennifer Hodgdon yahgrp at poplarware.com
Fri May 18 23:53:25 GMT 2007


Ah. You also need to add testendpoint to the list of known query 
variables. Try the query_vars action.
     Jennifer

Seamus Leahy wrote:
> 
> 
> On 5/18/07 2:04 PM, "Jennifer Hodgdon" <yahgrp at poplarware.com> wrote:
> 
>> Seamus --
>>
>> I may be wrong, but I don't think you can change the endpoint code as
>> you are suggesting, because I think it will break the use of endpoints
>> of this form:
>>
>>      existingurl/testendpoint/val/
>>
>> Endpoints of this form work with the existing rewrite code, and tell
>> it to set up q['testendpoint'] = 'val' in the query vars. This is used
>> for things like tags, language switching, etc., and appears to be what
>> the endpoint code was set up to do, rather than just having
>>
>>      existingurl/testendpoint/
>>
>> with no trailing value, as you are trying to do.
> 
> You may very well be correct there. I went off for on the little
> documentation I found
> <http://codex.wordpress.org/User:DavidHouse/WP_Rewrite_API#add_endpoint.28.2
> 9>:
> 
>     add_endpoint()
>     Add a new endpoint like /trackback/
> 
> Also, if I try existingurl/testendpoint/fooval/, I cannot find any reference
> to testendpoint or fooval when doing a var_dump of $wp_query with the
> original code.  I assume that those values would exist in $wp_query (I could
> wrong).
>  
>> By the way, did you try isset instead of empty, in your redirect
>> function? It is possible that that will fix your issue, but i am not
>> sure without testing it (or reading the query parsing code more than I
>> have time to do at the moment).
> 
> When I try using isset(), it always returns true because
> get_query_var/$wp_query->get will return an empty string instead of null if
> nothing is found.
> 
>> Hope this helps clarify --
>>      Jennifer
>>
>>
>> Seamus Leahy wrote [in part]:
>>> I think I have found a bug with rewrite endpoints, but I would like for
>>> someone with more experience and knowledge to check it out since I am a
>>> newbie at hacking WordPress.
>> [snipped]
>>
>>> I created a test plugin and I did the testing with WP 2.2.
>>> The plugin:
>>>
>>> -----------------------------------------------------------------
>>> <?php
>>> /*
>>> Plugin Name: Test Endpoint
>>> Plugin URI:
>>> Description: 
>>> Version: 1.0
>>> Author: Seamus Leahy
>>> */
>>> function TestEndpoint(){
>>>     add_action('init', 'TestEndpointInit');
>>>      add_action('template_redirect', 'TestEndpointRedirect');
>>> }
>>>
>>> function TestEndpointInit(){
>>>     global $wp_rewrite;
>>>     $wp_rewrite->add_endpoint("testendpoint", EP_ALL);
>>>      $wp_rewrite->flush_rules();
>>> }
>>>
>>> function TestEndpointRedirect(){
>>>     $my_var = get_query_var('testendpoint');
>>>
>>>     if (empty($my_var)){
>>>          return;
>>>      }
>>>     
>>>     die( '<h1>We hit the endpoint: testendpoint!</h1>');
>>>
>>> }
>>>
>>> TestEndpoint();
>>>
>>> ?>
>>> -----------------------------------------------------------------
>>>
>>> The test:
>>>   1. Install the plugin and activate it
>>>   2. Go to an existing page, append to the URL "/testendpoint/", and go to
>>> the new URL
>>>      - Expected results: " We hit the endpoint: testendpoint!"
>>>      - Actually results: The original page without the endpoint
>>>   3. Change the file /wp_include/rewrite.php as stated above
>>>   4. Repeat step 2
>>>       - Actually results:  " We hit the endpoint: testendpoint!"
> 
> Seamus.
> leahy at au.org | x220
> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 
> 
> 


-- 
Jennifer Hodgdon

Poplar ProductivityWare * www.poplarware.com
Web Databases/Scripts * Modeling/Analysis/Palm OS Software


More information about the wp-hackers mailing list