Schema - Version 1.7.1

Version Description

  • Added new function schema_wp_post_meta_fields, stop loading post meta directly.
  • Added new function schema_wp_is_blog, check if is Blog page.
  • Added capability support for super admin.
  • Added new function to truncate headlines to 110 characters per Google guidelines.
  • Enhanced performance by saving json-ld post meta only if has new value.
  • Enhanced some plugin settings description.
  • Enhanced the way plugin check for the Blog page.
  • Enhanced comments markup performance by checking comment number before query.
  • Fixed bug in schema_output function, typo in variable name.
  • Fixed home url when site is installed on its own subfolder.
  • Fixed AMP integration, schema was not present due to empty meta value.
  • Fixed copyrightYear markup in WPFooter, use post published year.
  • Fixed use of undefined constant notice in misc function file.
  • Fixed description markup in Blog page.
  • Fixed a PHP notice when settings page sections variable not containing an array.
  • Fixed admin menu item, hide the Schema Wizard empty menu item in dashboard.
  • Updated the readme.txt file, and pumped the tested WP version to 4.9.7
Download this release

Release Info

Developer hishaman
Plugin Icon 128x128 Schema
Version 1.7.1
Comparing to
See all releases

Code changes from version 1.7 to 1.7.1

includes/admin/class-setup-wizard.php CHANGED
@@ -28,6 +28,7 @@ class Schema_WP_Setup_Wizard {
28
  public function __construct() {
29
  if ( current_user_can( 'manage_options' ) ) {
30
  add_action( 'admin_menu', array( $this, 'admin_menus' ) );
 
31
  add_action( 'admin_init', array( $this, 'setup_wizard' ), 99 );
32
  }
33
  }
@@ -101,7 +102,16 @@ class Schema_WP_Setup_Wizard {
101
  * Add admin menus/screens.
102
  */
103
  public function admin_menus() {
104
- add_dashboard_page( '', '', 'manage_options', 'schema-setup', '' );
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
28
  public function __construct() {
29
  if ( current_user_can( 'manage_options' ) ) {
30
  add_action( 'admin_menu', array( $this, 'admin_menus' ) );
31
+ add_action( 'admin_head', array( $this, 'hide_admin_menus' ) );
32
  add_action( 'admin_init', array( $this, 'setup_wizard' ), 99 );
33
  }
34
  }
102
  * Add admin menus/screens.
103
  */
104
  public function admin_menus() {
105
+ add_dashboard_page( __('Schema Setup', 'schema-wp'), __('Schema Setup Wizard', 'schema-wp'), 'manage_options', 'schema-setup', '' );
106
+ }
107
+
108
+ /**
109
+ * Hide admin menus/screens.
110
+ *
111
+ * @since 1.7.1
112
+ */
113
+ public function hide_admin_menus() {
114
+ remove_submenu_page( 'index.php', 'schema-setup' );
115
  }
116
 
117
  /**
includes/admin/meta.php CHANGED
@@ -13,43 +13,22 @@
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
 
 
 
16
  /**
17
- * Schema post meta
18
  *
19
- * @since 1.4
20
  */
21
- $prefix = '_schema_';
 
 
22
 
23
  /**
24
- * Schema main post meta
25
  *
26
  * @since 1.4
27
  */
28
- $fields_main = array( apply_filters( 'schema_wp_types_post_meta_fields',
29
-
30
- array( // Select box
31
- 'label' => __('Schema Markup Type', 'schema-wp'), // <label>
32
- 'desc' => __('Select Schema type which describes your content best', 'schema-wp'), // description
33
- 'id' => $prefix.'type', // field id and name
34
- 'type' => 'select', // type of field
35
- 'options' => apply_filters( 'schema_wp_types', array ( // array of options
36
- 'Article' => array ( // array key needs to be the same as the option value
37
- 'label' => __('Article', 'schema-wp'), // text displayed as the option
38
- 'value' => __('Article', 'schema-wp'), // value stored for the option
39
- )
40
- )),
41
- ), // end of array
42
-
43
- array(
44
- 'label' => __('Post meta', 'schema-wp'),
45
- 'tip' => __('Enable custom post meta box', 'schema-wp'),
46
- 'desc' => __('Enable post meta box?', 'schema-wp'),
47
- 'id' => $prefix.'post_meta_box_enabled',
48
- 'type' => 'checkbox'
49
- )
50
- )
51
- );
52
-
53
  $fields_main = apply_filters( 'schema_wp_types_post_meta_fields', array(
54
 
55
  'schema_types' => array( // Select box
@@ -258,20 +237,21 @@ $fields_post_meta_box = array (
258
 
259
  );
260
 
261
- /**
262
- * Instantiate the class with all variables to create a meta box
263
- * var $id string meta box id
264
- * var $title string title
265
- * var $fields array fields
266
- * var $page string|array post type to add meta box to
267
- * var $context string context where to add meta box at (normal, side)
268
- * var $priority string meta box priority (high, core, default, low)
269
- * var $js bool including javascript or not
270
- */
271
- $schema_box = new Schema_Custom_Add_Meta_Box( 'schema', __('Schema Settings', 'schema-wp'), $fields_main, 'schema', 'normal', 'high', true );
272
- $schema_article_box = new Schema_Custom_Add_Meta_Box( 'schema_article', __('Article', 'schema-wp'), $fields_article, 'schema', 'normal', 'high', true );
273
- $schema_cpt_box = new Schema_Custom_Add_Meta_Box( 'schema_cpt', __('Post Types', 'schema-wp'), $fields_post_types, 'schema', 'side', 'default', true );
274
- $schema_post_meta_box = new Schema_Custom_Add_Meta_Box( 'schema_post_meta_box', __('Post Meta', 'schema-wp'), $fields_post_meta_box, 'schema', 'normal', 'default', true );
 
275
 
276
 
277
  /**
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
 
16
+
17
+ add_action( 'init', 'schema_wp_post_meta_fields' );
18
  /**
19
+ * Create schema post meta fields
20
  *
21
+ * @since 1.7.1
22
  */
23
+ function schema_wp_post_meta_fields() {
24
+
25
+ $prefix = '_schema_';
26
 
27
  /**
28
+ * Schema Main Type post meta
29
  *
30
  * @since 1.4
31
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  $fields_main = apply_filters( 'schema_wp_types_post_meta_fields', array(
33
 
34
  'schema_types' => array( // Select box
237
 
238
  );
239
 
240
+ /**
241
+ * Instantiate the class with all variables to create a meta box
242
+ * var $id string meta box id
243
+ * var $title string title
244
+ * var $fields array fields
245
+ * var $page string|array post type to add meta box to
246
+ * var $context string context where to add meta box at (normal, side)
247
+ * var $priority string meta box priority (high, core, default, low)
248
+ * var $js bool including javascript or not
249
+ */
250
+ $schema_box = new Schema_Custom_Add_Meta_Box( 'schema', __('Schema Settings', 'schema-wp'), $fields_main, 'schema', 'normal', 'high', true );
251
+ $schema_article_box = new Schema_Custom_Add_Meta_Box( 'schema_article', __('Article', 'schema-wp'), $fields_article, 'schema', 'normal', 'high', true );
252
+ $schema_cpt_box = new Schema_Custom_Add_Meta_Box( 'schema_cpt', __('Post Types', 'schema-wp'), $fields_post_types, 'schema', 'side', 'default', true );
253
+ $schema_post_meta_box = new Schema_Custom_Add_Meta_Box( 'schema_post_meta_box', __('Post Meta', 'schema-wp'), $fields_post_meta_box, 'schema', 'normal', 'default', true );
254
+ }
255
 
256
 
257
  /**
includes/admin/settings/display-settings.php CHANGED
@@ -88,7 +88,7 @@ function schema_wp_options_page() {
88
  </h1>
89
  <?php
90
 
91
- $number_of_sections = count( $sections );
92
  $number = 0;
93
  if ( $number_of_sections > 1 ) {
94
  echo '<div><ul class="subsubsub">';
88
  </h1>
89
  <?php
90
 
91
+ $number_of_sections = is_array($sections) ? count( $sections ) : 0;
92
  $number = 0;
93
  if ( $number_of_sections > 1 ) {
94
  echo '<div><ul class="subsubsub">';
includes/class-capabilities.php CHANGED
@@ -62,9 +62,8 @@ class Schema_WP_Capabilities {
62
  'publish_posts' => true,
63
  'read_private_pages' => true,
64
  'read_private_posts' => true,
65
-
66
- 'activate_plugins' => true,
67
- 'manage_options' => true
68
  ) );
69
  }
70
 
@@ -87,7 +86,9 @@ class Schema_WP_Capabilities {
87
 
88
  if ( is_object( $wp_roles ) ) {
89
 
 
90
  $wp_roles->add_cap( 'administrator', 'manage_schema_options' );
 
91
 
92
  }
93
  }
@@ -112,7 +113,8 @@ class Schema_WP_Capabilities {
112
 
113
  /** Site Administrator Capabilities */
114
  $wp_roles->remove_cap( 'administrator', 'manage_schema_options' );
 
115
 
116
  }
117
  }
118
- }
62
  'publish_posts' => true,
63
  'read_private_pages' => true,
64
  'read_private_posts' => true,
65
+ 'activate_plugins' => true,
66
+ 'manage_options' => true
 
67
  ) );
68
  }
69
 
86
 
87
  if ( is_object( $wp_roles ) ) {
88
 
89
+ /** Site Administrator Capabilities */
90
  $wp_roles->add_cap( 'administrator', 'manage_schema_options' );
91
+ $wp_roles->add_cap( 'super_admin', 'manage_schema_options' );
92
 
93
  }
94
  }
113
 
114
  /** Site Administrator Capabilities */
115
  $wp_roles->remove_cap( 'administrator', 'manage_schema_options' );
116
+ $wp_roles->remove_cap( 'super_admin', 'manage_schema_options' );
117
 
118
  }
119
  }
120
+ }
includes/deprecated-functions.php CHANGED
@@ -5,9 +5,37 @@
5
  *
6
  * This file is made to keep older non-used functions as a refrence.
7
  *
8
- * The functions within these files are loaded since the file itself won't be loaded
9
  *
10
  * @since 1.6
11
  * @return void
12
  */
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  *
6
  * This file is made to keep older non-used functions as a refrence.
7
  *
 
8
  *
9
  * @since 1.6
10
  * @return void
11
  */
12
 
13
+ /**
14
+ * Get First Post Date Function
15
+ *
16
+ * @since 1.6.9.8
17
+ * @param $format Type of date format to return, using PHP date standard, default Y-m-d
18
+ * @return Date of first post
19
+ */
20
+ function schema_wp_first_post_date( $format = 'Y-m-d' ) {
21
+ // Setup get_posts arguments
22
+ $ax_args = array(
23
+ 'numberposts' => -1,
24
+ 'post_status' => 'publish',
25
+ 'order' => 'ASC'
26
+ );
27
+
28
+ // Get all posts in order of first to last
29
+ $ax_get_all = get_posts($ax_args);
30
+
31
+ // Extract first post from array
32
+ $ax_first_post = $ax_get_all[0];
33
+
34
+ // Assign first post date to var
35
+ $ax_first_post_date = $ax_first_post->post_date;
36
+
37
+ // return date in required format
38
+ $output = date($format, strtotime($ax_first_post_date));
39
+
40
+ return $output;
41
+ }
includes/extensions/comment.php CHANGED
@@ -74,13 +74,25 @@ function schema_wp_do_comment( $schema ) {
74
  * @since 1.5.4
75
  * @return array
76
  */
77
- function schema_wp_get_comments() {
78
-
79
- global $post;
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  $number = apply_filters( 'schema_wp_do_comments', '10'); // default = 10
82
 
83
  $Comments = array();
 
84
  $PostComments = get_comments( array( 'post_id' => $post->ID, 'number' => $number, 'status' => 'approve', 'type' => 'comment' ) );
85
 
86
  if ( count( $PostComments ) ) {
74
  * @since 1.5.4
75
  * @return array
76
  */
77
+ function schema_wp_get_comments( $post_id = null ) {
 
 
78
 
79
+ if ( isset($post_id) ) {
80
+ $post = get_post($post_id);
81
+ } else {
82
+ global $post;
83
+ }
84
+
85
+ // Check comments count first, if now comments, then return an empty array
86
+ // @since 1.7.1
87
+ $comment_count = get_comments_number( $post->ID );
88
+ if ( $comment_count < 1 ) {
89
+ return array();
90
+ }
91
+
92
  $number = apply_filters( 'schema_wp_do_comments', '10'); // default = 10
93
 
94
  $Comments = array();
95
+
96
  $PostComments = get_comments( array( 'post_id' => $post->ID, 'number' => $number, 'status' => 'approve', 'type' => 'comment' ) );
97
 
98
  if ( count( $PostComments ) ) {
includes/extensions/page-about.php CHANGED
@@ -8,15 +8,14 @@
8
  // Exit if accessed directly
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
-
12
- add_filter( 'schema_output', 'schema_wp_no_sceham_output_if_page_about' );
13
  /**
14
  * Do not output schema default json-ld if this is the About page
15
  *
16
  * @since 1.5.2
17
  * @return schema json-ld array or an empy array
18
  */
19
- function schema_wp_no_sceham_output_if_page_about( $schema ) {
20
 
21
  $about_page_id = schema_wp_get_option( 'about_page' );
22
 
8
  // Exit if accessed directly
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
+ add_filter( 'schema_output', 'schema_wp_no_schema_output_if_page_about' );
 
12
  /**
13
  * Do not output schema default json-ld if this is the About page
14
  *
15
  * @since 1.5.2
16
  * @return schema json-ld array or an empy array
17
  */
18
+ function schema_wp_no_schema_output_if_page_about( $schema ) {
19
 
20
  $about_page_id = schema_wp_get_option( 'about_page' );
21
 
includes/extensions/page-contact.php CHANGED
@@ -9,14 +9,14 @@
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
 
12
- add_filter( 'schema_output', 'schema_wp_no_sceham_output_if_page_contact' );
13
  /**
14
  * Do not output schema default json-ld if this is the About page
15
  *
16
  * @since 1.5.2
17
  * @return schema json-ld array or an empy array
18
  */
19
- function schema_wp_no_sceham_output_if_page_contact( $schema ) {
20
 
21
  $contact_page_id = schema_wp_get_option( 'contact_page' );
22
 
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
 
12
+ add_filter( 'schema_output', 'schema_wp_no_schema_output_if_page_contact' );
13
  /**
14
  * Do not output schema default json-ld if this is the About page
15
  *
16
  * @since 1.5.2
17
  * @return schema json-ld array or an empy array
18
  */
19
+ function schema_wp_no_schema_output_if_page_contact( $schema ) {
20
 
21
  $contact_page_id = schema_wp_get_option( 'contact_page' );
22
 
includes/integrations/amp.php CHANGED
@@ -18,7 +18,18 @@ add_filter( 'amp_post_template_metadata', 'schema_wp_amp_modify_json_output', 10
18
  */
19
  function schema_wp_amp_modify_json_output( $metadata, $post ) {
20
 
21
- $json = schema_wp_get_jsonld( $post->ID );
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  if ( $json ) {
24
  return $json;
18
  */
19
  function schema_wp_amp_modify_json_output( $metadata, $post ) {
20
 
21
+ $about_page_id = schema_wp_get_option( 'about_page' );
22
+ $contact_page_id = schema_wp_get_option( 'contact_page' );
23
+
24
+ if ( isset($about_page_id) && $post->ID == $about_page_id ) {
25
+
26
+ $json = schema_wp_get_page_about_json( 'AboutPage' );
27
+ }
28
+
29
+ if ( isset($contact_page_id) && $post->ID == $contact_page_id) {
30
+
31
+ $json = schema_wp_get_page_contact_json( 'ContactPage' );
32
+ }
33
 
34
  if ( $json ) {
35
  return $json;
includes/integrations/yoast-seo.php CHANGED
@@ -78,7 +78,8 @@ function schema_wp_yoast_seo_settings_knowledge_graph( $settings_advanced ) {
78
  'desc' => __( 'Yes', 'schema-wp'),
79
  'type' => 'checkbox',
80
  'tooltip_title' => 'When disabled',
81
- 'tooltip_desc' => __('Schema plugin will override Yoast SEO output to avoid markup duplication.', 'schema-wp') . '<br /><br />' . __('These are the features that will be disabled:<br /><ol><li>Organization/Person</li><li>Social Profiles</li><li>Breadcrumb</li><li>Sitelink Search Box</li></ol>', 'schema-wp'),
 
82
  );
83
 
84
  return $settings_advanced;
78
  'desc' => __( 'Yes', 'schema-wp'),
79
  'type' => 'checkbox',
80
  'tooltip_title' => 'When disabled',
81
+ 'tooltip_desc' => __('Schema plugin will override Yoast SEO output to avoid markup duplication. Check this box if you would like to disable Schema markup and use Yoast SEO output instead.', 'schema-wp') . '<br /><br />' . __('Features that will be disabled:<br /><ol><li>Organization/Person</li><li>Social Profiles</li><li>Corporate Contacts
82
+ </li><li>Breadcrumb</li><li>Sitelink Search Box</li></ol>', 'schema-wp'),
83
  );
84
 
85
  return $settings_advanced;
includes/json/blog.php CHANGED
@@ -18,7 +18,9 @@ add_action('wp_head', 'schema_wp_output_blog');
18
  function schema_wp_output_blog() {
19
 
20
  // Run only on blog list page
21
- if ( ! is_front_page() && is_home() || is_home() ) {
 
 
22
 
23
  $json = schema_wp_get_blog_json( 'Blog' );
24
 
@@ -82,7 +84,7 @@ function schema_wp_get_blog_json( $type ) {
82
  (
83
  '@type' => 'BlogPosting',
84
  'headline' => wp_filter_nohtml_kses( get_the_title() ),
85
- //'description' => strip_shortcodes( get_the_excerpt($post->ID) ),
86
  'url' => get_the_permalink(),
87
  'sameAs' => schema_wp_get_sameAs($schema_post->ID),
88
  'datePublished' => get_the_date('c'),
18
  function schema_wp_output_blog() {
19
 
20
  // Run only on blog list page
21
+ //if ( ! is_front_page() && is_home() || is_home() ) {
22
+
23
+ if ( schema_wp_is_blog() ) {
24
 
25
  $json = schema_wp_get_blog_json( 'Blog' );
26
 
84
  (
85
  '@type' => 'BlogPosting',
86
  'headline' => wp_filter_nohtml_kses( get_the_title() ),
87
+ 'description' => schema_wp_get_description($schema_post->ID),
88
  'url' => get_the_permalink(),
89
  'sameAs' => schema_wp_get_sameAs($schema_post->ID),
90
  'datePublished' => get_the_date('c'),
includes/json/schema-output.php CHANGED
@@ -19,28 +19,18 @@ function schema_wp_output() {
19
 
20
  global $post;
21
 
22
- // do not run if default search query has been set (mostly not needed)
23
- // @todo remove this if not needed
24
- //if ( isset($_GET['s']) ) return;
25
-
26
  // do not run on front, home page, archive pages, search result pages, and 404 error pages
27
  if ( is_archive() || is_home() || is_front_page() || is_search() || is_404() ) return;
28
 
29
- // check for WPRichSnippets plugin
30
- // @since 1.4.5
31
- //if (function_exists('wprs_is_enabled')) {
32
- // if ( wprs_is_enabled( $post->ID ) ) return;
33
- //}
34
-
35
- $pttimestamp = time() + get_option('gmt_offset') * 60*60;
36
- $pttimestamp_old = get_post_meta( $post->ID, '_schema_json_timestamp', true );
37
- $json = array();
38
-
39
  // exclude entry, do not output the schema markup
40
  // @since 1.6
41
  $exclude = get_post_meta( $post->ID, '_schema_exclude' , true );
42
  if ( $exclude )
43
  return;
 
 
 
 
44
 
45
  // compare time stamp and check if json post meta value already exists
46
  // @since 1.5.9.7
@@ -49,14 +39,42 @@ function schema_wp_output() {
49
  if ( $time_diff <= DAY_IN_SECONDS ) {
50
  $json = get_post_meta( $post->ID, '_schema_json', true );
51
  } else {
52
- delete_post_meta( $post->ID, '_schema_json' );
53
- $json = array();
 
54
  }
55
- }
56
 
57
  if ( !isset($json) || empty($json) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- $schemas_enabled = array();
 
60
 
61
  // get Schema enabled array
62
  $schemas_enabled = schema_wp_cpt_get_enabled();
@@ -76,7 +94,7 @@ function schema_wp_output() {
76
  if ( ! empty($schema_cpt) && in_array( $post_type, $schema_cpt, true ) ) {
77
 
78
  // get enabled categories
79
- $categories = schema_wp_get_categories( $post->ID );
80
  $categories_enabled = $schema_enabled['categories'];
81
  // Get an array of common categories between the two arrays
82
  $categories_intersect = array_intersect($categories, $categories_enabled);
@@ -107,7 +125,6 @@ function schema_wp_output() {
107
  // } // end if
108
  //} // end foreach
109
 
110
-
111
  }
112
 
113
  }
@@ -116,28 +133,13 @@ function schema_wp_output() {
116
 
117
 
118
  // debug
119
- //print_r($schema_enabled);
120
 
121
  endforeach;
122
 
123
- } // end if
124
-
125
- $output = '';
126
-
127
- if ( ! empty($json) ) {
128
- $output .= "\n\n";
129
- $output .= '<!-- This site is optimized with the Schema plugin v'.SCHEMAWP_VERSION.' - https://schema.press -->';
130
- $output .= "\n";
131
- $output .= '<script type="application/ld+json">' . json_encode($json, JSON_UNESCAPED_UNICODE) .'</script>';
132
- $output .= "\n\n";
133
- }
134
-
135
- // update post meta with new generated json value and time stamp
136
- // @since 1.5.9.7
137
- update_post_meta( $post->ID, '_schema_json', $json );
138
- update_post_meta( $post->ID, '_schema_json_timestamp', $pttimestamp );
139
 
140
- echo $output;
141
  }
142
 
143
  /**
@@ -228,7 +230,7 @@ function schema_wp_get_schema_json_prepare( $post_id = null ) {
228
  // Set post ID
229
  If ( ! isset($post_id) ) $post_id = $post->ID;
230
 
231
- $jason = array();
232
 
233
 
234
  // Get post content
@@ -245,10 +247,14 @@ function schema_wp_get_schema_json_prepare( $post_id = null ) {
245
  // Get publisher array
246
  $publisher = schema_wp_get_publisher_array();
247
 
 
 
 
248
  //
249
  // Putting all together
250
  //
251
- $json["headline"] = apply_filters ( 'schema_wp_filter_headline', $content_post->post_title );
 
252
  $json['description'] = $description;
253
  $json['permalink'] = $permalink;
254
 
19
 
20
  global $post;
21
 
 
 
 
 
22
  // do not run on front, home page, archive pages, search result pages, and 404 error pages
23
  if ( is_archive() || is_home() || is_front_page() || is_search() || is_404() ) return;
24
 
 
 
 
 
 
 
 
 
 
 
25
  // exclude entry, do not output the schema markup
26
  // @since 1.6
27
  $exclude = get_post_meta( $post->ID, '_schema_exclude' , true );
28
  if ( $exclude )
29
  return;
30
+
31
+ $pttimestamp = time() + get_option('gmt_offset') * 60*60;
32
+ $pttimestamp_old = get_post_meta( $post->ID, '_schema_json_timestamp', true );
33
+ $json = array();
34
 
35
  // compare time stamp and check if json post meta value already exists
36
  // @since 1.5.9.7
39
  if ( $time_diff <= DAY_IN_SECONDS ) {
40
  $json = get_post_meta( $post->ID, '_schema_json', true );
41
  } else {
42
+ //delete_post_meta( $post->ID, '_schema_json' );
43
+ //$json = array();
44
+
45
  }
46
+ }
47
 
48
  if ( !isset($json) || empty($json) ) {
49
+ // get fresh schema
50
+ $json = schema_wp_get_enabled_json( $post->ID );
51
+ // update post meta with new generated json value and time stamp
52
+ // @since 1.5.9.7
53
+ update_post_meta( $post->ID, '_schema_json', $json );
54
+ update_post_meta( $post->ID, '_schema_json_timestamp', $pttimestamp );
55
+ }
56
+
57
+ if ( ! empty($json) ) {
58
+ $output = "\n\n";
59
+ $output .= '<!-- This site is optimized with the Schema plugin v'.SCHEMAWP_VERSION.' - https://schema.press -->';
60
+ $output .= "\n";
61
+ $output .= '<script type="application/ld+json">' . json_encode($json, JSON_UNESCAPED_UNICODE) .'</script>';
62
+ $output .= "\n\n";
63
+ echo $output;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Get enabled schema json-ld
69
+ *
70
+ * @since 1.7.1
71
+ * @param string $post_id post id
72
+ * @return array
73
+ */
74
+ function schema_wp_get_enabled_json( $post_id ) {
75
 
76
+ $json = array();
77
+ $schemas_enabled = array();
78
 
79
  // get Schema enabled array
80
  $schemas_enabled = schema_wp_cpt_get_enabled();
94
  if ( ! empty($schema_cpt) && in_array( $post_type, $schema_cpt, true ) ) {
95
 
96
  // get enabled categories
97
+ $categories = schema_wp_get_categories( $post_id );
98
  $categories_enabled = $schema_enabled['categories'];
99
  // Get an array of common categories between the two arrays
100
  $categories_intersect = array_intersect($categories, $categories_enabled);
125
  // } // end if
126
  //} // end foreach
127
 
 
128
  }
129
 
130
  }
133
 
134
 
135
  // debug
136
+ //echo'<pre>';print_r($schema_enabled);echo'</pre>';
137
 
138
  endforeach;
139
 
140
+ //echo'<pre>';print_r($json);echo'</pre>'; exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
+ return $json;
143
  }
144
 
145
  /**
230
  // Set post ID
231
  If ( ! isset($post_id) ) $post_id = $post->ID;
232
 
233
+ $json = array();
234
 
235
 
236
  // Get post content
247
  // Get publisher array
248
  $publisher = schema_wp_get_publisher_array();
249
 
250
+ // Truncate headline
251
+ $headline = schema_wp_get_truncate_to_word( $content_post->post_title );
252
+
253
  //
254
  // Putting all together
255
  //
256
+ $json["headline"] = apply_filters ( 'schema_wp_filter_headline', $headline );
257
+
258
  $json['description'] = $description;
259
  $json['permalink'] = $permalink;
260
 
includes/json/tag.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @since 1.6.9.5
6
  */
7
-
8
  // Exit if accessed directly
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
4
  *
5
  * @since 1.6.9.5
6
  */
7
+
8
  // Exit if accessed directly
9
  if ( ! defined( 'ABSPATH' ) ) exit;
10
 
includes/json/web-page-element.php CHANGED
@@ -136,11 +136,9 @@ function schema_wp_get_web_page_element_json() {
136
  $header = array(
137
  '@context' => 'http://schema.org/',
138
  '@type' => 'WPHeader',
139
- //'name' => get_bloginfo( 'name' ),
140
  'url' => $url,
141
  'headline' => wp_strip_all_tags($headline),
142
  'description' => wp_trim_words( wp_strip_all_tags($description), 18, '...' ),
143
- //'keywords' => schema_wp_get_categories_as_keywords(),
144
  );
145
 
146
  /*
@@ -149,15 +147,17 @@ function schema_wp_get_web_page_element_json() {
149
  $footer = array(
150
  '@context' => 'http://schema.org/',
151
  '@type' => 'WPFooter',
152
- //'name' => get_bloginfo( 'name' ),
153
  'url' => $url,
154
  'headline' => wp_strip_all_tags($headline),
155
  'description' => wp_trim_words( wp_strip_all_tags($description), 18, '...' ),
156
- //'keywords' => schema_wp_get_categories_as_keywords(),
157
- 'copyrightYear' => schema_wp_first_post_date( $format = 'Y' ),
158
- //'copyrightHolder' => schema_wp_get_knowledge_graph_json() // Organization or Person, @todo this didn't go well, it breaks Organization markup.
159
  );
160
 
 
 
 
 
 
 
161
  $page_element_output = array($header, $footer);
162
 
163
  // debug
136
  $header = array(
137
  '@context' => 'http://schema.org/',
138
  '@type' => 'WPHeader',
 
139
  'url' => $url,
140
  'headline' => wp_strip_all_tags($headline),
141
  'description' => wp_trim_words( wp_strip_all_tags($description), 18, '...' ),
 
142
  );
143
 
144
  /*
147
  $footer = array(
148
  '@context' => 'http://schema.org/',
149
  '@type' => 'WPFooter',
 
150
  'url' => $url,
151
  'headline' => wp_strip_all_tags($headline),
152
  'description' => wp_trim_words( wp_strip_all_tags($description), 18, '...' ),
 
 
 
153
  );
154
 
155
+ // Add copyrightYear to Footer singulars
156
+ // @since 1.7.1
157
+ if (is_singular() ) {
158
+ $footer['copyrightYear'] = get_the_date('Y');
159
+ }
160
+
161
  $page_element_output = array($header, $footer);
162
 
163
  // debug
includes/misc-functions.php CHANGED
@@ -50,7 +50,7 @@ function schema_wp_get_ref( $post_id = null ) {
50
 
51
  $schema_ref = get_post_meta( $post_id, '_schema_ref', true );
52
 
53
- If ( ! isset($schema_ref) ) $schema_ref = fasle;
54
 
55
  return apply_filters( 'schema_wp_ref', $schema_ref );
56
  }
@@ -100,7 +100,7 @@ function schema_wp_get_jsonld( $post_id = null ) {
100
 
101
  $schema_json = get_post_meta( $post_id, '_schema_json', true);
102
 
103
- If ( ! isset($schema_json )) $schema_json = fasle;
104
 
105
  return apply_filters( 'schema_wp_json', $schema_json );
106
  }
@@ -126,7 +126,7 @@ function schema_wp_get_publisher_array() {
126
 
127
  $publisher = array(
128
  "@type" => "Organization", // default required value
129
- "@id" => get_bloginfo("url") . "/#organization",
130
  "name" => wp_filter_nohtml_kses($name),
131
  "logo" => array(
132
  "@type" => "ImageObject",
@@ -835,31 +835,63 @@ function schema_wp_get_blog_posts_page_url() {
835
  }
836
 
837
  /**
838
- * Get First Post Date Function
839
  *
840
- * @since 1.6.9.8
841
- * @param $format Type of date format to return, using PHP date standard, default Y-m-d
842
- * @return Date of first post
843
  */
844
- function schema_wp_first_post_date( $format = 'Y-m-d' ) {
845
- // Setup get_posts arguments
846
- $ax_args = array(
847
- 'numberposts' => -1,
848
- 'post_status' => 'publish',
849
- 'order' => 'ASC'
850
- );
851
 
852
- // Get all posts in order of first to last
853
- $ax_get_all = get_posts($ax_args);
 
 
 
 
 
 
 
854
 
855
- // Extract first post from array
856
- $ax_first_post = $ax_get_all[0];
 
857
 
858
- // Assign first post date to var
859
- $ax_first_post_date = $ax_first_post->post_date;
860
 
861
- // return date in required format
862
- $output = date($format, strtotime($ax_first_post_date));
 
 
 
 
 
 
 
 
 
 
 
 
 
863
 
864
- return $output;
 
 
 
 
 
 
 
 
 
 
 
 
865
  }
50
 
51
  $schema_ref = get_post_meta( $post_id, '_schema_ref', true );
52
 
53
+ If ( ! isset($schema_ref) ) $schema_ref = false;
54
 
55
  return apply_filters( 'schema_wp_ref', $schema_ref );
56
  }
100
 
101
  $schema_json = get_post_meta( $post_id, '_schema_json', true);
102
 
103
+ If ( ! isset($schema_json )) $schema_json = false;
104
 
105
  return apply_filters( 'schema_wp_json', $schema_json );
106
  }
126
 
127
  $publisher = array(
128
  "@type" => "Organization", // default required value
129
+ "@id" => schema_wp_get_home_url() . "#organization",
130
  "name" => wp_filter_nohtml_kses($name),
131
  "logo" => array(
132
  "@type" => "ImageObject",
835
  }
836
 
837
  /**
838
+ * Retrieves the home URL
839
  *
840
+ * @since 1.7.1
841
+ * @return string
 
842
  */
843
+ function schema_wp_get_home_url( $path = '', $scheme = null ) {
844
+
845
+ $home_url = home_url( $path, $scheme );
846
+
847
+ if ( ! empty( $path ) ) {
848
+ return $home_url;
849
+ }
850
 
851
+ $home_path = wp_parse_url( $home_url, PHP_URL_PATH );
852
+
853
+ if ( '/' === $home_path ) { // Home at site root, already slashed.
854
+ return $home_url;
855
+ }
856
+
857
+ if ( is_null( $home_path ) ) { // Home at site root, always slash.
858
+ return trailingslashit( $home_url );
859
+ }
860
 
861
+ if ( is_string( $home_path ) ) { // Home in subdirectory, slash if permalink structure has slash.
862
+ return user_trailingslashit( $home_url );
863
+ }
864
 
865
+ return apply_filters( 'schema_wp_home_url', $home_url );
866
+ }
867
 
868
+ /**
869
+ * Check if is Blog page
870
+ *
871
+ * @since 1.7.1
872
+ * @return true or false
873
+ */
874
+ function schema_wp_is_blog() {
875
+
876
+ // Return true if is Blog (post list page)
877
+ if ( ! is_front_page() && is_home() || is_home() ) {
878
+ return true;
879
+ }
880
+
881
+ return false;
882
+ }
883
 
884
+ /**
885
+ * Truncate a string of content to 110 characters, respecting full words.
886
+ *
887
+ * @since 1.7.1
888
+ * @return string
889
+ */
890
+ function schema_wp_get_truncate_to_word( $value, $limit = 110, $end = '...' ) {
891
+
892
+ $limit = apply_filters( 'schema_wp_truncate_to_word_limit', $limit );
893
+ $limit = $limit - mb_strlen($end); // Take into account $end string into the limit
894
+ $valuelen = mb_strlen($value);
895
+
896
+ return $limit < $valuelen ? mb_substr($value, 0, mb_strrpos($value, ' ', $limit - $valuelen)) . $end : $value;
897
  }
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: hishaman, schemapress
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NGVUBT2QXN7YL
4
  Tags: schema, schema.org, json, json-ld, google, seo, structured data, markup, search engine, search, rich snippets, breadcrumbs, social, post, page, plugin, wordpress, content, article, news, search results, site name, knowledge graph, social, social profiles, keywords, meta-tags, metadata, tags, categories, optimize, ranking, search engine optimization, search engines, serp, sitelinks, google sitelinks, sitelinks search box, google sitelinks search box, semantic, structured, canonical, custom post types, post type, title, terms, media, images, thumb, featured, url, video, video markup, video object, VideoObject, video schema, audio object, AudioObject, audio schema, audio, sameAs, about, contact, amp, mobile, taxonomy
5
  Requires at least: 4.0
6
- Tested up to: 4.9.6
7
  Requires PHP: 5.4
8
- Stable tag: 1.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -156,6 +156,25 @@ Yes, Schema plugin will detect AMP plugin and output a more complete and valid s
156
 
157
  == Changelog ==
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  = 1.7 =
160
  * Fixed some typos and wording in the plugin settings.
161
  * Enhanced plugin settings usability by adding functionality for tooltips.
@@ -621,6 +640,9 @@ Yes, Schema plugin will detect AMP plugin and output a more complete and valid s
621
 
622
  == Upgrade Notice ==
623
 
 
 
 
624
  = 1.7 =
625
  In this release, we have introduced new settings page and step-by-step settings Configuration Wizard. Please, update the plugin on your website now to get fixes and enhancements.
626
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NGVUBT2QXN7YL
4
  Tags: schema, schema.org, json, json-ld, google, seo, structured data, markup, search engine, search, rich snippets, breadcrumbs, social, post, page, plugin, wordpress, content, article, news, search results, site name, knowledge graph, social, social profiles, keywords, meta-tags, metadata, tags, categories, optimize, ranking, search engine optimization, search engines, serp, sitelinks, google sitelinks, sitelinks search box, google sitelinks search box, semantic, structured, canonical, custom post types, post type, title, terms, media, images, thumb, featured, url, video, video markup, video object, VideoObject, video schema, audio object, AudioObject, audio schema, audio, sameAs, about, contact, amp, mobile, taxonomy
5
  Requires at least: 4.0
6
+ Tested up to: 4.9.7
7
  Requires PHP: 5.4
8
+ Stable tag: 1.7.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
156
 
157
  == Changelog ==
158
 
159
+ = 1.7.1 =
160
+ * Added new function schema_wp_post_meta_fields, stop loading post meta directly.
161
+ * Added new function schema_wp_is_blog, check if is Blog page.
162
+ * Added capability support for super admin.
163
+ * Added new function to truncate headlines to 110 characters per Google guidelines.
164
+ * Enhanced performance by saving json-ld post meta only if has new value.
165
+ * Enhanced some plugin settings description.
166
+ * Enhanced the way plugin check for the Blog page.
167
+ * Enhanced comments markup performance by checking comment number before query.
168
+ * Fixed bug in schema_output function, typo in variable name.
169
+ * Fixed home url when site is installed on its own subfolder.
170
+ * Fixed AMP integration, schema was not present due to empty meta value.
171
+ * Fixed copyrightYear markup in WPFooter, use post published year.
172
+ * Fixed use of undefined constant notice in misc function file.
173
+ * Fixed description markup in Blog page.
174
+ * Fixed a PHP notice when settings page sections variable not containing an array.
175
+ * Fixed admin menu item, hide the Schema Wizard empty menu item in dashboard.
176
+ * Updated the readme.txt file, and pumped the tested WP version to 4.9.7
177
+
178
  = 1.7 =
179
  * Fixed some typos and wording in the plugin settings.
180
  * Enhanced plugin settings usability by adding functionality for tooltips.
640
 
641
  == Upgrade Notice ==
642
 
643
+ = 1.7.1 =
644
+ In this release, several bug fixes and enhancements has been introduced. Please, update the plugin on your website now to get these fixes and enhancements.
645
+
646
  = 1.7 =
647
  In this release, we have introduced new settings page and step-by-step settings Configuration Wizard. Please, update the plugin on your website now to get fixes and enhancements.
648
 
schema.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: The next generation of Structured Data.
6
  * Author: Hesham
7
  * Author URI: http://zebida.com
8
- * Version: 1.7
9
  * Text Domain: schema-wp
10
  * Domain Path: languages
11
  *
@@ -51,7 +51,7 @@ final class Schema_WP {
51
  *
52
  * @since 1.0
53
  */
54
- private $version = '1.7';
55
 
56
  /**
57
  * The settings instance variable
@@ -222,6 +222,7 @@ final class Schema_WP {
222
  }
223
 
224
  require_once SCHEMAWP_PLUGIN_DIR . 'includes/misc-functions.php';
 
225
  require_once SCHEMAWP_PLUGIN_DIR . 'includes/scripts.php';
226
 
227
  // Schema outputs
5
  * Description: The next generation of Structured Data.
6
  * Author: Hesham
7
  * Author URI: http://zebida.com
8
+ * Version: 1.7.1
9
  * Text Domain: schema-wp
10
  * Domain Path: languages
11
  *
51
  *
52
  * @since 1.0
53
  */
54
+ private $version = '1.7.1';
55
 
56
  /**
57
  * The settings instance variable
222
  }
223
 
224
  require_once SCHEMAWP_PLUGIN_DIR . 'includes/misc-functions.php';
225
+ require_once SCHEMAWP_PLUGIN_DIR . 'includes/deprecated-functions.php';
226
  require_once SCHEMAWP_PLUGIN_DIR . 'includes/scripts.php';
227
 
228
  // Schema outputs