: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace EmbedPress\Providers;
use Embera\Provider\ProviderAdapter;
use Embera\Provider\ProviderInterface;
(defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
* Entity responsible to support Twitch embeds.
* @subpackage EmbedPress/Providers
* @author EmbedPress <help@embedpress.com>
* @copyright Copyright (C) 2023 WPDeveloper. All rights reserved.
* @license GPLv3 or later
class Twitch extends ProviderAdapter implements ProviderInterface
* The regex which identifies Twitch URLs.
private $urlRegexPattern = '/http[s]?:\/\/(?:www\.|clips\.)twitch\.tv\/([0-9a-zA-Z\-\_]+)\/?(chat\/?$|[0-9a-z\-\_]*)?/';
* Method that verifies if the embed URL belongs to Twitch.
public function validateUrl(Url $url)
return (bool) preg_match($this->urlRegexPattern, $this->url);
* Return the type of the embed based on the URL.
protected function getType($url)
if (stristr($url, 'clips.twitch.tv')) {
if (stristr($url, '/videos/')) {
if (preg_match('#/chat$#', $url)) {
* This method fakes an Oembed response.
public function fakeResponse()
$providerUrl = 'https://twitch.tv';
if (preg_match("{$this->urlRegexPattern}i", $url, $matches)) {
$channelName = $matches[1];
$type = $this->getType($url);
// Clip, channel, chat, collection, or video?
$src = 'https://clips.twitch.tv/embed?clip=' . $channelName . '&autoplay=false';
$attrs = 'scrolling="no" frameborder="0" allowfullscreen="true"';
$channelName = $matches[2];
$src = 'https://player.twitch.tv/?video=' . $channelName;
$attrs = 'scrolling="no" frameborder="0" allowfullscreen="true"';
$src = 'https://player.twitch.tv/?channel=' . $channelName;
$attrs = 'scrolling="no" frameborder="0" allowfullscreen="true"';
$src = 'http://www.twitch.tv/embed/' . $channelName . '/chat';
$attrs = 'scrolling="yes" frameborder="0" allowfullscreen="true" id="' . $channelName . '"';
$width = isset( $this->config['maxwidth']) ? $this->config['maxwidth']: 800;
$height = isset( $this->config['maxheight']) ? $this->config['maxheight']: 400;
$pars_url = wp_parse_url(get_site_url());
$src = !empty($pars_url['host'])?$src.'&parent='.$pars_url['host']:$src;
$html = '<iframe src="' . esc_url($src) . '" height="'.esc_attr($height).'" width="'.esc_attr($width).'" ' . $attrs . '></iframe>';
'content_id' => $channelName,
'provider_name' => 'Twitch',
'provider_url' => $providerUrl,
/** inline @inheritDoc */
public function modifyResponse( array $response = [])
return $this->fakeResponse();