Ultimate FAQ - Version 2.0.4

Version Description

(2021-04-12) = - Update to the structured data to make it so that, if you have multiple instances of the shortcode on the same page, it will combine the data from all of them and output only one FAQPage schema. - Fixes an issue with filtered FAQ content being displayed on archive pages.

Download this release

Release Info

Developer Rustaurius
Plugin Icon 128x128 Ultimate FAQ
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

Files changed (3) hide show
  1. readme.txt +4 -0
  2. ultimate-faqs.php +31 -1
  3. views/View.FAQs.class.php +4 -27
readme.txt CHANGED
@@ -264,6 +264,10 @@ Video 3 - FAQs Ordering
264
 
265
  == Changelog ==
266
 
 
 
 
 
267
  = 2.0.3 (2021-04-09) =
268
  - Disables group-by-category if there's only a single FAQ, which rectifies issue of duplicates showing on single post page.
269
 
264
 
265
  == Changelog ==
266
 
267
+ = 2.0.4 (2021-04-12) =
268
+ - Update to the structured data to make it so that, if you have multiple instances of the shortcode on the same page, it will combine the data from all of them and output only one FAQPage schema.
269
+ - Fixes an issue with filtered FAQ content being displayed on archive pages.
270
+
271
  = 2.0.3 (2021-04-09) =
272
  - Disables group-by-category if there's only a single FAQ, which rectifies issue of duplicates showing on single post page.
273
 
ultimate-faqs.php CHANGED
@@ -7,7 +7,7 @@ Author: Etoile Web Design
7
  Author URI: http://www.EtoileWebDesign.com/plugins/ultimate-faqs/
8
  Terms and Conditions: http://www.etoilewebdesign.com/plugin-terms-and-conditions/
9
  Text Domain: ultimate-faqs
10
- Version: 2.0.3
11
  */
12
 
13
  if ( ! defined( 'ABSPATH' ) )
