Skip to content
Snippets Groups Projects
Commit 68628e08 authored by Erick Hitter's avatar Erick Hitter
Browse files

Override shortlink to use the new format

parent b0856e8d
Branches
Tags
No related merge requests found
...@@ -53,22 +53,27 @@ class ETH_Simple_Shortlinks { ...@@ -53,22 +53,27 @@ class ETH_Simple_Shortlinks {
/** /**
* Class properties * Class properties
*/ */
private $slug = 'p';
private $qv = 'eth-shortlink'; private $qv = 'eth-shortlink';
/** /**
* *
*/ */
private function __construct() { private function __construct() {
// Request
add_action( 'init', array( $this, 'add_rewrite_rule' ) ); add_action( 'init', array( $this, 'add_rewrite_rule' ) );
add_filter( 'query_vars', array( $this, 'filter_query_vars' ) ); add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
add_action( 'parse_request', array( $this, 'action_parse_request' ) ); add_action( 'parse_request', array( $this, 'action_parse_request' ) );
// Shortlink
add_filter( 'get_shortlink', array( $this, 'filter_get_shortlink' ), 10, 2 );
} }
/** /**
* Register rewrite rule * Register rewrite rule
*/ */
public function add_rewrite_rule() { public function add_rewrite_rule() {
add_rewrite_rule( '^p/([\d]+)/?$', 'index.php?p=$matches[1]&' . $this->qv . '=1', 'top' ); add_rewrite_rule( '^' . $this->slug . '/([\d]+)/?$', 'index.php?p=$matches[1]&' . $this->qv . '=1', 'top' );
} }
/** /**
...@@ -101,6 +106,25 @@ class ETH_Simple_Shortlinks { ...@@ -101,6 +106,25 @@ class ETH_Simple_Shortlinks {
exit; exit;
} }
} }
/**
* Override shortlinks with this plugin's format
*/
public function filter_get_shortlink( $shortlink, $id ) {
if ( empty( $id ) ) {
$_p = get_post();
if ( ! empty( $_p->ID ) ) {
$id = $_p->ID;
}
}
if ( empty( $id ) ) {
return $shortlink;
}
return user_trailingslashit( home_url( sprintf( '%s/%d', $this->slug, $id ) ) );
}
} }
ETH_Simple_Shortlinks::get_instance(); ETH_Simple_Shortlinks::get_instance();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment