Skip to content

Commit

Permalink
Merge pull request #49 from x-team/issue-48
Browse files Browse the repository at this point in the history
Fix rewrite rule broken by filtering home_url
  • Loading branch information
westonruter committed Dec 12, 2013
2 parents 67085f1 + 30f64c8 commit 77f3d99
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions dependency-minification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
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( $new_rules, $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 );
}

protected static $is_footer = array(
Expand All @@ -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();
}

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -813,7 +813,7 @@ static function minify( $cached ) {
try {
$is_css = ( 'styles' === $type );
if ( 'scripts' === $type ) {
require_once( dirname(__FILE__) . '/minify/JS/JSMin.php' );
require_once( dirname(__FILE__) . '/minify/JS/JSMinPlus.php' );
} elseif ( 'styles' === $type ) {
require_once( dirname(__FILE__) . '/minify/CSS/UriRewriter.php' );
require_once( dirname(__FILE__) . '/minify/CSS/Compressor.php' );
Expand Down Expand Up @@ -883,7 +883,7 @@ static function minify( $cached ) {
// is the comment-reply.js in WordPress.
if ( 'scripts' === $type ) {
$minified_contents = join( "\n;;\n", $contents_for_each_dep );
$minified_contents = JSMin::minify($minified_contents);
$minified_contents = JSMinPlus::minify($minified_contents);
if ( false === $minified_contents ) {
throw new Dependency_Minification_Exception( 'JavaScript parse error' );
}
Expand Down

0 comments on commit 77f3d99

Please sign in to comment.