WP SEO Structured Data Schema - Version 2.6.17.2

Version Description

  • Fix local business @id property

=

Download this release

Release Info

Developer kcseopro
Plugin Icon 128x128 WP SEO Structured Data Schema
Version 2.6.17.2
Comparing to
See all releases

Code changes from version 2.6.17.1 to 2.6.17.2

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.7
7
- Stable tag: 2.6.17.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -114,6 +114,9 @@ You'll find the [FAQ on WPSEMPlugins.com](https://wpsemplugins.com/wordpress-seo
114
 
115
  == Changelog ==
116
 
 
 
 
117
  == 2.6.17.1 =
118
  * Fix post save issue
119
 
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.7
7
+ Stable tag: 2.6.17.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
114
 
115
  == Changelog ==
116
 
117
+ == 2.6.17.2 =
118
+ * Fix local business @id property
119
+
120
  == 2.6.17.1 =
121
  * Fix post save issue
122
 
lib/classes/KcSeoOutput.php CHANGED
@@ -1,216 +1,220 @@
1
  <?php
2
 
3
- if ( ! class_exists( 'KcSeoOutput' ) ):
4
-
5
- class KcSeoOutput {
6
- function __construct() {
7
- add_action( 'wp_footer', array( $this, 'footer' ), 99 );
8
- add_action( 'amp_post_template_footer', array( $this, 'footer' ), 999 ); // AMP support
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 head_product_name() {
14
- return 'WP SEO Structured Data Plugin';
15
- }
16
-
17
- public function debug_mark( $echo = true ) {
18
- $marker = sprintf(
19
- '<!-- This site is optimized with Phil Singleton\'s ' . $this->head_product_name() . ' v%1$s - https://kcseopro.com/wordpress-seo-structured-data-schema-plugin/ -->',
20
- KCSEO_WP_SCHEMA_VERSION
21
- );
22
-
23
- if ( $echo === false ) {
24
- return $marker;
25
- } else {
26
- echo "\n${marker}\n";
27
- }
28
- }
29
-
30
- function footer() {
31
-
32
- global $wp_query;
33
-
34
- $old_wp_query = null;
35
-
36
- if ( ! $wp_query->is_main_query() ) {
37
- $old_wp_query = $wp_query;
38
- wp_reset_query();
39
- }
40
- wp_reset_postdata(); // TODO This is for wrong theme loop
41
- do_action( 'kcseo_footer' );
42
-
43
- echo "\n<!-- / ", $this->head_product_name(), ". -->\n\n";
44
-
45
- if ( ! empty( $old_wp_query ) ) {
46
- $GLOBALS['wp_query'] = $old_wp_query;
47
- unset( $old_wp_query );
48
- }
49
-
50
- return;
51
- }
52
-
53
- function load_schema() {
54
- global $KcSeoWPSchema;
55
- $schemaModel = new KcSeoSchemaModel;
56
- $html = null;
57
- $settings = get_option( $KcSeoWPSchema->options['settings'] );
58
- if ( empty( $settings['disable_site_schema'] ) ) {
59
- if ( is_home() || is_front_page() ) {
60
- $metaData = array();
61
-
62
- $metaData["@context"] = "http://schema.org/";
63
- $metaData["@type"] = "WebSite";
64
- $author_url = ( ! empty( $settings['siteurl'] ) ? $settings['siteurl'] : get_home_url() );
65
-
66
- if ( ! empty( $settings['homeonly'] ) && $settings['homeonly'] ) {
67
- $metaData["url"] = $author_url;
68
- $metaData["potentialAction"] = array(
69
- "@type" => "SearchAction",
70
- "target" => trailingslashit( get_home_url() ) . "?s={query}",
71
- "query-input" => "required name=query"
72
- );
73
- $html .= $schemaModel->get_jsonEncode( $metaData );
74
- } else {
75
- $metaData["url"] = $KcSeoWPSchema->sanitizeOutPut( $author_url, 'url' );
76
- $metaData["name"] = ! empty( $settings['sitename'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['sitename'] ) : null;
77
- $metaData["alternateName"] = ! empty( $settings['siteaname'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['siteaname'] ) : null;
78
- $html .= $schemaModel->get_jsonEncode( $metaData );
79
- }
80
- }
81
- }
82
- $webMeta = array();
83
- $webMeta["@context"] = "http://schema.org";
84
- $siteType = ! empty( $settings['site_type'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['site_type'] ) : null;
85
- $webMeta["@type"] = $siteType;
86
- if ( $siteType != "Organization" ) {
87
- if ( ! empty( $settings['site_image'] ) && $imgID = absint( $settings['site_image'] ) ) {
88
- $image_url = wp_get_attachment_url( $imgID, 'full' );
89
- $webMeta["image"] = $KcSeoWPSchema->sanitizeOutPut( $image_url, 'url' );
90
- } else {
91
- $webMeta["image"] = null;
92
- }
93
- $webMeta["priceRange"] = ! empty( $settings['site_price_range'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['site_price_range'] ) : null;
94
- $webMeta["telephone"] = ! empty( $settings['site_telephone'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['site_telephone'] ) : null;
95
- }
96
-
97
- if ( ! empty( $settings['additionalType'] ) ) {
98
- $aType = explode( "\r\n", $settings['additionalType'] );
99
- if ( ! empty( $aType ) && is_array( $aType ) ) {
100
- if ( count( $aType ) == 1 ) {
101
- $webMeta["additionalType"] = $aType[0];
102
- } else if ( count( $aType ) > 1 ) {
103
- $webMeta["additionalType"] = $aType;
104
- }
105
- }
106
- }
107
-
108
- if ( $siteType == 'Person' ) {
109
- $webMeta["name"] = ! empty( $settings['person']['name'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['name'] ) : null;
110
- $webMeta["worksFor"] = ! empty( $settings['person']['worksFor'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['worksFor'] ) : null;
111
- $webMeta["jobTitle"] = ! empty( $settings['person']['jobTitle'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['jobTitle'] ) : null;
112
- $webMeta["image"] = ! empty( $settings['person']['image'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['image'], 'url' ) : null;
113
- $webMeta["description"] = ! empty( $settings['person']['description'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['description'], 'textarea' ) : null;
114
- $webMeta["birthDate"] = ! empty( $settings['person']['birthDate'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['person']['birthDate'] ) : null;
115
- } else {
116
- $webMeta["name"] = ! empty( $settings['type_name'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['type_name'] ) : null;
117
- if ( ! empty( $settings['organization_logo'] ) && $imgID = absint( $settings['organization_logo'] ) ) {
118
- $image_url = wp_get_attachment_url( $imgID, 'full' );
119
- $webMeta["logo"] = $KcSeoWPSchema->sanitizeOutPut( $image_url, 'url' );
120
- } else {
121
- $webMeta["logo"] = null;
122
- }
123
- }
124
- if ( $siteType != "Organization" && $siteType != "Person" ) {
125
- $webMeta["description"] = ! empty( $settings['business_info']['description'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['business_info']['description'], 'textarea' ) : null;
126
- if ( ! empty( $settings['business_info']['openingHours'] ) ) {
127
- $aOhour = explode( "\r\n", $settings['business_info']['openingHours'] );
128
- if ( ! empty( $aOhour ) && is_array( $aOhour ) ) {
129
- if ( count( $aOhour ) == 1 ) {
130
- $webMeta["openingHours"] = $aOhour[0];
131
- } else if ( count( $aOhour ) > 1 ) {
132
- $webMeta["openingHours"] = $aOhour;
133
- }
134
- }
135
- }
136
- $webMeta["geo"] = array(
137
- "@type" => "GeoCoordinates",
138
- "latitude" => ! empty( $settings['business_info']['latitude'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['business_info']['latitude'] ) : null,
139
- "longitude" => ! empty( $settings['business_info']['longitude'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['business_info']['longitude'] ) : null,
140
- );
141
- }
142
-
143
- if ( in_array( $siteType, array(
144
- 'FoodEstablishment',
145
- 'Bakery',
146
- 'BarOrPub',
147
- 'Brewery',
148
- 'CafeOrCoffeeShop',
149
- 'FastFoodRestaurant',
150
- 'IceCreamShop',
151
- 'Restaurant',
152
- 'Winery'
153
- ) ) ) {
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'] ) ? $settings['area_served'] : '',
177
- "availableLanguage" => ! empty( $settings['availableLanguage'] ) ? $settings['availableLanguage'] : null
178
- );
179
- $webMeta["address"] = array(
180
- "@type" => "PostalAddress",
181
- "addressCountry" => ! empty( $settings['address']['country'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['address']['country'] ) : null,
182
- "addressLocality" => ! empty( $settings['address']['locality'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['address']['locality'] ) : null,
183
- "addressRegion" => ! empty( $settings['address']['region'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['address']['region'] ) : null,
184
- "postalCode" => ! empty( $settings['address']['postalcode'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['address']['postalcode'] ) : null,
185
- "streetAddress" => ! empty( $settings['address']['street'] ) ? $KcSeoWPSchema->sanitizeOutPut( $settings['address']['street'] ) : null
186
- );
187
-
188
- $main_settings = get_option( $KcSeoWPSchema->options['main_settings'] );
189
- $site_schema = ! empty( $main_settings['site_schema'] ) ? $main_settings['site_schema'] : 'home_page';
190
- if ( $site_schema !== 'off' ) {
191
- if ( $webMeta["@type"] ) {
192
- if ( $site_schema == 'home_page' ) {
193
- if ( is_home() || is_front_page() ) {
194
- $html .= $schemaModel->get_jsonEncode( $webMeta );
195
- }
196
- } elseif ( $site_schema == 'all' ) {
197
- $html .= $schemaModel->get_jsonEncode( $webMeta );
198
- }
199
- }
200
- }
201
-
202
- if ( is_single() || is_page() ) {
203
- $post = get_queried_object();
204
- foreach ( KcSeoOptions::getSchemaTypes() as $schemaID => $schema ) {
205
- $schemaMetaId = $KcSeoWPSchema->KcSeoPrefix . $schemaID;
206
- $metaData = get_post_meta( $post->ID, $schemaMetaId, true );
207
- $metaData = ( is_array( $metaData ) ? $metaData : array() );
208
- if ( ! empty( $metaData ) && ! empty( $metaData['active'] ) ) {
209
- $html .= $schemaModel->schemaOutput( $schemaID, $metaData );
210
- }
211
- }
212
- }
213
- echo $html;
214
- }
215
- }
 
 
 
 
216
  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'), 99);
9
+ add_action('amp_post_template_footer', array($this, 'footer'), 999); // AMP support
10
+ add_action('kcseo_footer', array($this, 'debug_mark'), 2);
11
+ add_action('kcseo_footer', array($this, 'load_schema'), 3);
12
+ }
13
+
14
+ private function head_product_name() {
15
+ return 'WP SEO Structured Data Plugin';
16
+ }
17
+
18
+ public function debug_mark($echo = true) {
19
+ $marker = sprintf(
20
+ '<!-- This site is optimized with Phil Singleton\'s ' . $this->head_product_name() . ' v%1$s - https://kcseopro.com/wordpress-seo-structured-data-schema-plugin/ -->',
21
+ KCSEO_WP_SCHEMA_VERSION
22
+ );
23
+
24
+ if ($echo === false) {
25
+ return $marker;
26
+ } else {
27
+ echo "\n${marker}\n";
28
+ }
29
+ }
30
+
31
+ function footer() {
32
+
33
+ global $wp_query;
34
+
35
+ $old_wp_query = null;
36
+
37
+ if (!$wp_query->is_main_query()) {
38
+ $old_wp_query = $wp_query;
39
+ wp_reset_query();
40
+ }
41
+ wp_reset_postdata(); // TODO This is for wrong theme loop
42
+ do_action('kcseo_footer');
43
+
44
+ echo "\n<!-- / ", $this->head_product_name(), ". -->\n\n";
45
+
46
+ if (!empty($old_wp_query)) {
47
+ $GLOBALS['wp_query'] = $old_wp_query;
48
+ unset($old_wp_query);
49
+ }
50
+
51
+ return;
52
+ }
53
+
54
+ function load_schema() {
55
+ global $KcSeoWPSchema;
56
+ $schemaModel = new KcSeoSchemaModel;
57
+ $html = null;
58
+ $settings = get_option($KcSeoWPSchema->options['settings']);
59
+ if (empty($settings['disable_site_schema'])) {
60
+ if (is_home() || is_front_page()) {
61
+ $metaData = array();
62
+
63
+ $metaData["@context"] = "https://schema.org/";
64
+ $metaData["@type"] = "WebSite";
65
+ $author_url = (!empty($settings['siteurl']) ? $settings['siteurl'] : get_home_url());
66
+
67
+ if (!empty($settings['homeonly']) && $settings['homeonly']) {
68
+ $metaData["url"] = $author_url;
69
+ $metaData["potentialAction"] = array(
70
+ "@type" => "SearchAction",
71
+ "target" => trailingslashit(get_home_url()) . "?s={query}",
72
+ "query-input" => "required name=query"
73
+ );
74
+ $html .= $schemaModel->get_jsonEncode($metaData);
75
+ } else {
76
+ $metaData["url"] = $KcSeoWPSchema->sanitizeOutPut($author_url, 'url');
77
+ $metaData["name"] = !empty($settings['sitename']) ? $KcSeoWPSchema->sanitizeOutPut($settings['sitename']) : null;
78
+ $metaData["alternateName"] = !empty($settings['siteaname']) ? $KcSeoWPSchema->sanitizeOutPut($settings['siteaname']) : null;
79
+ $html .= $schemaModel->get_jsonEncode($metaData);
80
+ }
81
+ }
82
+ }
83
+ $siteType = !empty($settings['site_type']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_type']) : null;
84
+ $webMeta = [
85
+ "@context" => "https://schema.org",
86
+ '@type' => $siteType,
87
+ '@id' => get_home_url()
88
+ ];
89
+ if ($siteType != "Organization") {
90
+ if (!empty($settings['site_image']) && $imgID = absint($settings['site_image'])) {
91
+ $image_url = wp_get_attachment_url($imgID);
92
+ $webMeta["image"] = $KcSeoWPSchema->sanitizeOutPut($image_url, 'url');
93
+ } else {
94
+ $webMeta["image"] = null;
95
+ }
96
+ $webMeta["priceRange"] = !empty($settings['site_price_range']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_price_range']) : null;
97
+ $webMeta["telephone"] = !empty($settings['site_telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_telephone']) : null;
98
+ }
99
+
100
+ if (!empty($settings['additionalType'])) {
101
+ $aType = explode("\r\n", $settings['additionalType']);
102
+ if (!empty($aType) && is_array($aType)) {
103
+ if (count($aType) == 1) {
104
+ $webMeta["additionalType"] = $aType[0];
105
+ } else if (count($aType) > 1) {
106
+ $webMeta["additionalType"] = $aType;
107
+ }
108
+ }
109
+ }
110
+
111
+ if ($siteType == 'Person') {
112
+ $webMeta["name"] = !empty($settings['person']['name']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['name']) : null;
113
+ $webMeta["worksFor"] = !empty($settings['person']['worksFor']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['worksFor']) : null;
114
+ $webMeta["jobTitle"] = !empty($settings['person']['jobTitle']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['jobTitle']) : null;
115
+ $webMeta["image"] = !empty($settings['person']['image']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['image'], 'url') : null;
116
+ $webMeta["description"] = !empty($settings['person']['description']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['description'], 'textarea') : null;
117
+ $webMeta["birthDate"] = !empty($settings['person']['birthDate']) ? $KcSeoWPSchema->sanitizeOutPut($settings['person']['birthDate']) : null;
118
+ } else {
119
+ $webMeta["name"] = !empty($settings['type_name']) ? $KcSeoWPSchema->sanitizeOutPut($settings['type_name']) : null;
120
+ if (!empty($settings['organization_logo']) && $imgID = absint($settings['organization_logo'])) {
121
+ $image_url = wp_get_attachment_url($imgID);
122
+ $webMeta["logo"] = $KcSeoWPSchema->sanitizeOutPut($image_url, 'url');
123
+ } else {
124
+ $webMeta["logo"] = null;
125
+ }
126
+ }
127
+ if ($siteType != "Organization" && $siteType != "Person") {
128
+ $webMeta["description"] = !empty($settings['business_info']['description']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['description'], 'textarea') : null;
129
+ if (!empty($settings['business_info']['openingHours'])) {
130
+ $aOhour = explode("\r\n", $settings['business_info']['openingHours']);
131
+ if (!empty($aOhour) && is_array($aOhour)) {
132
+ if (count($aOhour) == 1) {
133
+ $webMeta["openingHours"] = $aOhour[0];
134
+ } else if (count($aOhour) > 1) {
135
+ $webMeta["openingHours"] = $aOhour;
136
+ }
137
+ }
138
+ }
139
+ $webMeta["geo"] = array(
140
+ "@type" => "GeoCoordinates",
141
+ "latitude" => !empty($settings['business_info']['latitude']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['latitude']) : null,
142
+ "longitude" => !empty($settings['business_info']['longitude']) ? $KcSeoWPSchema->sanitizeOutPut($settings['business_info']['longitude']) : null,
143
+ );
144
+ }
145
+
146
+ if (in_array($siteType, array(
147
+ 'FoodEstablishment',
148
+ 'Bakery',
149
+ 'BarOrPub',
150
+ 'Brewery',
151
+ 'CafeOrCoffeeShop',
152
+ 'FastFoodRestaurant',
153
+ 'IceCreamShop',
154
+ 'Restaurant',
155
+ 'Winery'
156
+ ))) {
157
+ $webMeta["servesCuisine"] = !empty($settings['restaurant']['servesCuisine']) ? $KcSeoWPSchema->sanitizeOutPut($settings['restaurant']['servesCuisine'], 'textarea') : null;
158
+ }
159
+
160
+ $webMeta["url"] = !empty($settings['web_url']) ? $KcSeoWPSchema->sanitizeOutPut($settings['web_url'], 'url') : $KcSeoWPSchema->sanitizeOutPut(get_home_url(), 'url');
161
+ if (!empty($settings['social']) && is_array($settings['social'])) {
162
+ $link = array();
163
+ foreach ($settings['social'] as $socialD) {
164
+ if ($socialD['link']) {
165
+ $link[] = $socialD['link'];
166
+ }
167
+ }
168
+ if (!empty($link)) {
169
+ $webMeta["sameAs"] = $link;
170
+ }
171
+ }
172
+
173
+ $webMeta["contactPoint"] = array(
174
+ "@type" => "ContactPoint",
175
+ "telephone" => !empty($settings['contact']['telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['telephone']) : (!empty($settings['site_telephone']) ? $KcSeoWPSchema->sanitizeOutPut($settings['site_telephone']) : null),
176
+ "contactType" => !empty($settings['contact']['contactType']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['contactType']) : '',
177
+ "email" => !empty($settings['contact']['email']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['email']) : '',
178
+ "contactOption" => !empty($settings['contact']['contactOption']) ? $KcSeoWPSchema->sanitizeOutPut($settings['contact']['contactOption']) : '',
179
+ "areaServed" => !empty($settings['area_served']) ? $settings['area_served'] : '',
180
+ "availableLanguage" => !empty($settings['availableLanguage']) ? $settings['availableLanguage'] : null
181
+ );
182
+ $webMeta["address"] = array(
183
+ "@type" => "PostalAddress",
184
+ "addressCountry" => !empty($settings['address']['country']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['country']) : null,
185
+ "addressLocality" => !empty($settings['address']['locality']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['locality']) : null,
186
+ "addressRegion" => !empty($settings['address']['region']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['region']) : null,
187
+ "postalCode" => !empty($settings['address']['postalcode']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['postalcode']) : null,
188
+ "streetAddress" => !empty($settings['address']['street']) ? $KcSeoWPSchema->sanitizeOutPut($settings['address']['street']) : null
189
+ );
190
+
191
+ $main_settings = get_option($KcSeoWPSchema->options['main_settings']);
192
+ $site_schema = !empty($main_settings['site_schema']) ? $main_settings['site_schema'] : 'home_page';
193
+
194
+ if ($site_schema !== 'off') {
195
+ if ($webMeta["@type"]) {
196
+ if ($site_schema == 'home_page') {
197
+ if (is_home() || is_front_page()) {
198
+ $html .= $schemaModel->get_jsonEncode($webMeta);
199
+ }
200
+ } elseif ($site_schema == 'all') {
201
+ $html .= $schemaModel->get_jsonEncode($webMeta);
202
+ }
203
+ }
204
+ }
205
+
206
+ if (is_single() || is_page()) {
207
+ $post = get_queried_object();
208
+ foreach (KcSeoOptions::getSchemaTypes() as $schemaID => $schema) {
209
+ $schemaMetaId = $KcSeoWPSchema->KcSeoPrefix . $schemaID;
210
+ $metaData = get_post_meta($post->ID, $schemaMetaId, true);
211
+ $metaData = (is_array($metaData) ? $metaData : array());
212
+ if (!empty($metaData) && !empty($metaData['active'])) {
213
+ $html .= $schemaModel->schemaOutput($schemaID, $metaData);
214
+ }
215
+ }
216
+ }
217
+ echo $html;
218
+ }
219
+ }
220
  endif;
lib/models/KcSeoSchemaModel.php CHANGED
@@ -16,7 +16,7 @@ if (!class_exists('KcSeoSchemaModel')):
16
  switch ($schemaID) {
17
  case "article":
18
  $article = array(
19
- "@context" => "http://schema.org",
20
  "@type" => "Article"
21
  );
22
  if (!empty($metaData['headline'])) {
@@ -83,7 +83,7 @@ if (!class_exists('KcSeoSchemaModel')):
83
 
84
  case "news_article":
85
  $newsArticle = array(
86
- "@context" => "http://schema.org",
87
  "@type" => "NewsArticle"
88
  );
89
  if (!empty($metaData['headline'])) {
@@ -147,7 +147,7 @@ if (!class_exists('KcSeoSchemaModel')):
147
 
148
  case "blog_posting":
149
  $blogPosting = array(
150
- "@context" => "http://schema.org",
151
  "@type" => "BlogPosting"
152
  );
153
  if (!empty($metaData['headline'])) {
@@ -211,7 +211,7 @@ if (!class_exists('KcSeoSchemaModel')):
211
 
212
  case 'event':
213
  $event = array(
214
- "@context" => "http://schema.org",
215
  "@type" => "Event"
216
  );
217
  if (!empty($metaData['name'])) {
@@ -267,7 +267,7 @@ if (!class_exists('KcSeoSchemaModel')):
267
  $html .= $this->get_jsonEncode(apply_filters('kcseo_snippet_event', $event, $metaData));
268
  if (isset($metaData['review_active'])) {
269
  $event_review = array(
270
- "@context" => "http://schema.org",
271
  "@type" => "Review"
272
  );
273
 
@@ -312,7 +312,7 @@ if (!class_exists('KcSeoSchemaModel')):
312
 
313
  case 'product':
314
  $product = array(
315
- "@context" => "http://schema.org",
316
  "@type" => "Product"
317
  );
318
  if (!empty($metaData['name'])) {
@@ -373,7 +373,7 @@ if (!class_exists('KcSeoSchemaModel')):
373
 
374
  case 'video':
375
  $video = array(
376
- "@context" => "http://schema.org",
377
  "@type" => "VideoObject"
378
  );
379
  if (!empty($metaData['name'])) {
@@ -408,7 +408,7 @@ if (!class_exists('KcSeoSchemaModel')):
408
 
409
  case 'service':
410
  $service = array(
411
- "@context" => "http://schema.org",
412
  "@type" => "Service"
413
  );
414
  if (!empty($metaData['name'])) {
@@ -449,7 +449,7 @@ if (!class_exists('KcSeoSchemaModel')):
449
 
450
  case 'review':
451
  $review = array(
452
- "@context" => "http://schema.org",
453
  "@type" => "Review"
454
  );
455
  if (!empty($metaData['itemName'])) {
@@ -491,9 +491,12 @@ if (!class_exists('KcSeoSchemaModel')):
491
  break;
492
  case 'aggregate_rating':
493
  $aRating = array(
494
- "@context" => "http://schema.org",
495
  "@type" => !empty($metaData['schema_type']) ? $metaData['schema_type'] : "LocalBusiness"
496
  );
 
 
 
497
  if (!empty($metaData['name'])) {
498
  $aRating["name"] = $KcSeoWPSchema->sanitizeOutPut($metaData['name']);
499
  }
@@ -544,7 +547,7 @@ if (!class_exists('KcSeoSchemaModel')):
544
 
545
  case 'restaurant':
546
  $restaurant = array(
547
- "@context" => "http://schema.org",
548
  "@type" => "Restaurant"
549
  );
550
  if (!empty($metaData['name'])) {
@@ -582,8 +585,9 @@ if (!class_exists('KcSeoSchemaModel')):
582
 
583
  case 'localBusiness':
584
  $local_business = array(
585
- "@context" => "http://schema.org",
586
- "@type" => "LocalBusiness"
 
587
  );
588
  if (!empty($metaData['name'])) {
589
  $local_business["name"] = $KcSeoWPSchema->sanitizeOutPut($metaData['name']);
@@ -616,7 +620,7 @@ if (!class_exists('KcSeoSchemaModel')):
616
  $html .= $this->get_jsonEncode(apply_filters('kcseo_snippet_local_business', $local_business, $metaData));
617
  if (isset($metaData['review_active'])) {
618
  $local_business_review = array(
619
- "@context" => "http://schema.org",
620
  "@type" => "Review",
621
  );
622
  if (isset($metaData['review_datePublished']) && !empty($metaData['review_datePublished'])) {
@@ -669,7 +673,7 @@ if (!class_exists('KcSeoSchemaModel')):
669
  break;
670
  case 'specialAnnouncement':
671
  $announcement = array(
672
- "@context" => "http://schema.org",
673
  "@type" => "SpecialAnnouncement",
674
  "category" => "https://www.wikidata.org/wiki/Q81068910"
675
  );
@@ -893,9 +897,13 @@ if (!class_exists('KcSeoSchemaModel')):
893
  return $html;
894
  }
895
 
 
 
 
 
 
896
  function get_jsonEncode($data = array()) {
897
  $html = null;
898
- /** @var TYPE_NAME $data */
899
  if (!empty($data) && is_array($data)) {
900
  $html .= '<script type="application/ld+json">' . json_encode($data,
901
  JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</script>';
16
  switch ($schemaID) {
17
  case "article":
18
  $article = array(
19
+ "@context" => "https://schema.org",
20
  "@type" => "Article"
21
  );
22
  if (!empty($metaData['headline'])) {
83
 
84
  case "news_article":
85
  $newsArticle = array(
86
+ "@context" => "https://schema.org",
87
  "@type" => "NewsArticle"
88
  );
89
  if (!empty($metaData['headline'])) {
147
 
148
  case "blog_posting":
149
  $blogPosting = array(
150
+ "@context" => "https://schema.org",
151
  "@type" => "BlogPosting"
152
  );
153
  if (!empty($metaData['headline'])) {
211
 
212
  case 'event':
213
  $event = array(
214
+ "@context" => "https://schema.org",
215
  "@type" => "Event"
216
  );
217
  if (!empty($metaData['name'])) {
267
  $html .= $this->get_jsonEncode(apply_filters('kcseo_snippet_event', $event, $metaData));
268
  if (isset($metaData['review_active'])) {
269
  $event_review = array(
270
+ "@context" => "https://schema.org",
271
  "@type" => "Review"
272
  );
273
 
312
 
313
  case 'product':
314
  $product = array(
315
+ "@context" => "https://schema.org",
316
  "@type" => "Product"
317
  );
318
  if (!empty($metaData['name'])) {
373
 
374
  case 'video':
375
  $video = array(
376
+ "@context" => "https://schema.org",
377
  "@type" => "VideoObject"
378
  );
379
  if (!empty($metaData['name'])) {
408
 
409
  case 'service':
410
  $service = array(
411
+ "@context" => "https://schema.org",
412
  "@type" => "Service"
413
  );
414
  if (!empty($metaData['name'])) {
449
 
450
  case 'review':
451
  $review = array(
452
+ "@context" => "https://schema.org",
453
  "@type" => "Review"
454
  );
455
  if (!empty($metaData['itemName'])) {
491
  break;
492
  case 'aggregate_rating':
493
  $aRating = array(
494
+ "@context" => "https://schema.org",
495
  "@type" => !empty($metaData['schema_type']) ? $metaData['schema_type'] : "LocalBusiness"
496
  );
497
+ if ("LocalBusiness" === $aRating['@type']) {
498
+ $aRating['@id'] = get_home_url();
499
+ }
500
  if (!empty($metaData['name'])) {
501
  $aRating["name"] = $KcSeoWPSchema->sanitizeOutPut($metaData['name']);
502
  }
547
 
548
  case 'restaurant':
549
  $restaurant = array(
550
+ "@context" => "https://schema.org",
551
  "@type" => "Restaurant"
552
  );
553
  if (!empty($metaData['name'])) {
585
 
586
  case 'localBusiness':
587
  $local_business = array(
588
+ "@context" => "https://schema.org",
589
+ "@type" => "LocalBusiness",
590
+ '@id' => get_home_url()
591
  );
592
  if (!empty($metaData['name'])) {
593
  $local_business["name"] = $KcSeoWPSchema->sanitizeOutPut($metaData['name']);
620
  $html .= $this->get_jsonEncode(apply_filters('kcseo_snippet_local_business', $local_business, $metaData));
621
  if (isset($metaData['review_active'])) {
622
  $local_business_review = array(
623
+ "@context" => "https://schema.org",
624
  "@type" => "Review",
625
  );
626
  if (isset($metaData['review_datePublished']) && !empty($metaData['review_datePublished'])) {
673
  break;
674
  case 'specialAnnouncement':
675
  $announcement = array(
676
+ "@context" => "https://schema.org",
677
  "@type" => "SpecialAnnouncement",
678
  "category" => "https://www.wikidata.org/wiki/Q81068910"
679
  );
897
  return $html;
898
  }
899
 
900
+ /**
901
+ * @param array $data
902
+ *
903
+ * @return string|null
904
+ */
905
  function get_jsonEncode($data = array()) {
906
  $html = null;
 
907
  if (!empty($data) && is_array($data)) {
908
  $html .= '<script type="application/ld+json">' . json_encode($data,
909
  JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</script>';
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.6.17.1
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.6.17.2
7
  * Author: WPSEMPlugins
8
  * Author URI: https://wpsemplugins.com/
9
  * Text Domain: wp-seo-structured-data-schema