« first day (3391 days earlier)      last day (1561 days later) » 

3:33 PM
Ben Popper on January 28, 2020

Our guest this week is Alex Qin, co-founder and CEO of the Code Cooperative.

Alex graduated from NYU with a degree in computer science and worked as a developer and engineer at several startups in New York City, eventually assuming senior roles like engineering team lead and director of technology.

Along the way, however, she found herself face with discrimination and harassment. In 2016, she dramatically altered her appearance, an experience she discusses in a humorous and poignant talk – Shaving My Head Made me a Better Developer. …

 
 
2 hours later…
5:17 PM
Any tips on preventing a rewrite rule from removing a query var? I've got a rewrite rule for /the/page, but visiting /the/page?my_var=value ends up at just /the/page without the query string.
 
Could the query var be a reserved keyword?
 
I tried using the query_vars filter and the add_rewrite_tag function to register the query var, but it still gets stripped.
 
The var I'm testing with is avorg_query=... so I don't think so...
If I dump the query on parse_request, the query param shows up in the data.
However, that seems to cancel the redirect (?) and the page doesn't load, just the dumped data.
Without the dump, get_query_var returns nothing
 
Did you add it using the query_vars filter?
 
5:22 PM
Using add_filter('query_vars', ...) ? Yes
public function registerQueryVar($vars)
{
    $vars[] = 'avorg_query';
    return $vars;
}
And it shows up in the public_query_vars section of the dumped query object.
 
Are you adding any other rewrites?
 
Yes, a lot. =P
How might that interfere?
 
Difficult to say without seeing them. If you removed all the custom rewrites, re-saved your permalink structure, and tried again does the same issue occur?
 
matched_rule and matched_query in the dumped query look right.
Hmm, I'll try...
 
A custom rewrite or a reserved keyword are the two things that come to mind which might remove a query string.
We've already ruled out it's not a reserved keyword
 
5:26 PM
There is a custom rewrite applied to this page.
public 'matched_rule' => string '^([\w\-\.]+)\/search\/?$' (length=24)
public 'matched_query' => string 'page_id=38&language=english' (length=27)
Would that prevent a query string from getting through?
Do I need to match the query string in the regex for the rewrite rule and then append it to the result query?
 
You shouldn't need to
 
Ok
I'll try turning the other rewrites off.
Turned everything else off, resaved permalinks, and confirmed I get 404s for everything else. Didn't fix it.
I just looked in the Network panel and I am getting an initial 301. Is that normal for a rewrite rule?
Status Code: 301 Moved Permanently (from ServiceWorker)
Maybe this is a PWA issue =P
Except the second entry doesn't say from ServiceWorker =P
 
5:47 PM
I would assume it's the search rewrite rules and work from there. Personally, I think \/? is the issue.
 
It shouldn't be 301 redirecting, I'm not sure why it would.
 
 
3 hours later…
8:33 PM
I just confirmed that the redirect is happening via redirect_canonical by putting a var_dump on that filter.
 
8:47 PM
That was it. I was already filtering the redirect, and I wasn't including the query string in what I returned. I feel like I've overcomplicated my solution. =P
Thank you so much for your help, @Howdy_McGee!
 
Yeah that sounded like a rough one to track down.
 
This is all due to a pretty complex home-grown routing system... You wouldn't know of any good examples of other people abstracting routing in a WordPress plugin?
Basically I have a large part of the plugin dedicated to taking routes like { language }/audiobooks/stories, translating them, and generating the regex needed for add_rewrite_rule.
But I feel like I've made things much more complex then they perhaps need to be.
It also handles routes like { language }/audiobooks/stories/{ entity_id:[0-9]+ }[/{ slug }]
which handles validation and optional route segments.
 
9:17 PM
I do not know but it's definitely something I would be interested in too. I really like how Laravel does Routes. That being replicated to a WordPress Helper Class would be pretty neat.
 

« first day (3391 days earlier)      last day (1561 days later) »