@@ -16,6 +16,8 @@ if ( ! defined( 'ABSPATH' ) )
16
  if ( ! class_exists( 'ewdufaqInit' ) ) {
17
  class ewdufaqInit {
18
 
 
 
19
  /**
20
  * Initialize the plugin and register hooks
21
  */
@@ -132,6 +134,7 @@ class ewdufaqInit {
132
  add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
133
 
134
  add_filter( 'the_content', array( $this, 'alter_faq_content' ) );
 
135
 
136
  add_action( 'init', array( $this, 'load_view_files' ) );
137
 
@@ -308,11 +311,38 @@ class ewdufaqInit {
308
 
309
  if ( ! empty( $ewd_ufaq_controller->shortcode_printing ) ) { return $content; }
310
 
 
 
311
  $content = do_shortcode( '[select-faq faq_id="' . $post->ID . '"]' );
312
 
313
  return $content;
314
  }
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  /**
317
  * Adds in a menu bar for the plugin
318
  * @since 2.0.0
7
  Author URI: http://www.EtoileWebDesign.com/plugins/ultimate-faqs/
8
  Terms and Conditions: http://www.etoilewebdesign.com/plugin-terms-and-conditions/
9
  Text Domain: ultimate-faqs
10
+ Version: 2.0.4
11
  */
12
 
13
  if ( ! defined( 'ABSPATH' ) )
16
  if ( ! class_exists( 'ewdufaqInit' ) ) {
17
  class ewdufaqInit {
18
 
19
+ public $schema_faq_data = array();
20
+
21
  /**
22
  * Initialize the plugin and register hooks
23
  */
134
  add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
135
 
136
  add_filter( 'the_content', array( $this, 'alter_faq_content' ) );
137
+ add_action( 'wp_footer', array( $this, 'output_ld_json_content' ) );
138
 
139
  add_action( 'init', array( $this, 'load_view_files' ) );
140
 
311
 
312
  if ( ! empty( $ewd_ufaq_controller->shortcode_printing ) ) { return $content; }
313
 
314
+ if ( is_archive() ) { return $content; }
315
+
316
  $content = do_shortcode( '[select-faq faq_id="' . $post->ID . '"]' );
317
 
318
  return $content;
319
  }
320
 
321
+ /**
322
+ * Output any FAQ schema data, if enabled
323
+ *
324
+ * @since 2.0.0
325
+ */
326
+ public function output_ld_json_content() {
327
+ global $ewd_ufaq_controller;
328
+
329
+ if ( empty( $this->schema_faq_data ) ) { return; }
330
+
331
+ if ( $ewd_ufaq_controller->settings->get_setting( 'disable-microdata' ) ) { return; }
332
+
333
+ $ewd_ufaq_schema_data = array(
334
+ '@context' => 'https://schema.org',
335
+ '@type' => 'FAQPage',
336
+ 'mainEntity' => $this->schema_faq_data
337
+ );
338
+
339
+ $ld_json_ouptut = apply_filters( 'bpfwp_ld_json_output', $ewd_ufaq_schema_data );
340
+
341
+ echo '<script type="application/ld+json" class="ewd-ufaq-ld-json-data">';
342
+ echo wp_json_encode( $ld_json_ouptut );
343
+ echo '</script>';
344
+ }
345
+
346
  /**
347
  * Adds in a menu bar for the plugin
348
  * @since 2.0.0
views/View.FAQs.class.php CHANGED
@@ -25,17 +25,6 @@ class ewdufaqViewFAQs extends ewdufaqView {
25
  // Array containing IDs of categories to not display, empty if all should be displayed
26
  public $exclude_categories = array();
27
 
28
- /**
29
- * Initialize the class
30
- * @since 2.0.0
31
- */
32
- public function __construct( $args ) {
33
-
34
- parent::__construct( $args );
35
-
36
- add_action( 'wp_footer', array( $this, 'print_schema_data' ) );
37
- }
38
-
39
  /**
40
  * Define the the FAQs to be used
41
  *
@@ -71,6 +60,8 @@ class ewdufaqViewFAQs extends ewdufaqView {
71
 
72
  $this->create_faq_data();
73
 
 
 
74
  // Add any dependent stylesheets or javascript
75
  $this->enqueue_assets();
76
 
@@ -259,17 +250,11 @@ class ewdufaqViewFAQs extends ewdufaqView {
259
  *
260
  * @since 2.0.0
261
  */
262
- public function print_schema_data() {
263
  global $ewd_ufaq_controller;
264
 
265
  if ( $ewd_ufaq_controller->settings->get_setting( 'disable-microdata' ) ) { return; }
266
 
267
- $ewd_ufaq_schema_data = array(
268
- '@context' => "https://schema.org",
269
- '@type' => 'FAQPage',
270
- 'mainEntity' => array()
271
- );
272
-
273
  foreach ( $this->faqs as $faq ) {
274
 
275
  $schema_object = array(
@@ -290,16 +275,8 @@ class ewdufaqViewFAQs extends ewdufaqView {
290
  );
291
  }
292
 
293
- $ewd_ufaq_schema_data['mainEntity'][] = $schema_object;
294
  }
295
-
296
- ?>
297
-
298
- <script type="application/ld+json" class="ewd-ufaq-ld-json-data">
299
- <?php echo wp_json_encode( $ewd_ufaq_schema_data ); ?>
300
- </script>
301
-
302
- <?php
303
  }
304
 
305
  /**
25
  // Array containing IDs of categories to not display, empty if all should be displayed
26
  public $exclude_categories = array();
27
 
 
 
 
 
 
 
 
 
 
 
 
28
  /**
29
  * Define the the FAQs to be used
30
  *
60
 
61
  $this->create_faq_data();
62
 
63
+ $this->add_schema_data();
64
+
65
  // Add any dependent stylesheets or javascript
66
  $this->enqueue_assets();
67
 
250
  *
251
  * @since 2.0.0
252
  */
253
+ public function add_schema_data() {
254
  global $ewd_ufaq_controller;
255
 
256
  if ( $ewd_ufaq_controller->settings->get_setting( 'disable-microdata' ) ) { return; }
257
 
 
 
 
 
 
 
258
  foreach ( $this->faqs as $faq ) {
259
 
260
  $schema_object = array(
275
  );
276
  }
277
 
278
+ $ewd_ufaq_controller->schema_faq_data[] = $schema_object;
279
  }
 
 
 
 
 
 
 
 
280
  }
281
 
282
  /**