-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisable-emojis.php
102 lines (85 loc) · 4.07 KB
/
disable-emojis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
Plugin Name: Disable Emojis
Plugin URI: https://www.littlebizzy.com/plugins/disable-emojis
Description: Disables emoji scripts and styles
Version: 2.0.1
Requires PHP: 7.0
Author: LittleBizzy
Author URI: https://www.littlebizzy.com
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
GitHub Plugin URI: littlebizzy/disable-emojis
Primary Branch: master
*/
// prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// disable wordpress.org updates for this plugin
add_filter( 'gu_override_dot_org', function( $overrides ) {
$overrides[] = 'disable-emojis/disable-emojis.php';
return $overrides;
}, 999 );
// disable emoji scripts in all relevant contexts
add_action( 'init', function() {
// remove emoji actions from the front-end
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles', 10 );
// remove emoji actions from the admin area
remove_action( 'admin_print_scripts', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_styles', 'print_emoji_styles', 10 );
// remove emoji actions from embedded content
remove_action( 'embed_head', 'print_emoji_detection_script', 7 );
remove_action( 'embed_head', 'print_emoji_styles', 10 );
// disable emojis in emails
remove_action( 'wp_mail', 'wp_staticize_emoji_for_email', 10 );
// disable emojis in RSS feeds
remove_action( 'the_content_feed', 'wp_staticize_emoji', 10 );
remove_action( 'comment_text_rss', 'wp_staticize_emoji', 10 );
// remove emoji support from TinyMCE (classic editor)
add_filter( 'tiny_mce_plugins', function( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, [ 'wpemoji' ] );
}
return $plugins;
}, 10 );
// disable DNS prefetch for emojis
add_filter( 'emoji_svg_url', '__return_false', 10 );
// disable emoji scripts for XML-RPC requests (safety net)
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles', 10 );
}
// disable emoji scripts for REST API requests (safety net)
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles', 10 );
}
// remove emojis in post titles (including RSS feed titles)
add_filter( 'the_title', function( $title ) {
$emoji_regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F1E6}-\x{1F1FF}\x{1F900}-\x{1F9FF}\x{1FA70}-\x{1FAFF}]/u';
return preg_replace( $emoji_regex, '', $title );
}, 10 );
// remove emojis in post content
add_filter( 'the_content', function( $content ) {
$emoji_regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F1E6}-\x{1F1FF}\x{1F900}-\x{1F9FF}\x{1FA70}-\x{1FAFF}]/u';
return preg_replace( $emoji_regex, '', $content );
}, 10 );
// remove emojis in post excerpts
add_filter( 'the_excerpt', function( $excerpt ) {
$emoji_regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F1E6}-\x{1F1FF}\x{1F900}-\x{1F9FF}\x{1FA70}-\x{1FAFF}]/u';
return preg_replace( $emoji_regex, '', $excerpt );
}, 10 );
// remove emojis in comment content
add_filter( 'comment_text', function( $comment_text ) {
$emoji_regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F1E6}-\x{1F1FF}\x{1F900}-\x{1F9FF}\x{1FA70}-\x{1FAFF}]/u';
return preg_replace( $emoji_regex, '', $comment_text );
}, 10 );
});
// disable emoji scripts in block editor (Gutenberg)
add_action( 'enqueue_block_editor_assets', function() {
remove_action( 'admin_print_scripts', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_styles', 'print_emoji_styles', 10 );
});
// Ref: ChatGPT