Disable Embeds - Version 1.4.0

Version Description

Download this release

Release Info

Developer swissspidy
Plugin Icon Disable Embeds
Version 1.4.0
Comparing to
See all releases

Code changes from version 1.3.0 to 1.4.0

Files changed (4) hide show
  1. composer.json +0 -7
  2. disable-embeds.php +82 -5
  3. js/editor.js +1 -0
  4. README.md → readme.txt +16 -9
composer.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "name": "swissspidy/disable-embeds",
3
- "description": "Don't like the enhanced embeds in WordPress 4.4? Easily disable the feature using this plugin.",
4
- "version": "1.3.0",
5
- "type": "wordpress-plugin",
6
- "license": "GPL-2.0+"
7
- }
 
 
 
 
 
 
 
disable-embeds.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Disable Embeds
4
  * Description: Don't like the enhanced embeds in WordPress 4.4? Easily disable the feature using this plugin.
5
- * Version: 1.3.0
6
  * Author: Pascal Birchler
7
  * Author URI: https://pascalbirchler.com
8
  * License: GPLv2+
@@ -16,6 +16,7 @@
16
  * - Removes the needed query vars.
17
  * - Disables oEmbed discovery.
18
  * - Completely removes the related JavaScript.
 
19
  *
20
  * @since 1.0.0
21
  */
@@ -28,8 +29,11 @@ function disable_embeds_init() {
28
  'embed',
29
  ) );
30
 
31
- // Remove the REST API endpoint.
32
- remove_action( 'rest_api_init', 'wp_oembed_register_route' );
 
 
 
33
 
34
  // Turn off oEmbed auto discovery.
35
  add_filter( 'embed_oembed_discover', '__return_false' );
@@ -49,6 +53,12 @@ function disable_embeds_init() {
49
 
50
  // Remove filter of the oEmbed result before any HTTP requests are made.
51
  remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
 
 
 
 
 
 
52
  }
53
 
54
  add_action( 'init', 'disable_embeds_init', 9999 );
@@ -90,7 +100,7 @@ function disable_embeds_rewrites( $rules ) {
90
  */
91
  function disable_embeds_remove_rewrite_rules() {
92
  add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
93
- flush_rewrite_rules();
94
  }
95
 
96
  register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
@@ -102,7 +112,74 @@ register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
102
  */
103
  function disable_embeds_flush_rewrite_rules() {
104
  remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
105
- flush_rewrite_rules();
106
  }
107
 
108
  register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Plugin Name: Disable Embeds
4
  * Description: Don't like the enhanced embeds in WordPress 4.4? Easily disable the feature using this plugin.
5
+ * Version: 1.4.0
6
  * Author: Pascal Birchler
7
  * Author URI: https://pascalbirchler.com
8
  * License: GPLv2+
16
  * - Removes the needed query vars.
17
  * - Disables oEmbed discovery.
18
  * - Completely removes the related JavaScript.
19
+ * - Disables the core-embed/wordpress block type (WordPress 5.0+)
20
  *
21
  * @since 1.0.0
22
  */
29
  'embed',
30
  ) );
31
 
32
+ // Remove the oembed/1.0/embed REST route.
33
+ add_filter( 'rest_endpoints', 'disable_embeds_remove_embed_endpoint' );
34
+
35
+ // Disable handling of internal embeds in oembed/1.0/proxy REST route.
36
+ add_filter( 'oembed_response_data', 'disable_embeds_filter_oembed_response_data' );
37
 
38
  // Turn off oEmbed auto discovery.
39
  add_filter( 'embed_oembed_discover', '__return_false' );
53
 
54
  // Remove filter of the oEmbed result before any HTTP requests are made.
55
  remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
56
+
57
+ // Load block editor JavaScript.
58
+ add_action( 'enqueue_block_editor_assets', 'disable_embeds_enqueue_block_editor_assets' );
59
+
60
+ // Remove wp-embed dependency of wp-edit-post script handle.
61
+ add_action( 'wp_default_scripts', 'disable_embeds_remove_script_dependencies' );
62
  }
63
 
64
  add_action( 'init', 'disable_embeds_init', 9999 );
100
  */
101
  function disable_embeds_remove_rewrite_rules() {
102
  add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
103
+ flush_rewrite_rules( false );
104
  }
105
 
106
  register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
112
  */
113
  function disable_embeds_flush_rewrite_rules() {
114
  remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
115
+ flush_rewrite_rules( false );
116
  }
117
 
118
  register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );
