: 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 Giphy embeds.
* @subpackage EmbedPress/Providers
* @author EmbedPress <help@embedpress.com>
* @copyright Copyright (C) 2023 WPDeveloper. All rights reserved.
* @license GPLv3 or later
class Giphy extends ProviderAdapter implements ProviderInterface
* The regex which identifies Giphy URLs.
private $urlRegexPattern = '~http[s]?:\/\/(?:www\.)?giphy\.com\/(?:gifs|clips)\/(?:[a-zA-Z0-9\-]+\-)?([a-zA-Z0-9]+)(?:[^\w\-]|$)|i.giphy\.com\/([a-zA-Z0-9]+)(\.gif)~';
* Method that verifies if the embed URL belongs to Giphy.
public function validateUrl(Url $url)
$urlString = (string) $url;
if (preg_match($this->urlRegexPattern, $urlString, $matches)) {
// Check which group matched and extract the GIF ID
$gifId = isset($matches[1]) && !empty($matches[1]) ? $matches[1] : (isset($matches[2]) ? $matches[2] : null);
* This method fakes an Oembed response.
public function fakeResponse()
if (preg_match($this->urlRegexPattern, $url, $matches)) {
$gifId = count($matches) > 3 && strtolower($matches[3]) === ".gif" ? $matches[2] : $matches[1];
$width = isset($this->config['maxwidth']) ? $this->config['maxwidth'] : 400;
$height = isset($this->config['maxheight']) ? $this->config['maxheight'] : 400;
$html = '<a href="https://giphy.com/gifs/' . $gifId . '">' .
'<img src="https://media.giphy.com/media/' . $gifId . '/giphy.gif" alt="" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '">' .
'provider_name' => 'Giphy',
'provider_url' => 'https://giphy.com',
/** inline @inheritDoc */
public function modifyResponse(array $response = [])
return $this->fakeResponse();