Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
eth-escape-headspace
Commits
67363557
Commit
67363557
authored
Jan 30, 2016
by
Erick Hitter
Browse files
Support for simple string-based data, as well as the robots meta built from several postmeta keys
parent
cbcea871
Changes
1
Show whitespace changes
Inline
Side-by-side
eth-escape-headspace.php
View file @
67363557
...
...
@@ -42,10 +42,17 @@ class ETH_Escape_HeadSpace2 {
/**
* Class properties
*/
private
$hs_keys
=
array
(
private
$hs_
string_
keys
=
array
(
'_headspace_description'
,
'_headspace_metakey'
,
);
private
$hs_robots_keys
=
array
(
'_headspace_noindex'
,
'_headspace_nofollow'
,
'_headspace_noarchive'
,
'_headspace_noodp'
,
'_headspace_noydir'
,
);
/**
...
...
@@ -69,7 +76,7 @@ class ETH_Escape_HeadSpace2 {
// Check for HS data
$hs_data
=
array
();
foreach
(
$this
->
hs_keys
as
$hs_key
)
{
foreach
(
array_merge
(
$this
->
hs_string_keys
,
$this
->
hs_robots_keys
)
as
$hs_key
)
{
$value
=
get_post_meta
(
get_the_ID
(),
$hs_key
,
true
);
if
(
!
empty
(
$value
)
)
{
...
...
@@ -83,13 +90,46 @@ class ETH_Escape_HeadSpace2 {
}
// Build output
echo
"
\n
<!-- Escape HeadSpace2 by Erick Hitter; ethitter.com -->
\n
"
;
// Handle basic, string-containing keys
foreach
(
$hs_data
as
$hs_key
=>
$hs_value
)
{
switch
(
$hs_key
)
{
case
'_headspace_description'
:
echo
'<meta name="description" content="'
.
esc_attr
(
$hs_value
)
.
'" />'
.
"
\n
"
;
break
;
case
'_headspace_metakey'
:
echo
'<meta name="keywords" content="'
.
esc_attr
(
$hs_value
)
.
'" />'
.
"
\n
"
;
break
;
default
:
continue
;
break
;
}
}
// Handle robots key, which is build from several meta keys
$robots
=
array
();
foreach
(
$this
->
hs_robots_keys
as
$hs_robot_key
)
{
if
(
isset
(
$hs_data
[
$hs_robot_key
]
)
)
{
$robots
[]
=
str_replace
(
'_headspace_'
,
''
,
$hs_robot_key
);
}
}
if
(
!
empty
(
$robots
)
)
{
if
(
1
===
count
(
$robots
)
&&
in_array
(
'noindex'
,
$robots
)
)
{
$robots
[]
=
'follow'
;
}
$robots
=
implode
(
','
,
$robots
);
echo
'<meta name="robots" content="'
.
esc_attr
(
$robots
)
.
'" />'
.
"
\n
"
;
}
// Mark end of output
echo
"<!-- Escape HeadSpace2 -->
\n
"
;
}
}
...
...
Write
Preview
Markdown
is supported
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