|
1 | 1 | <?php |
2 | | -/** |
3 | | - * Ammends the FAQ field to a PDC item. |
4 | | - */ |
| 2 | + |
5 | 3 | namespace OWC\PDC\FAQ\RestAPI; |
6 | 4 |
|
7 | 5 | use OWC\PDC\Base\Support\CreatesFields; |
|
12 | 10 | */ |
13 | 11 | class FAQField extends CreatesFields |
14 | 12 | { |
15 | | - |
16 | 13 | /** |
17 | 14 | * Create an additional field on an array. |
18 | | - * |
19 | | - * @param WP_Post $post |
20 | | - * |
21 | | - * @return array |
22 | 15 | */ |
23 | 16 | public function create(WP_Post $post): array |
24 | 17 | { |
25 | 18 | return array_map(function ($faq) { |
26 | 19 | return [ |
27 | 20 | 'question' => $faq['pdc_faq_question'] ?: '', |
28 | | - 'answer' => isset($faq['pdc_faq_answer']) ? apply_filters('the_content', $faq['pdc_faq_answer']) : '' |
| 21 | + 'answer' => ! empty($faq['pdc_faq_answer']) ? \apply_filters('the_content', $this->filterContent($faq['pdc_faq_answer'])) : '' |
29 | 22 | ]; |
30 | 23 | }, $this->getFAQ($post)); |
31 | 24 | } |
32 | 25 |
|
33 | 26 | /** |
34 | 27 | * Get faqs of a post. |
35 | | - * |
36 | | - * @param WP_Post $post |
37 | | - * |
38 | | - * @return array |
39 | 28 | */ |
40 | | - private function getFAQ(WP_Post $post) |
| 29 | + private function getFAQ(WP_Post $post): array |
41 | 30 | { |
42 | | - return array_filter(get_post_meta($post->ID, '_owc_pdc_faq_group', true) ?: [], function ($faq) { |
| 31 | + return array_filter(\get_post_meta($post->ID, '_owc_pdc_faq_group', true) ?: [], function ($faq) { |
43 | 32 | return ! empty($faq['pdc_faq_question']) && ! empty($faq['pdc_faq_answer']); |
44 | 33 | }); |
45 | 34 | } |
| 35 | + |
| 36 | + /** |
| 37 | + * Add no cookie to YouTube URL. |
| 38 | + * Disable YouTube oembed. |
| 39 | + * Remove no cookie from YouTube channel url. |
| 40 | + */ |
| 41 | + protected function filterContent(string $content): string |
| 42 | + { |
| 43 | + $content = str_replace('youtube.com', 'youtube-nocookie.com', $content); |
| 44 | + $content = str_replace('?feature=oembed', '?feature=oembed&disablekb=1', $content); |
| 45 | + $content = str_replace('youtube-nocookie.com/channel', 'youtube.com/channel', $content); |
| 46 | + |
| 47 | + return $content; |
| 48 | + } |
46 | 49 | } |
0 commit comments