Created
September 9, 2017 18:59
-
-
Save lgraubner/f588e20192a767bf92c55a75388a0d26 to your computer and use it in GitHub Desktop.
Plugin to disable Wordpress oembed functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Disable Emojis | |
Description: Disable Wordpress emoji functionality | |
Version: 1.0.0 | |
Author: Lars Graubner | |
Author URI: https://larsgraubner.com | |
License: MIT License | |
*/ | |
function disable_embeds_code_init() { | |
// Remove the REST API endpoint. | |
remove_action('rest_api_init', 'wp_oembed_register_route'); | |
// Turn off oEmbed auto discovery. | |
add_filter('embed_oembed_discover', '__return_false'); | |
// Don't filter oEmbed results. | |
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); | |
// Remove oEmbed discovery links. | |
remove_action('wp_head', 'wp_oembed_add_discovery_links'); | |
// Remove oEmbed-specific JavaScript from the front-end and back-end. | |
remove_action('wp_head', 'wp_oembed_add_host_js'); | |
add_filter('tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin'); | |
// Remove all embeds rewrite rules. | |
add_filter('rewrite_rules_array', 'disable_embeds_rewrites'); | |
// Remove filter of the oEmbed result before any HTTP requests are made. | |
remove_filter('pre_oembed_result', 'wp_filter_pre_oembed_result', 10); | |
} | |
add_action('init', 'disable_embeds_code_init', 9999); | |
function disable_embeds_tiny_mce_plugin($plugins) { | |
return array_diff($plugins, array('wpembed')); | |
} | |
function disable_embeds_rewrites($rules) { | |
foreach($rules as $rule => $rewrite) { | |
if(false !== strpos($rewrite, 'embed=true')) { | |
unset($rules[$rule]); | |
} | |
} | |
return $rules; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment