Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
ETH Simple Shortlinks
Commits
68628e08
Commit
68628e08
authored
Mar 20, 2016
by
Erick Hitter
Browse files
Override shortlink to use the new format
parent
b0856e8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
eth-simple-shortlinks.php
View file @
68628e08
...
...
@@ -53,22 +53,27 @@ class ETH_Simple_Shortlinks {
/**
* Class properties
*/
private
$slug
=
'p'
;
private
$qv
=
'eth-shortlink'
;
/**
*
*/
private
function
__construct
()
{
// Request
add_action
(
'init'
,
array
(
$this
,
'add_rewrite_rule'
)
);
add_filter
(
'query_vars'
,
array
(
$this
,
'filter_query_vars'
)
);
add_action
(
'parse_request'
,
array
(
$this
,
'action_parse_request'
)
);
// Shortlink
add_filter
(
'get_shortlink'
,
array
(
$this
,
'filter_get_shortlink'
),
10
,
2
);
}
/**
* Register 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 {
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
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment