PluginProbe
BeyondWords – AI audio for publishers / 6.3.0
BeyondWords – AI audio for publishers v6.3.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 / Core / Player / Renderer / Amp.php

Amp.php in BeyondWords – AI audio for publishers 6.3.0, at src/Core/Player/Renderer/Amp.php

72 lines 1.9 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\Core\Player\Renderer;
6
7 use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
8 use Beyondwords\Wordpress\Core\CoreUtils;
9 use Beyondwords\Wordpress\Core\Environment;
10
11 /**
12 * Class Amp
13 *
14 * Renders the AMP-compatible BeyondWords player.
15 */
16 defined('ABSPATH') || exit;
17
18 class Amp extends Base
19 {
20 /**
21 * Check whether we should use the AMP player for the current post.
22 *
23 * @param \WP_Post $post WordPress post object.
24 *
25 * @return bool True if AMP player should be used.
26 */
27 public static function check(\WP_Post $post): bool
28 {
29 if (! CoreUtils::isAmp()) {
30 return false;
31 }
32
33 return parent::check($post);
34 }
35
36 /**
37 * Render AMP player HTML.
38 *
39 *
40 * @return string HTML markup for AMP player.
41 */
42 public static function render(\WP_Post $post, string $context = 'shortcode'): string
43 {
44 $projectId = PostMetaUtils::getProjectId($post->ID);
45 $contentId = PostMetaUtils::getContentId($post->ID, true); // Fallback to Post ID if Content ID is not set
46
47 $src = sprintf(Environment::getAmpPlayerUrl(), $projectId, $contentId);
48
49 ob_start();
50 ?>
51 <amp-iframe
52 data-beyondwords-player-context="<?php echo esc_attr($context); ?>"
53 frameborder="0"
54 height="43"
55 layout="responsive"
56 sandbox="allow-scripts allow-same-origin allow-popups"
57 scrolling="no"
58 src="<?php echo esc_url($src); ?>"
59 width="295"
60 >
61 <amp-img
62 height="150"
63 layout="responsive"
64 placeholder
65 src="<?php echo esc_url(Environment::getAmpImgUrl()); ?>"
66 width="643"
67 ></amp-img>
68 </amp-iframe>
69 <?php
70 return ob_get_clean();
71 }
72 }