Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
External Permalinks Redux
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
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
External Permalinks Redux
Commits
67f5acbf
Commit
67f5acbf
authored
5 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Automated PHPCS fixes
parent
daedadf2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Fix all PHPCS issues
Pipeline
#837
passed with warnings with stages
Stage:
Stage:
in 3 minutes and 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
external-permalinks-redux.php
+33
-23
33 additions, 23 deletions
external-permalinks-redux.php
with
33 additions
and
23 deletions
external-permalinks-redux.php
+
33
−
23
View file @
67f5acbf
...
@@ -29,7 +29,7 @@ class external_permalinks_redux {
...
@@ -29,7 +29,7 @@ class external_permalinks_redux {
protected
static
$instance
;
protected
static
$instance
;
var
$meta_key_target
=
'_links_to'
;
var
$meta_key_target
=
'_links_to'
;
var
$meta_key_type
=
'_links_to_type'
;
var
$meta_key_type
=
'_links_to_type'
;
var
$status_codes
;
var
$status_codes
;
/**
/**
...
@@ -38,8 +38,9 @@ class external_permalinks_redux {
...
@@ -38,8 +38,9 @@ class external_permalinks_redux {
* @return object
* @return object
*/
*/
static
function
get_instance
()
{
static
function
get_instance
()
{
if
(
!
isset
(
self
::
$instance
)
)
if
(
!
isset
(
self
::
$instance
)
)
{
self
::
$instance
=
new
self
;
self
::
$instance
=
new
self
();
}
return
self
::
$instance
;
return
self
::
$instance
;
}
}
...
@@ -71,9 +72,9 @@ class external_permalinks_redux {
...
@@ -71,9 +72,9 @@ class external_permalinks_redux {
*/
*/
function
action_init
()
{
function
action_init
()
{
$this
->
meta_key_target
=
apply_filters
(
'epr_meta_key_target'
,
$this
->
meta_key_target
);
$this
->
meta_key_target
=
apply_filters
(
'epr_meta_key_target'
,
$this
->
meta_key_target
);
$this
->
meta_key_type
=
apply_filters
(
'epr_meta_key_type'
,
$this
->
meta_key_type
);
$this
->
meta_key_type
=
apply_filters
(
'epr_meta_key_type'
,
$this
->
meta_key_type
);
$status_codes
=
array
(
$status_codes
=
array
(
302
=>
__
(
'Temporary (302)'
,
'external-permalinks-redux'
),
302
=>
__
(
'Temporary (302)'
,
'external-permalinks-redux'
),
301
=>
__
(
'Permanent (301)'
,
'external-permalinks-redux'
),
301
=>
__
(
'Permanent (301)'
,
'external-permalinks-redux'
),
);
);
...
@@ -92,14 +93,16 @@ class external_permalinks_redux {
...
@@ -92,14 +93,16 @@ class external_permalinks_redux {
function
action_admin_init
()
{
function
action_admin_init
()
{
$post_types
=
apply_filters
(
'epr_post_types'
,
array
(
'post'
,
'page'
)
);
$post_types
=
apply_filters
(
'epr_post_types'
,
array
(
'post'
,
'page'
)
);
if
(
!
is_array
(
$post_types
)
)
if
(
!
is_array
(
$post_types
)
)
{
return
;
return
;
}
foreach
(
$post_types
as
$post_type
)
{
foreach
(
$post_types
as
$post_type
)
{
$title
=
apply_filters
(
'epr_metabox_title'
,
''
,
$post_type
);
$title
=
apply_filters
(
'epr_metabox_title'
,
''
,
$post_type
);
if
(
!
$title
)
if
(
!
$title
)
{
$title
=
__
(
'External Permalinks Redux'
,
'external-permalinks-redux'
);
$title
=
__
(
'External Permalinks Redux'
,
'external-permalinks-redux'
);
}
add_meta_box
(
'external-permalinks-redux'
,
$title
,
array
(
$this
,
'meta_box'
),
$post_type
,
'normal'
);
add_meta_box
(
'external-permalinks-redux'
,
$title
,
array
(
$this
,
'meta_box'
),
$post_type
,
'normal'
);
...
@@ -122,7 +125,7 @@ class external_permalinks_redux {
...
@@ -122,7 +125,7 @@ class external_permalinks_redux {
*/
*/
function
meta_box
(
$post
)
{
function
meta_box
(
$post
)
{
$type
=
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_type
,
true
);
$type
=
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_type
,
true
);
?>
?>
<p
class=
"epr-destination"
>
<p
class=
"epr-destination"
>
<label
for=
"epr-url"
>
<?php
_e
(
'Destination Address:'
,
'external-permalinks-redux'
);
?>
</label><br
/>
<label
for=
"epr-url"
>
<?php
_e
(
'Destination Address:'
,
'external-permalinks-redux'
);
?>
</label><br
/>
<input
name=
"
<?php
echo
esc_attr
(
$this
->
meta_key_target
);
?>
_url"
class=
"large-text code"
id=
"epr-url"
type=
"text"
value=
"
<?php
echo
esc_url
(
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_target
,
true
)
);
?>
"
/>
<input
name=
"
<?php
echo
esc_attr
(
$this
->
meta_key_target
);
?>
_url"
class=
"large-text code"
id=
"epr-url"
type=
"text"
value=
"
<?php
echo
esc_url
(
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_target
,
true
)
);
?>
"
/>
...
@@ -136,15 +139,17 @@ class external_permalinks_redux {
...
@@ -136,15 +139,17 @@ class external_permalinks_redux {
<label
for=
"epr-type"
>
<?php
_e
(
'Redirect Type:'
,
'external-permalinks-redux'
);
?>
</label>
<label
for=
"epr-type"
>
<?php
_e
(
'Redirect Type:'
,
'external-permalinks-redux'
);
?>
</label>
<select
name=
"
<?php
echo
esc_attr
(
$this
->
meta_key_target
);
?>
_type"
id=
"epr-type"
>
<select
name=
"
<?php
echo
esc_attr
(
$this
->
meta_key_target
);
?>
_type"
id=
"epr-type"
>
<option
value=
""
>
<?php
_e
(
'-- Select --'
,
'external-permalinks-redux'
);
?>
</option>
<option
value=
""
>
<?php
_e
(
'-- Select --'
,
'external-permalinks-redux'
);
?>
</option>
<?php
foreach
(
$this
->
status_codes
as
$status_code
=>
$explanation
)
{
<?php
foreach
(
$this
->
status_codes
as
$status_code
=>
$explanation
)
{
echo
'<option value="'
.
esc_attr
(
$status_code
)
.
'"'
;
echo
'<option value="'
.
esc_attr
(
$status_code
)
.
'"'
;
selected
(
$status_code
,
intval
(
$type
)
);
selected
(
$status_code
,
intval
(
$type
)
);
echo
'>'
.
esc_attr
(
$explanation
)
.
'</option>'
;
echo
'>'
.
esc_attr
(
$explanation
)
.
'</option>'
;
}
?>
}
?>
</select>
</select>
</p>
</p>
<?php
<?php
wp_nonce_field
(
'external-permalinks-redux'
,
$this
->
meta_key_target
.
'_nonce'
,
false
);
wp_nonce_field
(
'external-permalinks-redux'
,
$this
->
meta_key_target
.
'_nonce'
,
false
);
}
}
...
@@ -161,21 +166,23 @@ class external_permalinks_redux {
...
@@ -161,21 +166,23 @@ class external_permalinks_redux {
*/
*/
function
action_save_post
(
$post_id
)
{
function
action_save_post
(
$post_id
)
{
if
(
isset
(
$_POST
[
$this
->
meta_key_target
.
'_nonce'
]
)
&&
wp_verify_nonce
(
$_POST
[
$this
->
meta_key_target
.
'_nonce'
],
'external-permalinks-redux'
)
)
{
if
(
isset
(
$_POST
[
$this
->
meta_key_target
.
'_nonce'
]
)
&&
wp_verify_nonce
(
$_POST
[
$this
->
meta_key_target
.
'_nonce'
],
'external-permalinks-redux'
)
)
{
//Target
//
Target
$url
=
esc_url_raw
(
$_POST
[
$this
->
meta_key_target
.
'_url'
]
);
$url
=
esc_url_raw
(
$_POST
[
$this
->
meta_key_target
.
'_url'
]
);
if
(
!
empty
(
$url
)
)
if
(
!
empty
(
$url
)
)
{
update_post_meta
(
$post_id
,
$this
->
meta_key_target
,
$url
);
update_post_meta
(
$post_id
,
$this
->
meta_key_target
,
$url
);
else
}
else
{
delete_post_meta
(
$post_id
,
$this
->
meta_key_target
,
$url
);
delete_post_meta
(
$post_id
,
$this
->
meta_key_target
,
$url
);
}
//Redirect type
//
Redirect type
$type
=
intval
(
$_POST
[
$this
->
meta_key_target
.
'_type'
]
);
$type
=
intval
(
$_POST
[
$this
->
meta_key_target
.
'_type'
]
);
if
(
!
empty
(
$url
)
&&
array_key_exists
(
$type
,
$this
->
status_codes
)
)
if
(
!
empty
(
$url
)
&&
array_key_exists
(
$type
,
$this
->
status_codes
)
)
{
update_post_meta
(
$post_id
,
$this
->
meta_key_type
,
$type
);
update_post_meta
(
$post_id
,
$this
->
meta_key_type
,
$type
);
else
}
else
{
delete_post_meta
(
$post_id
,
$this
->
meta_key_type
);
delete_post_meta
(
$post_id
,
$this
->
meta_key_type
);
}
}
}
}
}
...
@@ -190,8 +197,9 @@ class external_permalinks_redux {
...
@@ -190,8 +197,9 @@ class external_permalinks_redux {
* @return string
* @return string
*/
*/
function
filter_post_permalink
(
$permalink
,
$post
)
{
function
filter_post_permalink
(
$permalink
,
$post
)
{
if
(
$external_link
=
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_target
,
true
)
)
if
(
$external_link
=
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_target
,
true
)
)
{
$permalink
=
$external_link
;
$permalink
=
$external_link
;
}
return
$permalink
;
return
$permalink
;
}
}
...
@@ -200,14 +208,15 @@ class external_permalinks_redux {
...
@@ -200,14 +208,15 @@ class external_permalinks_redux {
* Filter page permalinks
* Filter page permalinks
*
*
* @param string $link
* @param string $link
* @param int $id
* @param int
$id
* @uses get_post_meta
* @uses get_post_meta
* @filter page_link
* @filter page_link
* @return string
* @return string
*/
*/
function
filter_page_link
(
$link
,
$id
)
{
function
filter_page_link
(
$link
,
$id
)
{
if
(
$external_link
=
get_post_meta
(
$id
,
$this
->
meta_key_target
,
true
)
)
if
(
$external_link
=
get_post_meta
(
$id
,
$this
->
meta_key_target
,
true
)
)
{
$link
=
$external_link
;
$link
=
$external_link
;
}
return
$link
;
return
$link
;
}
}
...
@@ -230,8 +239,9 @@ class external_permalinks_redux {
...
@@ -230,8 +239,9 @@ class external_permalinks_redux {
$type
=
intval
(
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_type
,
true
)
);
$type
=
intval
(
get_post_meta
(
$post
->
ID
,
$this
->
meta_key_type
,
true
)
);
$type
=
apply_filters
(
'epr_status_code'
,
$type
,
$link
,
$post
);
$type
=
apply_filters
(
'epr_status_code'
,
$type
,
$link
,
$post
);
if
(
!
$type
)
if
(
!
$type
)
{
$type
=
302
;
$type
=
302
;
}
wp_redirect
(
$link
,
$type
);
wp_redirect
(
$link
,
$type
);
exit
;
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