Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #66 from godbone/master
Moved add_rewrite_tag calls to init hook
  • Loading branch information
Nomafin committed Mar 19, 2018
2 parents a2c21a1 + 9c10fd9 commit 2a0ec5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
- Moved add_rewrite_tag calls to init

## [1.13.0] - 2018-03-15

### Added
Expand Down
14 changes: 11 additions & 3 deletions dustpress.php
Expand Up @@ -108,12 +108,20 @@ protected function __construct() {
// Initialize settings
add_action( 'init', [ $this, 'init_settings' ] );

// Register custom route rewrite tag
add_action( 'init', [ $this, 'rewrite_tags' ], 20 );

return;
}

/**
* Register custom route rewrite tag
*/
public function rewrite_tags() {
// Register custom route rewrite tag
add_rewrite_tag( '%dustpress_custom_route%', '([^\/]+)' );
add_rewrite_tag( '%dustpress_custom_route_route%', '(.+)' );
add_rewrite_tag( '%dustpress_custom_route_parameters%', '(.+)' );

return;
}

/**
Expand Down Expand Up @@ -1467,7 +1475,7 @@ private function get_template_paths( $append ) {
public function register_custom_route( $route, $template ) {
add_action( 'init', function() use ( $route, $template ) {
add_rewrite_rule( '(' . $route . ')(\/(.+))?\/?$', 'index.php?dustpress_custom_route=' . $template . '&dustpress_custom_route_route=$matches[1]&dustpress_custom_route_parameters=$matches[3]', 'top' );
});
}, 30);
}
}

Expand Down

0 comments on commit 2a0ec5c

Please sign in to comment.