-
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fa14cc2
Issue-48 Remove add_rewrite_rule and filter rewrite_rules_array instead
b0e8f29
Cleanup debug changes and replace Text Domain back to dependency-mini…
98094cc
Use array_merge instead of appending arrays with +
ad5eb95
Replace home_url() with get_option( 'home' )
387998f
Ensure front matter is ignored for minify URL pattern
westonruter 6828dad
Inject rewrite rule to beginning of array
westonruter 30f64c8
Use JSMinPlus since JSMin was timing-out
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,26 +84,26 @@ static function setup() { | |
static function hook_rewrites() { | ||
add_filter( 'query_vars', array( __CLASS__, 'filter_query_vars' ) ); | ||
add_action( 'pre_get_posts', array( __CLASS__, 'handle_request' ) ); | ||
self::add_rewrite_rule(); | ||
add_filter( 'rewrite_rules_array', array( __CLASS__, 'add_rewrite_rule' ), 99999 ); | ||
} | ||
|
||
static function get_rewrite_regex() { | ||
return sprintf( '^%s/%s', self::$options['endpoint'], self::FILENAME_PATTERN ); | ||
} | ||
|
||
static function add_rewrite_rule() { | ||
static function add_rewrite_rule( $rules ) { | ||
$regex = self::get_rewrite_regex(); | ||
$redirect = 'index.php?'; | ||
for ( $i = 0; $i < count( self::$query_vars ); $i += 1 ) { | ||
$redirect .= sprintf( '%s=$matches[%d]&', self::$query_vars[$i], $i + 1 ); | ||
} | ||
add_rewrite_rule( $regex, $redirect, 'top' ); | ||
$new_rules[$regex] = $redirect; | ||
|
||
return array_merge( $rules, $new_rules ); | ||
} | ||
|
||
static function remove_rewrite_rule() { | ||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. @c3mdigital good idea! |
||
} | ||
|
||
protected static $is_footer = array( | ||
|
@@ -116,7 +116,7 @@ static function remove_rewrite_rule() { | |
*/ | ||
static function activate() { | ||
self::setup(); | ||
self::add_rewrite_rule(); | ||
add_filter( 'rewrite_rules_array', array( __CLASS__, 'add_rewrite_rule' ), 99999 ); | ||
flush_rewrite_rules(); | ||
} | ||
|
||
|
@@ -398,7 +398,7 @@ static function admin_page() { | |
$_link_params = $link_params; | ||
$_link_params['depmin_task'] = 'purge'; | ||
?> | ||
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'dependency-minification' ) ?>" href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>"> | ||
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'depmin' ) ?>" href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>"> | ||
<?php esc_html_e( 'Try again', 'dependency-minification' ) ?> | ||
</a> | ||
</span> | ||
|
@@ -505,7 +505,7 @@ static function get_cache_option_name( $src_hash ) { | |
static function get_dependency_minified_url( array $deps, $type ) { | ||
$src_hash = self::hash_array( wp_list_pluck( $deps, 'src' ) ); | ||
$ver_hash = self::hash_array( wp_list_pluck( $deps, 'ver' ) ); | ||
$src = trailingslashit( home_url( self::$options['endpoint'] ) ); | ||
$src = trailingslashit( get_option( 'home' ) . DIRECTORY_SEPARATOR . self::$options['endpoint'] ); | ||
$src .= join( '.', array( | ||
join( ',', wp_list_pluck( $deps, 'handle' ) ), | ||
$src_hash, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.