-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 48 Minify regex rewrite rule broken by external plugin / theme #49
Conversation
- Change add_rewrite_rule to a filter for the rewrite_rules_array to insure additional plugins will not cause the rules to break - Fixes #48
add_rewrite_rule( $regex, $redirect, 'top' ); | ||
$new_rules[$regex] = $redirect; | ||
|
||
return $rules + $new_rules; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c3mdigital I believe this needs to be array_merge()
, as using +
does some strange things where it will skip merging a item from the right array, if it has the same numeric index as an item in the left.
@westonruter Yes array_merge is the way to go. Fixed in 98094cc |
- Allows plugin to work with other plugins or themes who have filtered home_url
add_rewrite_rule( $regex, $redirect, 'top' ); | ||
$new_rules[$regex] = $redirect; | ||
|
||
return array_merge( $rules, $new_rules ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c3mdigital it seems I need to reverse the order here, so that $new_rules
will appear at the top. Otherwise, on one site I'm getting the page rewrite rule matching before the the minification rewrite rule can be reached.
If this is not done, then a page rewrite rule may match first
$regex = self::get_rewrite_regex(); | ||
global $wp_rewrite; | ||
unset( $wp_rewrite->extra_rules_top[ $regex ] ); | ||
remove_filter( 'rewrite_rules_array', array( __CLASS__, 'add_rewrite_rule' ), 99999 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c3mdigital good idea!
Fix rewrite rule broken by filtering home_url
This solves the issue by adding the minify rewrite rule to the end of the rewrite_rules_array insuring in theory that the rule can not be broken by an external rewrite filter.
@westonruter please reivew