| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\integration; |
| 3 |
|
| 4 |
use epiphyt\Embed_Privacy\embed\Replacement; |
| 5 |
use epiphyt\Embed_Privacy\Embed_Privacy; |
| 6 |
|
| 7 |
/** |
| 8 |
* Instagram integration for Embed Privacy. |
| 9 |
* |
| 10 |
* @author Epiphyt |
| 11 |
* @license GPL2 |
| 12 |
* @package epiphyt\Embed_Privacy |
| 13 |
* @since 1.11.0 |
| 14 |
*/ |
| 15 |
final class Instagram { |
| 16 |
/** |
| 17 |
* Initialize functionality. |
| 18 |
*/ |
| 19 |
public static function init() { |
| 20 |
\add_filter( 'embed_privacy_overlay_replaced_content', [ self::class, 'replace_posts' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Replace Instagram posts. |
| 25 |
* |
| 26 |
* @param string $content Current replaced content |
| 27 |
* @return string Updated replaced content |
| 28 |
*/ |
| 29 |
public static function replace_posts( $content ) { |
| 30 |
if ( ! \str_contains( $content, 'instagram.com/embed.js' ) ) { |
| 31 |
return $content; |
| 32 |
} |
| 33 |
|
| 34 |
\remove_filter( 'embed_privacy_overlay_replaced_content', [ self::class, 'replace_posts' ] ); |
| 35 |
|
| 36 |
$attributes = [ |
| 37 |
'additional_checks' => [ |
| 38 |
[ |
| 39 |
'attribute' => 'class', |
| 40 |
'compare' => '===', |
| 41 |
'type' => 'attribute', |
| 42 |
'value' => 'instagram-media', |
| 43 |
], |
| 44 |
], |
| 45 |
'assets' => [], |
| 46 |
'elements' => [ |
| 47 |
'blockquote', |
| 48 |
], |
| 49 |
'regex' => '/<blockquote class="instagram-media"([^>]+)>([\S\s]*?)<\/blockquote>\s?<script async src="\/\/www\.instagram\.com\/embed\.js"><\/script>/', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 50 |
]; |
| 51 |
$overlay = new Replacement( $content ); |
| 52 |
$new_content = $overlay->get( $attributes ); |
| 53 |
|
| 54 |
if ( $new_content !== $content ) { |
| 55 |
Embed_Privacy::get_instance()->has_embed = true; |
| 56 |
$content = $new_content; |
| 57 |
} |
| 58 |
|
| 59 |
return $content; |
| 60 |
} |
| 61 |
} |
| 62 |
|