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 / player / renderer / class-amp.php

class-amp.php in BeyondWords – AI audio for publishers 7.0.0, at src/player/renderer/class-amp.php

72 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AMP-compatible BeyondWords player renderer.
4 *
5 * @package BeyondWords\Player\Renderer
6 * @since 6.0.0
7 * @since 7.0.0 Refactored to BeyondWords namespace with snake_case methods.
8 */
9
10 declare( strict_types = 1 );
11
12 namespace BeyondWords\Player\Renderer;
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Renders the player as an `<amp-iframe>` so it survives the AMP validator.
18 *
19 * @since 7.0.0 Refactored to BeyondWords namespace with snake_case methods.
20 */
21 class Amp extends Base {
22
23 /**
24 * Whether the AMP renderer applies to this request.
25 *
26 * @param \WP_Post $post Post object.
27 */
28 public static function check( \WP_Post $post ): bool {
29 if ( ! \BeyondWords\Core\Utils::is_amp() ) {
30 return false;
31 }
32
33 return parent::check( $post );
34 }
35
36 /**
37 * Render the AMP player HTML.
38 *
39 * @param \WP_Post $post Post object.
40 * @param string $context Rendering context: 'auto' or 'shortcode'.
41 */
42 public static function render( \WP_Post $post, string $context = 'shortcode' ): string {
43 $project_id = \BeyondWords\Post\Meta::get_project_id( $post->ID );
44 $content_id = \BeyondWords\Post\Meta::get_content_id( $post->ID, true );
45
46 $src = sprintf( \BeyondWords\Core\Urls::get_amp_player_url(), $project_id, $content_id );
47
48 ob_start();
49 ?>
50 <amp-iframe
51 data-beyondwords-player-context="<?php echo esc_attr( $context ); ?>"
52 frameborder="0"
53 height="43"
54 layout="responsive"
55 sandbox="allow-scripts allow-same-origin allow-popups"
56 scrolling="no"
57 src="<?php echo esc_url( $src ); ?>"
58 width="295"
59 >
60 <amp-img
61 height="150"
62 layout="responsive"
63 placeholder
64 src="<?php echo esc_url( \BeyondWords\Core\Urls::get_amp_img_url() ); ?>"
65 width="643"
66 ></amp-img>
67 </amp-iframe>
68 <?php
69 return ob_get_clean();
70 }
71 }
72