PluginProbe
BeyondWords – AI audio for publishers / 6.0.3
BeyondWords – AI audio for publishers v6.0.3
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Post / Post.php

Post.php in BeyondWords – AI audio for publishers 6.0.3, at src/Component/Post/Post.php

118 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Beyondwords\Wordpress\Component\Post;
6
7 /**
8 * General Post class.
9 *
10 * @package Beyondwords
11 * @subpackage Beyondwords/includes
12 * @author Stuart McAlpine <stu@beyondwords.io>
13 * @since 6.0.0
14 */
15 class Post
16 {
17 /**
18 * Init.
19 *
20 * @since 6.0.0
21 */
22 public static function init()
23 {
24 add_action('wp_head', [self::class, 'addMetaTags']);
25 }
26
27 /**
28 * Sets meta[beyondwords-*] tags in the head tag of singular pages.
29 * We set both the [content] attribute and a custom data attribute for compatibility.
30 *
31 * @since 6.0.0
32 *
33 * @return void
34 */
35 public static function addMetaTags()
36 {
37 if (! is_singular()) {
38 return;
39 }
40
41 $postId = get_queried_object_id();
42
43 if (! $postId) {
44 return;
45 }
46
47 $projectId = PostMetaUtils::getProjectId($postId, true);
48
49 if (! $projectId) {
50 return;
51 }
52
53 $title = get_the_title($postId);
54
55 printf(
56 '<meta name="beyondwords-title" content="%s" data-beyondwords-title="%s" />' . "\n",
57 esc_attr($title),
58 esc_attr($title)
59 );
60
61 $authorName = get_the_author_meta('display_name', get_post_field('post_author', $postId));
62
63 printf(
64 '<meta name="beyondwords-author" content="%s" data-beyondwords-author="%s" />' . "\n",
65 esc_attr($authorName),
66 esc_attr($authorName)
67 );
68
69 $publishDate = get_the_date('c', $postId);
70
71 printf(
72 '<meta name="beyondwords-publish-date" content="%s" data-beyondwords-publish-date="%s" />' . "\n",
73 esc_attr($publishDate),
74 esc_attr($publishDate)
75 );
76
77 $titleVoiceId = get_post_meta($postId, 'beyondwords_title_voice_id', true);
78
79 if ($titleVoiceId) {
80 printf(
81 '<meta name="beyondwords-title-voice-id" content="%d" data-beyondwords-title-voice-id="%d" />' . "\n",
82 esc_attr($titleVoiceId),
83 esc_attr($titleVoiceId)
84 );
85 }
86
87 $bodyVoiceId = get_post_meta($postId, 'beyondwords_body_voice_id', true);
88
89 if ($bodyVoiceId) {
90 printf(
91 '<meta name="beyondwords-body-voice-id" content="%d" data-beyondwords-body-voice-id="%d" />' . "\n",
92 esc_attr($bodyVoiceId),
93 esc_attr($bodyVoiceId)
94 );
95 }
96
97 $summaryVoiceId = get_post_meta($postId, 'beyondwords_summary_voice_id', true);
98
99 if ($summaryVoiceId) {
100 printf(
101 '<meta name="beyondwords-summary-voice-id" content="%d" data-beyondwords-summary-voice-id="%d" />' . "\n", // phpcs:ignore Generic.Files.LineLength.TooLong
102 esc_attr($summaryVoiceId),
103 esc_attr($summaryVoiceId)
104 );
105 }
106
107 $languageCode = get_post_meta($postId, 'beyondwords_language_code', true);
108
109 if ($languageCode) {
110 printf(
111 '<meta name="beyondwords-article-language" content="%s" data-beyondwords-article-language="%s" />' . "\n", // phpcs:ignore Generic.Files.LineLength.TooLong
112 esc_attr($languageCode),
113 esc_attr($languageCode)
114 );
115 }
116 }
117 }
118