playerHtml() . $content; } /** * Player HTML. * * Displays JS SDK variant of the BeyondWords audio player, for both * AMP and non-AMP content. * * @SuppressWarnings(PHPMD.NPathComplexity) * * @param WP_Post $post WordPress Post. * * @since 3.0.0 * @since 3.1.0 Added _doing_it_wrong deprecation warnings * * @return string */ public function playerHtml($post = false) { if (! ($post instanceof \WP_Post)) { $post = get_post($post); } if (! $post) { return ''; } if (! $this->isPlayerEnabled($post)) { return ''; } $projectId = PostMetaUtils::getProjectId($post->ID); if (! $projectId) { return ''; } $podcastId = PostMetaUtils::getContentId($post->ID); if (! $podcastId) { return ''; } // AMP or JS Player? if ($this->useAmpPlayer()) { $html = $this->ampPlayerHtml($post->ID, $projectId, $podcastId); } else { $html = $this->jsPlayerHtml($post->ID, $projectId, $podcastId); } return $html; } /** * Has custom player? * * Checks the post content to see whether a custom player has been added. * * @param int $postId WordPress Post ID. * * @since 3.2.0 * * @return boolean */ public function hasCustomPlayer($postId) { $content = get_the_content(null, false, $postId); $crawler = new Crawler($content); return count($crawler->filterXPath('//div[@data-beyondwords-player="true"]')) > 0; } /** * JS Player HTML. * * Displays the HTML required for the JS player. * * @param int $postId WordPress Post ID. * @param int $projectId BeyondWords Project ID. * @param int $podcastId BeyondWords Podcast ID. * * @since 3.0.0 * @since 3.1.0 Added speechkit_js_player_html filter * * @return string */ public function jsPlayerHtml($postId, $projectId, $podcastId) { $html = ''; if (! $this->hasCustomPlayer($postId)) { $html .= '
'; } /** * Filters the HTML of the BeyondWords Player. * * @since 4.0.0 * * @param string $html The HTML for the JS audio player. The audio player JavaScript may * fail to locate the target element if you remove or replace the * default contents of this parameter. * @param int $post_id WordPress post ID. * @param int $project_id BeyondWords project ID. * @param int $podcast_id BeyondWords podcast ID. */ $html = apply_filters('beyondwords_player_html', $html, $postId, $projectId, $podcastId); /** * Filters the HTML of the BeyondWords JS audio player. * * @since 3.3.3 * @deprecated Scheduled for removal in v5.0 * * @param string $html The HTML for the JS audio player. The audio player JavaScript may * fail to locate the target element if you remove or replace the * default contents of this parameter. * @param int $post_id WordPress post ID. * @param int $project_id BeyondWords project ID. * @param int $podcast_id BeyondWords podcast ID. */ $html = apply_filters('beyondwords_js_player_html', $html, $postId, $projectId, $podcastId); return $html; } /** * AMP Player HTML. * * Displays the HTML required for the AMP player. * * @param int $postId WordPress Post ID. * @param int $projectId BeyondWords Project ID. * @param int $podcastId BeyondWords Podcast ID. * * @since 3.0.0 * @since 3.1.0 Added speechkit_amp_player_html filter * * @return string */ public function ampPlayerHtml($postId, $projectId, $podcastId) { $src = sprintf(Environment::getAmpPlayerUrl(), $projectId, $podcastId); // Turn on output buffering ob_start(); ?>