WP_Route icon indicating copy to clipboard operation
WP_Route copied to clipboard

This class doesn't work. A quick review of the many forks.

Open tomas-eklund opened this issue 5 years ago • 2 comments

As stated in other issues this routing class simply doesn't work. The routing logic isn't actually implemented. No check is made to see if the requested URL matches any of the registered routes. There are also a few bugs such as using $this in a non object context and annoyances such as non-standard capitalization of PHP keywords such as Self, NULL and FALSE.

So don't use this class.

There are a number of forks however, and I thought I'd have a quick look at them to see if any one had taken the implementation of this class a step further. I hope my efforts will help someone save a few precious minutes. I haven't actually tested any of the forks yet, but most are an exact copy of the original and are therefore just as useless.

Samuel Tissot has made significant changes to the class. There is documentation and code comments. The code has been cleaned up and the methods handling the routing have been completely rewritten. There is also a test class. From a cursory glance this fork looks the most promising. It seems to be actively maintained.

Snellcode has made significant changes to the routing method. The rest of the class is left untouched:

Minor code changes. However, no changes to the routing logic:

No changes to the code whatsoever. For now, they are just as useless as the original class:

tomas-eklund avatar Mar 06 '19 13:03 tomas-eklund

Thanks for the info @tomas-eklund. If anyone sees this issue and is looking for an alternative, checkout https://github.com/Upstatement/routes.

It has not been updated in awhile, but last I used it it was working fine.

zlove avatar Mar 13 '19 20:03 zlove

I have now tried out SamuelTissots fork and it worked (at least for some very simple stuff I was doing). I had to tweak the class a little bit (hooking into the wp-loaded instead of the init hook) to get it to play nice with some plugins (such as WPML), but it worked.

However, I wasn't aware that Jared from Upstatement had made a similar class. I'll definitely check it out. I really like his Timber plugin and use it from time to time. Thanks for the tip @zlove!

tomas-eklund avatar Mar 13 '19 20:03 tomas-eklund