Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ETH Simple Shortlinks
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
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 Simple Shortlinks
Commits
d04902da
Commit
d04902da
authored
9 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Check if plugin is supported before acting
parent
7b1bceae
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-simple-shortlinks.php
+29
-12
29 additions, 12 deletions
eth-simple-shortlinks.php
with
29 additions
and
12 deletions
eth-simple-shortlinks.php
+
29
−
12
View file @
d04902da
...
@@ -4,7 +4,7 @@ Plugin Name: ETH Simple Shortlinks
...
@@ -4,7 +4,7 @@ Plugin Name: ETH Simple Shortlinks
Plugin URI: https://ethitter.com/plugins/
Plugin URI: https://ethitter.com/plugins/
Description: Simple non-GET shortlinks using post IDs
Description: Simple non-GET shortlinks using post IDs
Author: Erick Hitter
Author: Erick Hitter
Version: 0.
4
Version: 0.
5
Author URI: https://ethitter.com/
Author URI: https://ethitter.com/
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
...
@@ -56,33 +56,46 @@ class ETH_Simple_Shortlinks {
...
@@ -56,33 +56,46 @@ class ETH_Simple_Shortlinks {
private
$slug
=
'p'
;
private
$slug
=
'p'
;
private
$qv
=
'eth-shortlink'
;
private
$qv
=
'eth-shortlink'
;
private
$plugin_supported
=
false
;
private
$supported_post_types
=
array
();
private
$supported_post_types
=
array
();
private
$supported_post_statuses
=
array
();
private
$supported_post_statuses
=
array
();
/**
/**
* Register
actions and filters
* Register
plugin's setup action
*/
*/
private
function
__construct
()
{
private
function
__construct
()
{
// Request
add_action
(
'init'
,
array
(
$this
,
'action_init'
)
);
add_action
(
'init'
,
array
(
$this
,
'add_rewrite_rule'
)
);
}
/**
* Verify plugin is supported and register its functionality
*/
public
function
action_init
()
{
global
$wp_rewrite
;
// Plugin won't work if site doesn't use pretty permalinks
if
(
empty
(
$wp_rewrite
->
permalink_structure
)
)
{
return
;
}
else
{
$this
->
plugin_supported
=
true
;
}
// Register rewrite rule
add_rewrite_rule
(
'^'
.
$this
->
slug
.
'/([\d]+)/?$'
,
'index.php?p=$matches[1]&'
.
$this
->
qv
.
'=1'
,
'top'
);
// Request handling
add_action
(
'wp_loaded'
,
array
(
$this
,
'filter_support'
)
);
add_action
(
'wp_loaded'
,
array
(
$this
,
'filter_support'
)
);
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
// Shortlink
overrides
add_filter
(
'get_shortlink'
,
array
(
$this
,
'filter_get_shortlink'
),
10
,
2
);
add_filter
(
'get_shortlink'
,
array
(
$this
,
'filter_get_shortlink'
),
10
,
2
);
add_action
(
'admin_head-edit.php'
,
array
(
$this
,
'add_admin_header_assets'
)
);
add_action
(
'admin_head-edit.php'
,
array
(
$this
,
'add_admin_header_assets'
)
);
add_filter
(
'post_row_actions'
,
array
(
$this
,
'filter_row_actions'
),
10
,
2
);
add_filter
(
'post_row_actions'
,
array
(
$this
,
'filter_row_actions'
),
10
,
2
);
add_filter
(
'page_row_actions'
,
array
(
$this
,
'filter_row_actions'
),
10
,
2
);
add_filter
(
'page_row_actions'
,
array
(
$this
,
'filter_row_actions'
),
10
,
2
);
}
}
/**
* Register rewrite rule
*/
public
function
add_rewrite_rule
()
{
add_rewrite_rule
(
'^'
.
$this
->
slug
.
'/([\d]+)/?$'
,
'index.php?p=$matches[1]&'
.
$this
->
qv
.
'=1'
,
'top'
);
}
/**
/**
* Allow filtering of supported statuses and types
* Allow filtering of supported statuses and types
*/
*/
...
@@ -199,6 +212,10 @@ class ETH_Simple_Shortlinks {
...
@@ -199,6 +212,10 @@ class ETH_Simple_Shortlinks {
* Utility method for building permlink
* Utility method for building permlink
*/
*/
public
function
get_shortlink
(
$post_id
)
{
public
function
get_shortlink
(
$post_id
)
{
if
(
!
$this
->
plugin_supported
)
{
return
wp_get_shortlink
(
$post_id
);
}
return
user_trailingslashit
(
home_url
(
sprintf
(
'%s/%d'
,
$this
->
slug
,
$post_id
)
)
);
return
user_trailingslashit
(
home_url
(
sprintf
(
'%s/%d'
,
$this
->
slug
,
$post_id
)
)
);
}
}
}
}
...
...
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