|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Framework\Site\Module; |
|
4
|
|
|
|
|
5
|
|
|
use Closure; |
|
6
|
|
|
use Leonidas\Framework\Module\Abstracts\Module; |
|
7
|
|
|
use Leonidas\Hooks\TargetsInitHook; |
|
8
|
|
|
|
|
9
|
|
|
class EmojiDisabler extends Module |
|
10
|
|
|
{ |
|
11
|
|
|
use TargetsInitHook; |
|
12
|
|
|
|
|
13
|
|
|
public function hook(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this->targetInitHook(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
protected function doInitAction(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->disableEmojis(); |
|
21
|
|
|
$this->disableAdminEmojis(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Disable the emoji's |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function disableEmojis(): void |
|
28
|
|
|
{ |
|
29
|
|
|
remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
30
|
|
|
remove_action('wp_print_styles', 'print_emoji_styles'); |
|
31
|
|
|
remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
32
|
|
|
remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
33
|
|
|
remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
34
|
|
|
|
|
35
|
|
|
add_filter( |
|
36
|
|
|
'tiny_mce_plugins', |
|
37
|
|
|
Closure::fromCallable([$this, 'disableEmojisTinymce']) |
|
38
|
|
|
); |
|
39
|
|
|
add_filter( |
|
40
|
|
|
'wp_resource_hints', |
|
41
|
|
|
Closure::fromCallable([$this, 'disableEmojisRemoveDnsPrefetch']), |
|
42
|
|
|
10, |
|
43
|
|
|
2 |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function disableAdminEmojis(): void |
|
48
|
|
|
{ |
|
49
|
|
|
remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
50
|
|
|
remove_action('admin_print_styles', 'print_emoji_styles'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Filter function used to remove the tinymce emoji plugin. |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function disableEmojisTinymce(array $plugins): array |
|
57
|
|
|
{ |
|
58
|
|
|
return array_diff($plugins, ['wpemoji']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Remove emoji CDN hostname from DNS prefetching hints. |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $urls URLs to print for resource hints. |
|
65
|
|
|
* @param string $relation_type The relation type the URLs are printed for. |
|
66
|
|
|
* @return array Difference betwen the two arrays. |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function disableEmojisRemoveDnsPrefetch(array $urls, string $relation_type): array |
|
69
|
|
|
{ |
|
70
|
|
|
if ('dns-prefetch' == $relation_type) { |
|
71
|
|
|
/** This filter is documented in wp-includes/formatting.php */ |
|
72
|
|
|
$emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/'); |
|
73
|
|
|
|
|
74
|
|
|
$urls = array_diff($urls, [$emoji_svg_url]); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $urls; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|