| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | use WPDeveloper\BetterDocs\Core\Shortcode; |
| 10 | +use WPDeveloper\BetterDocs\Utils\Helper; | |
| 10 | 11 | |
| 11 | 12 | class FaqList extends Shortcode { |
| 12 | 13 | protected $layout = 'modern'; |
| 13 | 14 | protected $icon_hook = 'betterdocs_faq_post_after'; |
| @@ -56,12 +57,24 @@ | ||
| 56 | 57 | 'faq_per_page' => 9, |
| 57 | 58 | 'show_button_icon' => true, |
| 58 | 59 | 'button_icon_position' => 'after', |
| 59 | 60 | 'button_color' => '#528ffe', |
| 60 | - 'is_gutenberg' => false | |
| 61 | + 'is_gutenberg' => false, | |
| 62 | + 'faq_taxonomy' => 'betterdocs_faq_category', | |
| 63 | + // Per-placement order override. Empty = use the global FAQ Builder | |
| 64 | + // order (`betterdocs_faq_order` option). One of: default, | |
| 65 | + // most_recent, least_recent, a_to_z, z_to_a, most_questions. | |
| 66 | + 'order' => '' | |
| 61 | 67 | ]; |
| 62 | 68 | } |
| 63 | 69 | |
| 70 | + /** | |
| 71 | + * Allowed per-placement order keys, mirroring the FAQ Builder header dropdown. | |
| 72 | + * | |
| 73 | + * @var string[] | |
| 74 | + */ | |
| 75 | + protected $allowed_order_keys = [ 'default', 'most_recent', 'least_recent', 'a_to_z', 'z_to_a', 'most_questions' ]; | |
| 76 | + | |
| 64 | 77 | public function icons( $faq_toggle ) { |
| 65 | 78 | $faq_markup = '<svg class="betterdocs-faq-iconminus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"' .($faq_toggle ? " style='display:inline;'" : ""). 'stroke-width="2"><g fill="none" stroke="' . esc_attr( $this->attributes['button_color'] ) . '" stroke-linecap="round" stroke-miterlimit="10" stroke-linejoin="round"><path d="M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>'; |
| 66 | 79 | $faq_markup .= '<svg class="betterdocs-faq-iconplus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"'.($faq_toggle ? " style='display:none;'" : "").'><g stroke-width="2" fill="none" stroke="' . esc_attr( $this->attributes['button_color'] ) . '" stroke-linecap="square" stroke-miterlimit="10"><path d="M12 7v10M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>'; |
| 67 | 80 | |
| @@ -79,15 +92,32 @@ | ||
| 79 | 92 | } else { |
| 80 | 93 | add_action( $this->icon_hook, [ $this, 'icons' ] ); |
| 81 | 94 | } |
| 82 | 95 | |
| 96 | + // When this placement sets a valid `order`, scope it to this render only | |
| 97 | + // (via the existing `betterdocs_faq_order_key` filter) so it overrides | |
| 98 | + // the global FAQ Builder order without affecting other placements. | |
| 99 | + $order_override = is_string( $this->attributes['order'] ) ? trim( $this->attributes['order'] ) : ''; | |
| 100 | + $order_filter = null; | |
| 101 | + if ( $order_override && in_array( $order_override, $this->allowed_order_keys, true ) ) { | |
| 102 | + $order_filter = function () use ( $order_override ) { | |
| 103 | + return $order_override; | |
| 104 | + }; | |
| 105 | + add_filter( 'betterdocs_faq_order_key', $order_filter, 20 ); | |
| 106 | + } | |
| 107 | + | |
| 83 | 108 | $this->views( 'shortcodes/faq' ); |
| 84 | 109 | |
| 110 | + if ( $order_filter ) { | |
| 111 | + remove_filter( 'betterdocs_faq_order_key', $order_filter, 20 ); | |
| 112 | + } | |
| 113 | + | |
| 85 | 114 | remove_action( $this->icon_hook, [ $this, 'icons' ] ); |
| 86 | 115 | } |
| 87 | 116 | |
| 88 | 117 | public function view_params() { |
| 89 | - $terms_query = $this->query->faq_terms_query_args( $this->attributes['groups'], $this->attributes['group_exclude'] ); | |
| 118 | + $taxonomy = sanitize_key( $this->attributes['faq_taxonomy'] ); | |
| 119 | + $terms_query = $this->query->faq_terms_query_args( $this->attributes['groups'], $this->attributes['group_exclude'], [], $taxonomy ); | |
| 90 | 120 | |
| 91 | 121 | $wrapper_attr = [ |
| 92 | 122 | 'class' => [ |
| 93 | 123 | 'betterdocs-faq-wrapper', |
| @@ -102,9 +132,9 @@ | ||
| 102 | 132 | 'wrapper_attr' => $wrapper_attr, |
| 103 | 133 | 'widget' => $this, |
| 104 | 134 | 'layout' => 'list', |
| 105 | 135 | 'terms_query_args' => $terms_query, |
| 106 | - 'faq_schema' => $this->attributes['faq_schema'] | |
| 136 | + 'faq_schema' => $this->attributes['faq_schema'] && ! Helper::seo_plugin_outputs_faq_schema() | |
| 107 | 137 | ] |
| 108 | 138 | ); |
| 109 | 139 | } |
| 110 | 140 | } |