| @@ -1,35 +1,46 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. | |
| 2 | 3 | |
| 3 | -$faqs = betterdocs()->query->get_faq_by_term( $term->term_id ); | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | +$faq_taxonomy = isset( $term->taxonomy ) ? $term->taxonomy : 'betterdocs_faq_category'; | |
| 8 | +$faqs = betterdocs()->query->get_faq_by_term( $term->term_id, $faq_taxonomy ); | |
| 4 | 9 | |
| 5 | 10 | if ( $faqs->have_posts() ) { |
| 6 | - echo '<ul class="betterdocs-faq-list">'; | |
| 11 | + echo '<ul class="betterdocs-faq-list">'; | |
| 7 | 12 | |
| 8 | - $faq_markup = ''; | |
| 9 | - while ( $faqs->have_posts() ): $faqs->the_post(); | |
| 10 | - echo '<li>'; | |
| 11 | - echo '<div class="betterdocs-faq-group">'; | |
| 12 | - $view_object->get( 'shortcode-parts/faq-title' ); | |
| 13 | - $view_object->get( 'shortcode-parts/faq-content' ); | |
| 14 | - echo '</div>'; | |
| 15 | - echo '</li>'; | |
| 13 | + $faq_markup = ''; | |
| 14 | + while ( $faqs->have_posts() ) : | |
| 15 | + $faqs->the_post(); | |
| 16 | + $faq_toggle = (bool)get_post_meta(get_the_ID(), 'faq_open_by_default', true); | |
| 17 | + echo '<li>'; | |
| 18 | + echo '<div class="betterdocs-faq-group'.($faq_toggle ? ' active' : '').'">'; | |
| 19 | + $view_object->get( 'shortcode-parts/faq-title', [ | |
| 20 | + 'faq_toggle' => $faq_toggle | |
| 21 | + ] ); | |
| 22 | + $view_object->get( 'shortcode-parts/faq-content', [ | |
| 23 | + 'faq_toggle' => $faq_toggle | |
| 24 | + ] ); | |
| 25 | + echo '</div>'; | |
| 26 | + echo '</li>'; | |
| 16 | 27 | |
| 17 | - if ( $faq_schema ) { | |
| 18 | - $faq_json = [ | |
| 19 | - '@type' => 'Question', | |
| 20 | - 'name' => get_the_title(), | |
| 21 | - 'acceptedAnswer' => [ | |
| 22 | - '@type' => 'Answer', | |
| 23 | - 'text' => get_the_content() | |
| 24 | - ] | |
| 25 | - ]; | |
| 26 | - $GLOBALS['betterdocs_faq_schema_main_entity'][] = $faq_json; | |
| 27 | - } | |
| 28 | - endwhile; | |
| 29 | - wp_reset_postdata(); | |
| 30 | - wp_reset_query(); | |
| 31 | - echo $faq_markup; | |
| 32 | - echo '</ul>'; | |
| 28 | + if ( $faq_schema ) { | |
| 29 | + $faq_json = [ | |
| 30 | + '@type' => 'Question', | |
| 31 | + 'name' => get_the_title(), | |
| 32 | + 'acceptedAnswer' => [ | |
| 33 | + '@type' => 'Answer', | |
| 34 | + 'text' => get_the_content() | |
| 35 | + ] | |
| 36 | + ]; | |
| 37 | + $GLOBALS['betterdocs_faq_schema_main_entity'][] = $faq_json; | |
| 38 | + } | |
| 39 | + endwhile; | |
| 40 | + wp_reset_postdata(); | |
| 41 | + wp_reset_postdata(); | |
| 42 | + echo $faq_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 43 | + echo '</ul>'; | |
| 33 | 44 | } else { |
| 34 | - echo '<p>' . __( 'Sorry, no FAQ matched your criteria.', 'betterdocs' ) . '</p>'; | |
| 45 | + echo '<p>' . esc_html__( 'Sorry, no FAQ matched your criteria.', 'betterdocs' ) . '</p>'; | |
| 35 | 46 | } |