diff --git a/eth-redirect-to-latest.php b/eth-redirect-to-latest.php index f7796e8112932dbd4db6f0db65ab60c3240c185e..46396f6285bde84b7a351fa8bb2278859d235c40 100644 --- a/eth-redirect-to-latest.php +++ b/eth-redirect-to-latest.php @@ -4,7 +4,7 @@ Plugin Name: ETH Redirect to Latest Post Plugin URI: https://ethitter.com/plugins/ Description: Redirect a chosen slug to the whatever is currently the latest post Author: Erick Hitter -Version: 0.2.1 +Version: 0.2.2 Author URI: https://ethitter.com/ Text Domain: eth_redirect_to_latest_post Domain Path: /languages/ @@ -90,7 +90,18 @@ class ETH_Redirect_To_Latest_Post { * Redirect to the latest post any requests made to plugin's slug */ public function action_parse_request( $r ) { + $should_intercept = false; + + // Check if request is for our slug + // The first condition catches permastructs that are more than just post slug, whereas the second catches for slug-only permalinks if ( isset( $r->query_vars['pagename'] ) && $this->slug === $r->query_vars['pagename'] ) { + $should_intercept = true; + } elseif ( isset( $r->query_vars['name'] ) && $this->slug === $r->query_vars['name'] ) { + $should_intercept = true; + } + + // Handle redirection + if ( $should_intercept ) { $latest = get_posts( array( 'posts_per_page' => 1, 'post_type' => 'post', diff --git a/readme.txt b/readme.txt index 729e3288b10f3cdde1cca27136f0362872c5a003..ca6e7af425d2b6f21a8709529aa1fc9d32938ea3 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: ethitter Donate link: https://ethitter.com/donate/ Tags: latest, latest post, redirect, redirect latest, redirect post Requires at least: 4.5 -Tested up to: 4.6 -Stable tag: 0.2.1 +Tested up to: 4.7 +Stable tag: 0.2.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -22,6 +22,9 @@ Once activated, a given slug will redirect to whatever is the most recently-publ == Changelog == += 0.2.2 = +* Handle sites using slug-only permalinks + = 0.2.1 = * Correct Composer path error