PluginProbe
BeyondWords – AI audio for publishers / 6.2.0
BeyondWords – AI audio for publishers v6.2.0
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.2.0, at src/Component/Post/Post.php

120 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 defined('ABSPATH') || exit;
16
17 class Post
18 {
19 /**
20 * Init.
21 *
22 * @since 6.0.0
23 */
24 public static function init()
25 {
26 add_action('wp_head', [self::class, 'addMetaTags']);
27 }
28
29 /**
30 * Sets meta[beyondwords-*] tags in the head tag of singular pages.
31 * We set both the [content] attribute and a custom data attribute for compatibility.
32 *
33 * @since 6.0.0
34 *
35 * @return void
36 */
37 public static function addMetaTags()
38 {
39 if (! is_singular()) {
40 return;
41 }
42
43 $postId = get_queried_object_id();
44
45 if (! $postId) {
46 return;
47 }
48
49 $projectId = PostMetaUtils::getProjectId($postId, true);
50
51 if (! $projectId) {
52 return;
53 }
54
55 $title = get_the_title($postId);
56
57 printf(
58 '<meta name="beyondwords-title" content="%s" data-beyondwords-title="%s" />' . "\n",
59 esc_attr($title),
60 esc_attr($title)
61 );
62
63 $authorName = get_the_author_meta('display_name', get_post_field('post_author', $postId));
64
65 printf(
66 '<meta name="beyondwords-author" content="%s" data-beyondwords-author="%s" />' . "\n",
67 esc_attr($authorName),
68 esc_attr($authorName)
69 );
70
71 $publishDate = get_the_date('c', $postId);
72
73 printf(
74 '<meta name="beyondwords-publish-date" content="%s" data-beyondwords-publish-date="%s" />' . "\n",
75 esc_attr($publishDate),
76 esc_attr($publishDate)
77 );
78
79 $titleVoiceId = get_post_meta($postId, 'beyondwords_title_voice_id', true);
80
81 if ($titleVoiceId) {
82 printf(
83 '<meta name="beyondwords-title-voice-id" content="%d" data-beyondwords-title-voice-id="%d" />' . "\n",
84 esc_attr($titleVoiceId),
85 esc_attr($titleVoiceId)
86 );
87 }
88
89 $bodyVoiceId = get_post_meta($postId, 'beyondwords_body_voice_id', true);
90
91 if ($bodyVoiceId) {
92 printf(
93 '<meta name="beyondwords-body-voice-id" content="%d" data-beyondwords-body-voice-id="%d" />' . "\n",
94 esc_attr($bodyVoiceId),
95 esc_attr($bodyVoiceId)
96 );
97 }
98
99 $summaryVoiceId = get_post_meta($postId, 'beyondwords_summary_voice_id', true);
100
101 if ($summaryVoiceId) {
102 printf(
103 '<meta name="beyondwords-summary-voice-id" content="%d" data-beyondwords-summary-voice-id="%d" />' . "\n", // phpcs:ignore Generic.Files.LineLength.TooLong
104 esc_attr($summaryVoiceId),
105 esc_attr($summaryVoiceId)
106 );
107 }
108
109 $languageCode = get_post_meta($postId, 'beyondwords_language_code', true);
110
111 if ($languageCode) {
112 printf(
113 '<meta name="beyondwords-article-language" content="%s" data-beyondwords-article-language="%s" />' . "\n", // phpcs:ignore Generic.Files.LineLength.TooLong
114 esc_attr($languageCode),
115 esc_attr($languageCode)
116 );
117 }
118 }
119 }
120