Ultimate FAQ - Version 2.1.9

Version Description

(2022-02-01) = - Fixed compatibility issue when using block-based themes.

Download this release

Release Info

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

Code changes from version 2.1.8 to 2.1.9

assets/js/ewd-ufaq.js CHANGED
@@ -106,7 +106,7 @@ function UFAQSetAutoCompleteClickHandlers() {
106
 
107
  jQuery( '.ewd-ufaq-text-auto-complete' ).autocomplete({
108
 
109
- source: ewd_ufaq_php_data.question_titles,
110
  minLength: 3,
111
  appendTo: '#ewd-ufaq-jquery-ajax-search',
112
  select: function( event, ui ) {
@@ -125,7 +125,7 @@ function EWD_UFAQ_Reveal_FAQ( faq_element ) {
125
 
126
  var params = {};
127
 
128
- params.nonce = ewd_ufaq_php_data.nonce;
129
  params.post_id = post_id;
130
  params.action = 'ewd_ufaq_record_view';
131
 
@@ -235,13 +235,13 @@ function ewd_ufaq_ajax_reload( pagination, append_results, search_string ) {
235
 
236
  var retrieving_results = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.retrieving_results : 'Retrieving Results';
237
 
238
- jQuery( '.ewd-ufaq-faqs' ).html( '<h3>' + ewd_ufaq_php_data.retrieving_results + '</h3>' );
239
 
240
  var faqs_only = 'No';
241
  var faq_page = 0;
242
  }
243
 
244
- request_count = request_count + 1;
245
 
246
  if (show_on_load == 'No' && Question.length == 0) {jQuery('#ewd-ufaq-ajax-results').html(''); return;}
247
 
@@ -258,7 +258,7 @@ function ewd_ufaq_ajax_reload( pagination, append_results, search_string ) {
258
  params.faqs_only = faqs_only;
259
  params.faq_page = faq_page;
260
  params.action = 'ewd_ufaq_search';
261
- params.nonce = ewd_ufaq_php_data.nonce;
262
 
263
  var data = jQuery.param( params );
264
 
@@ -302,7 +302,7 @@ function UFAQSetRatingHandlers() {
302
  var params = {};
303
 
304
  params.action = 'ewd_ufaq_update_rating'
305
- params.nonce = ewd_ufaq_php_data.nonce;
306
  params.faq_id = faq_id;
307
  params.vote_type = vote_type;
308
 
@@ -315,7 +315,7 @@ function UFAQSetExpandCollapseHandlers() {
315
 
316
  jQuery('.ewd-ufaq-expand-all').off('click').on('click', function() {
317
 
318
- var accordion_setting = ewd_ufaq_php_data.faq_accordion;
319
  ewd_ufaq_php_data.faq_accordion = false; // turn FAQ accordion off while expanding all
320
 
321
  jQuery( '.ewd-ufaq-faq-toggle' ).each( function() {
@@ -327,7 +327,7 @@ function UFAQSetExpandCollapseHandlers() {
327
  EWD_UFAQ_Reveal_FAQ( faq );
328
  });
329
 
330
- ewd_ufaq_php_data.faq_accordion = accordion_setting; //reset FAQ accordion setting
331
 
332
  jQuery('.ewd-ufaq-faq-category-inner').removeClass('ewd-ufaq-faq-category-body-hidden');
333
  jQuery('.ewd-ufaq-collapse-all').removeClass('ewd-ufaq-hidden');
106
 
107
  jQuery( '.ewd-ufaq-text-auto-complete' ).autocomplete({
108
 
109
+ source: typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.question_titles : '',
110
  minLength: 3,
111
  appendTo: '#ewd-ufaq-jquery-ajax-search',
112
  select: function( event, ui ) {
125
 
126
  var params = {};
127
 
128
+ params.nonce = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.nonce : '';
129
  params.post_id = post_id;
130
  params.action = 'ewd_ufaq_record_view';
131
 
235
 
236
  var retrieving_results = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.retrieving_results : 'Retrieving Results';
237
 
238
+ jQuery( '.ewd-ufaq-faqs' ).html( '<h3>' + retrieving_results + '</h3>' );
239
 
240
  var faqs_only = 'No';
241
  var faq_page = 0;
242
  }
243
 
244
+ request_count = request_count + 1;
245
 
246
  if (show_on_load == 'No' && Question.length == 0) {jQuery('#ewd-ufaq-ajax-results').html(''); return;}
247
 
258
  params.faqs_only = faqs_only;
259
  params.faq_page = faq_page;
260
  params.action = 'ewd_ufaq_search';
261
+ params.nonce = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.nonce : '';
262
 
263
  var data = jQuery.param( params );
264
 
302
  var params = {};
303
 
304
  params.action = 'ewd_ufaq_update_rating'
305
+ params.nonce = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.nonce : '';
306
  params.faq_id = faq_id;
307
  params.vote_type = vote_type;
308
 
315
 
316
  jQuery('.ewd-ufaq-expand-all').off('click').on('click', function() {
317
 
318
+ var accordion_setting = typeof ewd_ufaq_php_data != 'undefined' ? ewd_ufaq_php_data.faq_accordion : false;
319
  ewd_ufaq_php_data.faq_accordion = false; // turn FAQ accordion off while expanding all
320
 
321
  jQuery( '.ewd-ufaq-faq-toggle' ).each( function() {
327
  EWD_UFAQ_Reveal_FAQ( faq );
328
  });
329
 
330
+ if ( typeof ewd_ufaq_php_data != 'undefined' ) { ewd_ufaq_php_data.faq_accordion = accordion_setting; } //reset FAQ accordion setting
331
 
332
  jQuery('.ewd-ufaq-faq-category-inner').removeClass('ewd-ufaq-faq-category-body-hidden');
333
  jQuery('.ewd-ufaq-collapse-all').removeClass('ewd-ufaq-hidden');
includes/Helper.class.php CHANGED
@@ -60,6 +60,35 @@ class ewdufaqHelper {
60
  )
61
  );
62
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
 
65
  }
60
  )
61
  );
62
  }
63
+
64
+ /**
65
+ * Escapes PHP data being passed to JS, recursively
66
+ * @since 2.1.0
67
+ */
68
+ public static function escape_js_recursive( $values ) {
69
+
70
+ $return_values = array();
71
+
72
+ foreach ( (array) $values as $key => $value ) {
73
+
74
+ if ( is_array( $value ) ) {
75
+
76
+ $value = ewdufaqHelper::escape_js_recursive( $value );
77
+ }
78
+ elseif ( ! is_scalar( $value ) ) {
79
+
80
+ continue;
81
+ }
82
+ else {
83
+
84
+ $value = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
85
+ }
86
+
87
+ $return_values[ $key ] = $value;
88
+ }
89
+
90
+ return $return_values;
91
+ }
92
  }
93
 
94
  }
includes/WPForms.class.php CHANGED
@@ -89,18 +89,17 @@ if ( !class_exists( 'ewdufaqWPForms' ) ) {
89
  * @since 2.0.0
90
  */
91
  public function js_localization( $form_data, $form ) {
 
92
 
93
  $target_field = $this->get_target_field( $form_data );
94
 
95
- wp_localize_script(
96
- 'ewd-ufaq-js',
97
- 'wpforms_integration',
98
- array(
99
- 'ufaq_enabled' => isset ( $form_data['settings']['ufaq_enabled'] ) ? $form_data['settings']['ufaq_enabled'] : 'enabled',
100
- 'ufaq_selected_field' => $target_field,
101
- 'form_id' => $form_data['id']
102
- )
103
  );
 
 
104
  }
105
 
106
  public function enqueue_scripts() {
89
  * @since 2.0.0
90
  */
91
  public function js_localization( $form_data, $form ) {
92
+ global $ewd_ufaq_controller;
93
 
94
  $target_field = $this->get_target_field( $form_data );
95
 
96
+ $args = array(
97
+ 'ufaq_enabled' => isset ( $form_data['settings']['ufaq_enabled'] ) ? $form_data['settings']['ufaq_enabled'] : 'enabled',
98
+ 'ufaq_selected_field' => $target_field,
99
+ 'form_id' => $form_data['id']
 
 
 
 
100
  );
101
+
102
+ $ewd_ufaq_controller->add_front_end_php_data( 'ewd-ufaq-js', 'wpforms_integration', $args );
103
  }
104
 
105
  public function enqueue_scripts() {
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Rustaurius, EtoileWebDesign
3
  Tags: faq, faqs, accordion, woocommerce faq, gutenberg faq, faq block
4
  Requires at least: 5.0
5
- Tested up to: 5.8
6
- Stable tag: 2.1.8
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -267,6 +267,9 @@ Video 3 - FAQs Ordering
267
 
268
  == Changelog ==
269
 
 
 
 
270
  = 2.1.8 (2022-01-26) =
271
  - Updated escaping function to correct issue with the widget output.
272
 
2
  Contributors: Rustaurius, EtoileWebDesign
3
  Tags: faq, faqs, accordion, woocommerce faq, gutenberg faq, faq block
4
  Requires at least: 5.0
5
+ Tested up to: 5.9
6
+ Stable tag: 2.1.9
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
267
 
268
  == Changelog ==
269
 
270
+ = 2.1.9 (2022-02-01) =
271
+ - Fixed compatibility issue when using block-based themes.
272
+
273
  = 2.1.8 (2022-01-26) =
274
  - Updated escaping function to correct issue with the widget output.
275
 
ultimate-faqs.php CHANGED
@@ -6,7 +6,7 @@ Description: FAQ and accordion plugin with easy to use Gutenberg blocks, shortco
6
  Author URI: https://www.etoilewebdesign.com/
7
  Terms and Conditions: https://www.etoilewebdesign.com/plugin-terms-and-conditions/
8
  Text Domain: ultimate-faqs
9
- Version: 2.1.8
10
  WC requires at least: 3.0
11
  WC tested up to: 6.1
12
  */
@@ -43,7 +43,7 @@ class ewdufaqInit {
43
  define( 'EWD_UFAQ_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
44
  define( 'EWD_UFAQ_PLUGIN_FNAME', plugin_basename( __FILE__ ) );
45
  define( 'EWD_UFAQ_TEMPLATE_DIR', 'ewd-ufaq-templates' );
46
- define( 'EWD_UFAQ_VERSION', '2.1.8' );
47
 
48
  define( 'EWD_UFAQ_FAQ_POST_TYPE', 'ufaq' );
49
  define( 'EWD_UFAQ_FAQ_CATEGORY_TAXONOMY', 'ufaq-category' );
@@ -128,27 +128,28 @@ class ewdufaqInit {
128
  register_activation_hook( __FILE__, array( $this, 'run_walkthrough' ) );
129
  register_activation_hook( __FILE__, array( $this, 'convert_options' ) );
130
 
131
- add_filter( 'ewd_ufaq_admin_menu', array( $this, 'admin_menu_optional' ) );
132
 
133
- add_filter( 'init', array( $this, 'rewrite_rules' ) );
134
- add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
135
- add_filter( 'redirect_canonical', array( $this, 'disable_canonical_redirect_for_front_page' ) );
136
 
137
- add_filter( 'the_content', array( $this, 'alter_faq_content' ) );
138
- add_action( 'wp_footer', array( $this, 'output_ld_json_content' ) );
139
 
140
- add_action( 'init', array( $this, 'load_view_files' ) );
141
 
142
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
143
 
144
- add_action( 'admin_notices', array( $this, 'display_header_area' ) );
145
- add_action( 'admin_notices', array( $this, 'maybe_display_helper_notice' ) );
146
 
147
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ), 10, 1 );
148
- add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
149
- add_action( 'wp_head', 'ewd_add_frontend_ajax_url' );
 
150
 
151
- add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2);
152
 
153
  add_action( 'wp_ajax_ewd_ufaq_hide_helper_notice', array( $this, 'hide_helper_notice' ) );
154
  }
@@ -322,7 +323,7 @@ class ewdufaqInit {
322
  * Register the front-end CSS and Javascript for the FAQs
323
  * @since 2.0.0
324
  */
325
- function register_assets() {
326
  global $ewd_ufaq_controller;
327
 
328
  wp_register_style( 'ewd-ufaq-rrssb', EWD_UFAQ_PLUGIN_URL . '/assets/css/rrssb-min.css', EWD_UFAQ_VERSION );
@@ -333,6 +334,51 @@ class ewdufaqInit {
333
  wp_register_script( 'ewd-ufaq-js', EWD_UFAQ_PLUGIN_URL . '/assets/js/ewd-ufaq.js', array( 'jquery', 'jquery-ui-core' ), EWD_UFAQ_VERSION, true );
334
  }
335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  /**
337
  * Add links to the plugin listing on the installed plugins page
338
  * @since 2.0.0
6
  Author URI: https://www.etoilewebdesign.com/
7
  Terms and Conditions: https://www.etoilewebdesign.com/plugin-terms-and-conditions/
8
  Text Domain: ultimate-faqs
9
+ Version: 2.1.9
10
  WC requires at least: 3.0
11
  WC tested up to: 6.1
12
  */
43
  define( 'EWD_UFAQ_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
44
  define( 'EWD_UFAQ_PLUGIN_FNAME', plugin_basename( __FILE__ ) );
45
  define( 'EWD_UFAQ_TEMPLATE_DIR', 'ewd-ufaq-templates' );
46
+ define( 'EWD_UFAQ_VERSION', '2.1.9' );
47
 
48
  define( 'EWD_UFAQ_FAQ_POST_TYPE', 'ufaq' );
49
  define( 'EWD_UFAQ_FAQ_CATEGORY_TAXONOMY', 'ufaq-category' );
128
  register_activation_hook( __FILE__, array( $this, 'run_walkthrough' ) );
129
  register_activation_hook( __FILE__, array( $this, 'convert_options' ) );
130
 
131
+ add_filter( 'ewd_ufaq_admin_menu', array( $this, 'admin_menu_optional' ) );
132
 
133
+ add_filter( 'init', array( $this, 'rewrite_rules' ) );
134
+ add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
135
+ add_filter( 'redirect_canonical', array( $this, 'disable_canonical_redirect_for_front_page' ) );
136
 
137
+ add_filter( 'the_content', array( $this, 'alter_faq_content' ) );
138
+ add_action( 'wp_footer', array( $this, 'output_ld_json_content' ) );
139
 
140
+ add_action( 'init', array( $this, 'load_view_files' ) );
141
 
142
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
143
 
144
+ add_action( 'admin_notices', array( $this, 'display_header_area' ) );
145
+ add_action( 'admin_notices', array( $this, 'maybe_display_helper_notice' ) );
146
 
147
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ), 10, 1 );
148
+ add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
149
+ add_action( 'wp_head', 'ewd_add_frontend_ajax_url' );
150
+ add_action( 'wp_footer', array( $this, 'assets_footer' ), 2 );
151
 
152
+ add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2);
153
 
154
  add_action( 'wp_ajax_ewd_ufaq_hide_helper_notice', array( $this, 'hide_helper_notice' ) );
155
  }
323
  * Register the front-end CSS and Javascript for the FAQs
324
  * @since 2.0.0
325
  */
326
+ public function register_assets() {
327
  global $ewd_ufaq_controller;
328
 
329
  wp_register_style( 'ewd-ufaq-rrssb', EWD_UFAQ_PLUGIN_URL . '/assets/css/rrssb-min.css', EWD_UFAQ_VERSION );
334
  wp_register_script( 'ewd-ufaq-js', EWD_UFAQ_PLUGIN_URL . '/assets/js/ewd-ufaq.js', array( 'jquery', 'jquery-ui-core' ), EWD_UFAQ_VERSION, true );
335
  }
336
 
337
+ /**
338
+ * Print out any PHP data needed for our JS to work correctly
339
+ * @since 2.1.0
340
+ */
341
+ public function assets_footer() {
342
+
343
+ if ( empty( $this->front_end_php_js_data ) ) { return; }
344
+
345
+ $print_variables = array();
346
+
347
+ foreach ( (array) $this->front_end_php_js_data as $variable => $values ) {
348
+
349
+ if ( empty( $values ) ) { continue; }
350
+
351
+ $print_variables[ $variable ] = ewdufaqHelper::escape_js_recursive( $values );
352
+ }
353
+
354
+ foreach ( $print_variables as $variable => $values ) {
355
+
356
+ echo "<script type='text/javascript'>\n";
357
+ echo "/* <![CDATA[ */\n";
358
+ echo 'var ' . esc_attr( $variable ) . ' = ' . wp_json_encode( $values ) . "\n";
359
+ echo "/* ]]> */\n";
360
+ echo "</script>\n";
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Adds a variable to be passed to our front-end JS
366
+ * @since 2.1.0
367
+ */
368
+ public function add_front_end_php_data( $handle, $variable, $data ) {
369
+
370
+ $this->front_end_php_js_data[ $variable ] = $data;
371
+ }
372
+
373
+ /**
374
+ * Returns the corresponding front-end JS variable if it exists, otherwise an empty array
375
+ * @since 2.1.0
376
+ */
377
+ public function get_front_end_php_data( $handle, $variable ) {
378
+
379
+ return ! empty( $this->front_end_php_js_data[ $variable ] ) ? $this->front_end_php_js_data[ $variable ] : array();
380
+ }
381
+
382
  /**
383
  * Add links to the plugin listing on the installed plugins page
384
  * @since 2.0.0
views/View.FAQs.class.php CHANGED
@@ -547,22 +547,19 @@ class ewdufaqViewFAQs extends ewdufaqView {
547
  }
548
 
549
  // Fetch any existing script data
550
- $prev_question_titles = $wp_scripts->get_data( $handle, 'question_titles' );
551
 
552
  if ( ! empty( $prev_question_titles ) ) {
553
  $args['question_titles'] = array_merge( $prev_question_titles, $args['question_titles'] );
554
  $args['question_titles'] = array_unique( $args['question_titles'] );
555
  }
556
 
557
- $wp_scripts->add_data( $handle, 'question_titles', $args['question_titles'] );
558
- wp_localize_script(
559
- $handle,
560
- 'ewd_ufaq_php_data',
561
- apply_filters( 'ewd_ufaq_js_localize_data', $args )
562
- );
563
 
564
  wp_enqueue_script( $handle );
565
 
 
 
566
  wp_enqueue_script( 'jquery-ui-core' );
567
 
568
  if ( $ewd_ufaq_controller->settings->get_setting( 'auto-complete-titles' ) ) {
547
  }
548
 
549
  // Fetch any existing script data
550
+ $prev_question_titles = $ewd_ufaq_controller->get_front_end_php_data( $handle, 'question_titles' );
551
 
552
  if ( ! empty( $prev_question_titles ) ) {
553
  $args['question_titles'] = array_merge( $prev_question_titles, $args['question_titles'] );
554
  $args['question_titles'] = array_unique( $args['question_titles'] );
555
  }
556
 
557
+ $ewd_ufaq_controller->add_front_end_php_data( $handle, 'question_titles', $args['question_titles'] );
 
 
 
 
 
558
 
559
  wp_enqueue_script( $handle );
560
 
561
+ $ewd_ufaq_controller->add_front_end_php_data( $handle, 'ewd_ufaq_php_data', apply_filters( 'ewd_ufaq_js_localize_data', $args ) );
562
+
563
  wp_enqueue_script( 'jquery-ui-core' );
564
 
565
  if ( $ewd_ufaq_controller->settings->get_setting( 'auto-complete-titles' ) ) {