PluginProbe
Embed Privacy / 1.11.2
Embed Privacy v1.11.2
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / inc / integration / class-instagram.php

class-instagram.php in Embed Privacy 1.11.2, at inc/integration/class-instagram.php

62 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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