PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.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 / post / class-head.php

class-head.php in BeyondWords – AI audio for publishers 7.0.0, at src/post/class-head.php

113 lines 2.7 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\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 * @since 7.0.0 Refactored to BeyondWords namespace with snake_case methods.
15 */
16 defined( 'ABSPATH' ) || exit;
17
18 class Head {
19
20 /**
21 * Init.
22 *
23 * @since 6.0.0
24 * @since 7.0.0 Refactored to BeyondWords namespace with snake_case methods.
25 */
26 public static function init() {
27 add_action( 'wp_head', [ self::class, 'add_meta_tags'] );
28 }
29
30 /**
31 * Sets meta[beyondwords-*] tags in the head tag of singular pages.
32 *
33 * Magic Embed only: the tags are hints for the BeyondWords crawler/SDK. The
34 * REST API integration already sends these values in the content payload.
35 *
36 * @since 6.0.0
37 * @since 7.0.0 Refactored to BeyondWords namespace with snake_case methods.
38 * @since 7.0.0 Only emitted for the client-side (Magic Embed) integration.
39 *
40 * @return void
41 */
42 public static function add_meta_tags() {
43 if ( ! is_singular() ) {
44 return;
45 }
46
47 $post_id = get_queried_object_id();
48
49 if ( ! $post_id ) {
50 return;
51 }
52
53 $project_id = Meta::get_project_id( $post_id, true );
54
55 if ( ! $project_id ) {
56 return;
57 }
58
59 $post = get_post( $post_id );
60
61 if (
62 \BeyondWords\Settings\Fields::INTEGRATION_CLIENT_SIDE
63 !== \BeyondWords\Settings\Fields::get_integration_method( $post )
64 ) {
65 return;
66 }
67
68 $title = get_the_title( $post_id );
69
70 printf(
71 '<meta name="beyondwords-title" content="%s" data-beyondwords-title="%s" />' . "\n",
72 esc_attr( $title ),
73 esc_attr( $title )
74 );
75
76 $author_name = get_the_author_meta( 'display_name', get_post_field( 'post_author', $post_id ) );
77
78 printf(
79 '<meta name="beyondwords-author" content="%s" data-beyondwords-author="%s" />' . "\n",
80 esc_attr( $author_name ),
81 esc_attr( $author_name )
82 );
83
84 $publish_date = get_the_date( 'c', $post_id );
85
86 printf(
87 '<meta name="beyondwords-publish-date" content="%s" data-beyondwords-publish-date="%s" />' . "\n",
88 esc_attr( $publish_date ),
89 esc_attr( $publish_date )
90 );
91
92 $body_voice_id = get_post_meta( $post_id, 'beyondwords_body_voice_id', true );
93
94 if ( $body_voice_id ) {
95 printf(
96 '<meta name="beyondwords-body-voice-id" content="%d" data-beyondwords-body-voice-id="%d" />' . "\n",
97 esc_attr( $body_voice_id ),
98 esc_attr( $body_voice_id )
99 );
100 }
101
102 $language_code = get_post_meta( $post_id, 'beyondwords_language_code', true );
103
104 if ( $language_code ) {
105 printf(
106 '<meta name="beyondwords-article-language" content="%s" data-beyondwords-article-language="%s" />' . "\n", // phpcs:ignore Generic.Files.LineLength.TooLong
107 esc_attr( $language_code ),
108 esc_attr( $language_code )
109 );
110 }
111 }
112 }
113