Brain-WP / Cortex

Routing system for WordPress
MIT License
347 stars 20 forks source link

Accessing $matches within before or after callbacks #12

Closed chrisvanpatten closed 8 years ago

chrisvanpatten commented 8 years ago

Hi there -

Really loving this library. Definitely the smoothest routing utility for WordPress that I've found!

I'm trying to figure out how to access the captured $matches within the before/after callbacks. Right now, as far as I can tell, you can only access it in the $queryBuilder callable.

It's very possible I'm missing something obvious… if not, consider this a feature request :)

Thanks!

gmazzap commented 8 years ago

Hi @chrisvanpatten

Thanks for your interest in Cortex.

I don't know if you noticed that version 0.* (that at the moment lives on "master" branch) is pretty different that version 1.*. (that at the moment lives in the "refactoring-fastroute" branch).

To help you I need to know which version are you using.

Thanks

chrisvanpatten commented 8 years ago

Using 1.*, and loving it!

It doesn't seem to merge in the $matches array… here's what I've got:

dev-directories_ecommercefuel_com_myroute_word_

I haven't touched the merge_query_string setting at all - left it at the default.

gmazzap commented 8 years ago

Oh, yes, you right. When using a query route, the route vars is a callback that get called passing matches... and yes, in that case they can't be get inside "before" / "after" callbacks.

I consider this a feature request I will do as soon as I can.

chrisvanpatten commented 8 years ago

Awesome, thanks! I found a temporary workaround for my use-case, but having it baked in like this would be super nice.

Appreciate the quick response! Looking forward to using this more.

gmazzap commented 8 years ago

So I have pushed a new branch "issue-12" that should fix this.

Note that I need to fix unit tests, now they are failing for this branch because of the changes, however it should work.

With changes introduced in this branch "before" and "after" callbacks receives 4 arguments:

Where:

chrisvanpatten commented 8 years ago

Thanks! This is working brilliantly.

gmazzap commented 8 years ago

@chrisvanpatten Thanks! I hope I will find the time today to write some tests, merge and release new version.

Thanks to you for your interest and your issue.

gmazzap commented 8 years ago

@chrisvanpatten this have been merged and included in v1.0.0-alpha.7.

Thanks for your contribute.