119
+
120
+ /**
121
+ * Removes the oembed/1.0/embed REST route.
122
+ *
123
+ * @since 1.4.0
124
+ *
125
+ * @param array $endpoints Registered REST API endpoints.
126
+ * @return array Filtered REST API endpoints.
127
+ */
128
+ function disable_embeds_remove_embed_endpoint( $endpoints ) {
129
+ unset( $endpoints['/oembed/1.0/embed'] );
130
+
131
+ return $endpoints;
132
+ }
133
+
134
+ /**
135
+ * Disables sending internal oEmbed response data in proxy endpoint.
136
+ *
137
+ * @since 1.4.0
138
+ *
139
+ * @param array $data The response data.
140
+ * @return array|false Response data or false if in a REST API context.
141
+ */
142
+ function disable_embeds_filter_oembed_response_data( $data ) {
143
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
144
+ return false;
145
+ }
146
+
147
+ return $data;
148
+ }
149
+
150
+ /**
151
+ * Enqueues JavaScript for the block editor.
152
+ *
153
+ * @since 1.4.0
154
+ *
155
+ * This is used to unregister the `core-embed/wordpress` block type.
156
+ */
157
+ function disable_embeds_enqueue_block_editor_assets() {
158
+ wp_enqueue_script(
159
+ 'disable-embeds',
160
+ plugins_url( 'js/editor.js', __FILE__ ),
161
+ array(
162
+ 'wp-edit-post',
163
+ 'wp-editor',
164
+ 'wp-dom',
165
+ ),
166
+ '20181202',
167
+ true
168
+ );
169
+ }
170
+
171
+ /**
172
+ * Removes wp-embed dependency of core packages.
173
+ *
174
+ * @since 1.4.0
175
+ *
176
+ * @param \WP_Scripts $scripts WP_Scripts instance, passed by reference.
177
+ */
178
+ function disable_embeds_remove_script_dependencies( $scripts ) {
179
+ if ( ! empty( $scripts->registered['wp-edit-post'] ) ) {
180
+ $scripts->registered['wp-edit-post']->deps = array_diff(
181
+ $scripts->registered['wp-edit-post']->deps,
182
+ array( 'wp-embed' )
183
+ );
184
+ }
185
+ }
js/editor.js ADDED
@@ -0,0 +1 @@
 
1
+ this.DisableEmbeds=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.wp.domReady}()},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1);n.n(o)()(function(){Object(r.unregisterBlockType)("core-embed/wordpress")})}]);
README.md → readme.txt RENAMED
@@ -1,12 +1,12 @@
1
  # Disable Embeds #
2
- Contributors: swissspidy
3
- Donate link: https://pascalbirchler.com
4
- Tags: embed, embeds, oembed
5
- Requires at least: 4.4
6
- Tested up to: 4.9
7
- Stable tag: trunk
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Don’t like the enhanced embeds in WordPress 4.4? Easily disable the feature using this plugin.
12
 
@@ -17,6 +17,7 @@ What this plugin does:
17
  * Prevents others from embedding your site.
18
  * Prevents you from embedding other non-whitelisted sites.
19
  * Disables all JavaScript related to the feature.
 
20
 
21
  Just activate the plugin and you’re good to go.
22
 
@@ -45,6 +46,9 @@ Sorry, there are no screenshots for this plugin! Everything is done behind the s
45
 
46
  ## Changelog ##
47
 
 
 
 
48
  ### 1.3.0 ###
49
  * Updated against WordPress 4.6 Beta 2
50
  * Removes a new embeds filter introduced in WordPress 4.5.3
@@ -61,6 +65,9 @@ Sorry, there are no screenshots for this plugin! Everything is done behind the s
61
 
62
  ## Upgrade Notice ##
63
 
 
 
 
64
  ### 1.3.0 ###
65
  Removes a new embeds filter that was added in WordPress 4.5.3
66
 
@@ -71,4 +78,4 @@ Now removes all embeds rewrite rules on plugin activation.
71
  Updated against WordPress 4.4 Beta 2.
72
 
73
  ### 1.0.0 ###
74
- Initial release.
1
  # Disable Embeds #
2
+ Contributors: swissspidy
3
+ Donate link: https://pascalbirchler.com
4
+ Tags: embed, embeds, oembed
5
+ Requires at least: 4.4
6
+ Tested up to: 5.0
7
+ Stable tag: 1.4.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Don’t like the enhanced embeds in WordPress 4.4? Easily disable the feature using this plugin.
12
 
17
  * Prevents others from embedding your site.
18
  * Prevents you from embedding other non-whitelisted sites.
19
  * Disables all JavaScript related to the feature.
20
+ * Removes support for the WordPress embed block in the new block editor.
21
 
22
  Just activate the plugin and you’re good to go.
23
 
46
 
47
  ## Changelog ##
48
 
49
+ ### 1.4.0 ###
50
+ * Updated against WordPress 5.0
51
+
52
  ### 1.3.0 ###
53
  * Updated against WordPress 4.6 Beta 2
54
  * Removes a new embeds filter introduced in WordPress 4.5.3
65
 
66
  ## Upgrade Notice ##
67
 
68
+ ### 1.4.0 ###
69
+ Adds support for WordPress 5.0 and its new block editor.
70
+
71
  ### 1.3.0 ###
72
  Removes a new embeds filter that was added in WordPress 4.5.3
73
 
78
  Updated against WordPress 4.4 Beta 2.
79
 
80
  ### 1.0.0 ###
81
+ Initial release.