Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ETH Redirect to Latest Post
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
ETH Redirect to Latest Post
Commits
89289561
Verified
Commit
89289561
authored
9 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
First pass at basic plugin to redirect `latest` to the latest post.
parent
12422690
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eth-redirect-to-latest.php
+32
-1
32 additions, 1 deletion
eth-redirect-to-latest.php
with
32 additions
and
1 deletion
eth-redirect-to-latest.php
+
32
−
1
View file @
89289561
...
...
@@ -61,7 +61,38 @@ class ETH_Redirect_To_Latest_Post {
/**
* Register plugin's setup action
*/
private
function
__construct
()
{}
private
function
__construct
()
{
add_action
(
'parse_request'
,
array
(
$this
,
'action_parse_request'
)
);
}
/**
* Redirect to the latest post any requests made to plugin's slug
*/
public
function
action_parse_request
(
$r
)
{
if
(
isset
(
$r
->
query_vars
[
'pagename'
]
)
&&
$this
->
slug
===
$r
->
query_vars
[
'pagename'
]
)
{
$latest
=
get_posts
(
array
(
'posts_per_page'
=>
1
,
'post_type'
=>
'post'
,
'orderby'
=>
'date'
,
'order'
=>
'desc'
,
'suppress_filters'
=>
false
,
'no_found_rows'
=>
true
,
)
);
if
(
is_array
(
$latest
)
&&
!
empty
(
$latest
)
)
{
$latest
=
array_shift
(
$latest
);
$dest
=
get_permalink
(
$latest
->
ID
);
if
(
!
$dest
)
{
$dest
=
user_trailingslashit
(
home_url
()
);
}
wp_redirect
(
$dest
,
302
);
// Not validating in case other plugins redirect elsewhere
exit
;
}
}
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment