Version Description
- Add a Hack
=
Download this release
Release Info
Developer | kcseopro |
Plugin | WP SEO Structured Data Schema |
Version | 2.5.4 |
Comparing to | |
See all releases |
Code changes from version 2.5.3 to 2.5.4
- README.txt +4 -1
- lib/classes/KcSeoOutput.php +203 -200
- wp-seo-structured-data-schema.php +1 -1
README.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link:
|
|
4 |
Tags: seo, schema, structured data, rich snippets, microdata, json-ld, search engine optimization, local seo, google, sitelinks, schema.org, microformat, serp
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 5.0
|
7 |
-
Stable tag: 2.5.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -120,6 +120,9 @@ You'll find the [FAQ on Kcseopro.com](https://wpsemplugins.com/).
|
|
120 |
|
121 |
== Changelog ==
|
122 |
|
|
|
|
|
|
|
123 |
== 2.5.3 =
|
124 |
* Bug fixed
|
125 |
|
4 |
Tags: seo, schema, structured data, rich snippets, microdata, json-ld, search engine optimization, local seo, google, sitelinks, schema.org, microformat, serp
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 5.0
|
7 |
+
Stable tag: 2.5.4
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
120 |
|
121 |
== Changelog ==
|
122 |
|
123 |
+
== 2.5.4 =
|
124 |
+
* Add a Hack
|
125 |
+
|
126 |
== 2.5.3 =
|
127 |
* Bug fixed
|
128 |
|
lib/classes/KcSeoOutput.php
CHANGED
@@ -1,192 +1,194 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if (
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
190 |
if ($site_schema !== 'off') {
|
191 |
if ($webMeta["@type"]) {
|
192 |
if ($site_schema == 'home_page') {
|
@@ -199,17 +201,18 @@ if ( ! class_exists( 'KcSeoOutput' ) ):
|
|
199 |
}
|
200 |
}
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
215 |
endif;
|
1 |
<?php
|
2 |
|
3 |
+
if (!class_exists('KcSeoOutput')):
|
4 |
+
|
5 |
+
class KcSeoOutput
|
6 |
+
{
|
7 |
+
function __construct() {
|
8 |
+
add_action('wp_footer', array($this, 'footer'), 1);
|
9 |
+
add_action('kcseo_footer', array($this, 'debug_mark'), 2);
|
10 |
+
add_action('kcseo_footer', array($this, 'load_schema'), 3);
|
11 |
+
}
|
12 |
+
|
13 |
+
private function is_premium() {
|
14 |
+
return false;
|
15 |
+
}
|
16 |
+
|
17 |
+
private function head_product_name() {
|
18 |
+
if ($this->is_premium()) {
|
19 |
+
return 'WP SEO Structured Data pro plugin';
|
20 |
+
} else {
|
21 |
+
return 'WP SEO Structured Data Plugin';
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
public function debug_mark($echo = true) {
|
26 |
+
$marker = sprintf(
|
27 |
+
'<!-- This site is optimized with Phil Singleton\'s ' . $this->head_product_name() . ' v%1$s - https://kcseopro.com/wordpress-seo-structured-data-schema-plugin/ -->',
|
28 |
+
KCSEO_WP_SCHEMA_VERSION
|
29 |
+
);
|
30 |
+
|
31 |
+
if ($echo === false) {
|
32 |
+
return $marker;
|
33 |
+
} else {
|
34 |
+
echo "\n${marker}\n";
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
function footer() {
|
39 |
+
|
40 |
+
global $wp_query;
|
41 |
+
|
42 |
+
$old_wp_query = null;
|
43 |
+
|
44 |
+
if (!$wp_query->is_main_query()) {
|
45 |
+
$old_wp_query = $wp_query;
|
46 |
+
wp_reset_query();
|
47 |
+
}
|
48 |
+
wp_reset_postdata(); // TODO This is for wrong theme loop
|
49 |
+
do_action('kcseo_footer');
|
50 |
+
|
51 |
+
echo "\n<!-- / ", $this->head_product_name(), ". -->\n\n";
|
52 |
+
|
53 |
+
if (!empty($old_wp_query)) {
|
54 |
+
$GLOBALS['wp_query'] = $old_wp_query;
|
55 |
+
unset($old_wp_query);
|
56 |
+
}
|
57 |
+
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
|
61 |
+
function load_schema() {
|
62 |
+
global $KcSeoWPSchema;
|
63 |
+
$schemaModel = new KcSeoSchemaModel;
|
64 |
+
$html = null;
|
65 |
+
$settings = get_option($KcSeoWPSchema->options['settings']);
|
66 |
+
if (is_home() || is_front_page()) {
|
67 |
+
$metaData = array();
|
68 |
+
|
69 |
+
$metaData["@context"] = "http://schema.org/";
|
70 |
+
$metaData["@type"] = "WebSite";
|
71 |
+
|
72 |
+
if (!empty($settings['homeonly']) && $settings['homeonly']) {
|
73 |
+
$author_url = (!empty($settings['siteurl']) ? $settings['siteurl'] : get_home_url());
|
74 |
+
$to_remove = array('http://', 'https://', 'www.');
|
75 |
+
foreach ($to_remove as $item) {
|
76 |
+
$author_url = str_replace($item, '', $author_url); // to: www.example.com
|
77 |
+
}
|
78 |
+
$metaData["url"] = $KcSeoWPSchema->sanitizeOutPut($author_url, 'url');
|
79 |
+
$metaData["name"] = !empty($settings['sitename']) ? $KcSeoWPSchema->sanitizeOutPut($settings['sitename']) : null;
|
80 |
+
$metaData["alternateName"] = !empty($settings['siteaname']) ? $KcSeoWPSchema->sanitizeOutPut($settings['siteaname']) : null;
|
81 |
+
$html .= $schemaModel->get_jsonEncode($metaData);
|
82 |
+
} else {
|
83 |
+
$metaData["url"] = get_home_url();
|
84 |
+
$metaData["potentialAction"] = array(
|
85 |
+
"@type" => "SearchAction",
|
86 |
+
"target" => get_home_url() . "/?s={query}",
|
87 |
+
"query-input" => "required name=query"
|
88 |
+
);
|
89 |
+
$html .= $schemaModel->get_jsonEncode($metaData);
|
90 |
+
}
|
91 |
+
}
|
92 |
+
$webMeta = array();
|
93 |
+
$webMeta["@context"] = "http://schema.org";
|
94 |
+
$siteType = !empty($settings['site_type']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_type']) : null;
|
95 |
+
$webMeta["@type"] = $siteType;
|
96 |
+
if ($siteType != "Organization") {
|
97 |
+
if (!empty($settings['site_image']) && $imgID = absint($settings['site_image'])) {
|
98 |
+
$image_url = wp_get_attachment_url($imgID, 'full');
|
99 |
+
$webMeta["image"] = $KcSeoWPSchema->sanitizeOutPut($image_url, 'url');
|
100 |
+
} else {
|
101 |
+
$webMeta["image"] = null;
|
102 |
+
}
|
103 |
+
$webMeta["priceRange"] = !empty($settings['site_price_range']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_price_range']) : null;
|
104 |
+
$webMeta["telephone"] = !empty($settings['site_telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_telephone']) : null;
|
105 |
+
}
|
106 |
+
|
107 |
+
if (!empty($settings['additionalType'])) {
|
108 |
+
$aType = explode("\r\n", $settings['additionalType']);
|
109 |
+
if (!empty($aType) && is_array($aType)) {
|
110 |
+
if (count($aType) == 1) {
|
111 |
+
$webMeta["additionalType"] = $aType[0];
|
112 |
+
} else if (count($aType) > 1) {
|
113 |
+
$webMeta["additionalType"] = $aType;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
if ($siteType == 'Person') {
|
119 |
+
$webMeta["name"] = !empty($settings['person']['name']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['name']) : null;
|
120 |
+
$webMeta["worksFor"] = !empty($settings['person']['worksFor']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['worksFor']) : null;
|
121 |
+
$webMeta["jobTitle"] = !empty($settings['person']['jobTitle']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['jobTitle']) : null;
|
122 |
+
$webMeta["image"] = !empty($settings['person']['image']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['image'], 'url') : null;
|
123 |
+
$webMeta["description"] = !empty($settings['person']['description']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['description'], 'textarea') : null;
|
124 |
+
$webMeta["birthDate"] = !empty($settings['person']['birthDate']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['birthDate']) : null;
|
125 |
+
} else {
|
126 |
+
$webMeta["name"] = !empty($settings['type_name']) ? $KcSeoWPSchema->sanitizeOutPut($settings['type_name']) : null;
|
127 |
+
if (!empty($settings['organization_logo']) && $imgID = absint($settings['organization_logo'])) {
|
128 |
+
$image_url = wp_get_attachment_url($imgID, 'full');
|
129 |
+
$webMeta["logo"] = $KcSeoWPSchema->sanitizeOutPut($image_url, 'url');
|
130 |
+
} else {
|
131 |
+
$webMeta["logo"] = null;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
if ($siteType != "Organization" && $siteType != "Person") {
|
135 |
+
$webMeta["description"] = !empty($settings['business_info']['description']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['description'], 'textarea') : null;
|
136 |
+
if (!empty($settings['business_info']['openingHours'])) {
|
137 |
+
$aOhour = explode("\r\n", $settings['business_info']['openingHours']);
|
138 |
+
if (!empty($aOhour) && is_array($aOhour)) {
|
139 |
+
if (count($aOhour) == 1) {
|
140 |
+
$webMeta["openingHours"] = $aOhour[0];
|
141 |
+
} else if (count($aOhour) > 1) {
|
142 |
+
$webMeta["openingHours"] = $aOhour;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
$webMeta["geo"] = array(
|
147 |
+
"@type" => "GeoCoordinates",
|
148 |
+
"latitude" => !empty($settings['business_info']['latitude']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['latitude']) : null,
|
149 |
+
"longitude" => !empty($settings['business_info']['longitude']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['longitude']) : null,
|
150 |
+
);
|
151 |
+
}
|
152 |
+
|
153 |
+
if (in_array($siteType, array('FoodEstablishment', 'Bakery', 'BarOrPub', 'Brewery', 'CafeOrCoffeeShop', 'FastFoodRestaurant', 'IceCreamShop', 'Restaurant', 'Winery'))) {
|
154 |
+
$webMeta["servesCuisine"] = !empty($settings['restaurant']['servesCuisine']) ? $KcSeoWPSchema->sanitizeOutPut($settings['restaurant']['servesCuisine'], 'textarea') : null;
|
155 |
+
}
|
156 |
+
|
157 |
+
$webMeta["url"] = !empty($settings['web_url']) ? $KcSeoWPSchema->sanitizeOutPut($settings['web_url'], 'url') : $KcSeoWPSchema->sanitizeOutPut(get_home_url(), 'url');
|
158 |
+
if (!empty($settings['social']) && is_array($settings['social'])) {
|
159 |
+
$link = array();
|
160 |
+
foreach ($settings['social'] as $socialD) {
|
161 |
+
if ($socialD['link']) {
|
162 |
+
$link[] = $socialD['link'];
|
163 |
+
}
|
164 |
+
}
|
165 |
+
if (!empty($link)) {
|
166 |
+
$webMeta["sameAs"] = $link;
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
$webMeta["contactPoint"] = array(
|
171 |
+
"@type" => "ContactPoint",
|
172 |
+
"telephone" => !empty($settings['contact']['telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['telephone']) : (!empty($settings['site_telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_telephone']) : null),
|
173 |
+
"contactType" => !empty($settings['contact']['contactType']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['contactType']) : '',
|
174 |
+
"email" => !empty($settings['contact']['email']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['email']) : '',
|
175 |
+
"contactOption" => !empty($settings['contact']['contactOption']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['contactOption']) : '',
|
176 |
+
"areaServed" => !empty($settings['area_served']) ? implode(',',
|
177 |
+
!empty($settings['area_served']) ? $settings['area_served'] : array()) : '',
|
178 |
+
"availableLanguage" => !empty($settings['availableLanguage']) ? @implode(',',
|
179 |
+
!empty($settings['availableLanguage']) ? $settings['availableLanguage'] : array()) : null
|
180 |
+
);
|
181 |
+
$webMeta["address"] = array(
|
182 |
+
"@type" => "PostalAddress",
|
183 |
+
"addressCountry" => !empty($settings['address']['country']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['country']) : null,
|
184 |
+
"addressLocality" => !empty($settings['address']['locality']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['locality']) : null,
|
185 |
+
"addressRegion" => !empty($settings['address']['region']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['region']) : null,
|
186 |
+
"postalCode" => !empty($settings['address']['postalcode']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['postalcode']) : null,
|
187 |
+
"streetAddress" => !empty($settings['address']['street']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['street']) : null
|
188 |
+
);
|
189 |
+
|
190 |
+
$main_settings = get_option($KcSeoWPSchema->options['main_settings']);
|
191 |
+
$site_schema = !empty($main_settings['site_schema']) ? $main_settings['site_schema'] : 'home_page';
|
192 |
if ($site_schema !== 'off') {
|
193 |
if ($webMeta["@type"]) {
|
194 |
if ($site_schema == 'home_page') {
|
201 |
}
|
202 |
}
|
203 |
|
204 |
+
if (is_single() || is_page()) {
|
205 |
+
$post = get_queried_object();
|
206 |
+
foreach ($schemaModel->schemaTypes() as $schemaID => $schema) {
|
207 |
+
$schemaMetaId = $KcSeoWPSchema->KcSeoPrefix . $schemaID;
|
208 |
+
$metaData = get_post_meta($post->ID, $schemaMetaId, true);
|
209 |
+
$metaData = (is_array($metaData) ? $metaData : array());
|
210 |
+
if (!empty($metaData) && !empty($metaData['active'])) {
|
211 |
+
$html .= $schemaModel->schemaOutput($schemaID, $metaData);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
echo $html;
|
216 |
+
}
|
217 |
+
}
|
218 |
endif;
|
wp-seo-structured-data-schema.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WP SEO Structured Data Schema
|
4 |
* Plugin URI: https://wpsemplugins.com/
|
5 |
* Description: Comprehensive JSON-LD based Structured Data solution for WordPress for adding schema for organizations, businesses, blog posts, ratings & more.
|
6 |
-
* Version: 2.5.
|
7 |
* Author: WPSEMPlugins
|
8 |
* Author URI: https://wpsemplugins.com/
|
9 |
* Text Domain: wp-seo-structured-data-schema
|
3 |
* Plugin Name: WP SEO Structured Data Schema
|
4 |
* Plugin URI: https://wpsemplugins.com/
|
5 |
* Description: Comprehensive JSON-LD based Structured Data solution for WordPress for adding schema for organizations, businesses, blog posts, ratings & more.
|
6 |
+
* Version: 2.5.4
|
7 |
* Author: WPSEMPlugins
|
8 |
* Author URI: https://wpsemplugins.com/
|
9 |
* Text Domain: wp-seo-structured-data-schema
|