There is an error at my console showing Uncaught TypeError: Cannot read property 'secret' of null at a.wp.receiveEmbedMessage (wp-embed.min.js?x59911:1)
Is there a way to fix this?
There is an error at my console showing Uncaught TypeError: Cannot read property 'secret' of null at a.wp.receiveEmbedMessage (wp-embed.min.js?x59911:1)
Is there a way to fix this?
Issue is with Wordpress wp-embed.js . Change following following code/
if ( ! ( data.secret || data.message || data.value ) ) {
to
if ( ! data || ! ( data.secret || data.message || data.value ) ) {
On line 32. It should solve the issue. Refrence : https://core.trac.wordpress.org/ticket/44832
The issue ticket (also linked by Webmatrix) suggests the following code for wp-embed.js (starting line 31).
if ( data && ! ( data.secret || data.message || data.value ) ) {
return;
}
But changing that won't matter, since the wp-embed.min.js file is the one actually used. - And since it's all on one line, it's a little harder to find the right place.
Search for the string d.secret||
to find the right part and then replace that condition check with if(d && !(d.secret||d.message||d.value))
.
I had the same issue and doing this fixed it for me, while webmatrix's code (minified) if ( !d||!(d.secret||d.message||d.value) )
didn't work for my problem.
This suggests that in my case data is in fact being passed, it just doesn't have the value that I want. Maybe there's also a problem of sometimes no data being passed at all in which case you should still add his !data ||
at the very beginning of my conditional, like so: if(!d||d && !(d.secret||d.message||d.value))
.
Note
However, note you shouldn't be editing core files usually - because it could vanish on the next update - in this situation though, the next update is very likely to contain the same or a better fix, so if it's overwritten it shouldn't matter.
It seems like the fix for that problem depends on your WordPress version. In 4.9.8
the problematic snippet in /wp-includes/js/wp-embed.min.js
looks like this:
var d=c.data;if(d.secret||d.message||d.value)if(!/[^a-zA-Z0-9]/.test(d.secret)){...}
There is no exit condition in this case, but rather a continuation condition. The following code will be executed if the previous conditions are fulfilled. Thus you need to check if the conditions are met, instead of being not met.
This worked for me:
var d=c.data;if(d&&(d.secret||d.message||d.value))...
It checks first if d
is valid (not null
) and then goes on to check if any of the following conditions are met.
Make sure to reload the page without the cache after uploading the fix. Ctrl+F5 for Chrome
and Firefox
on Windows
or Command+Shift+R for Chrome
and Firefox
on Mac
.
Modifying directly the wp-embed.min.js and it works perfectly and the console error dissapears.
Particulary, in the minified code I change this piece of code
> if(d.secret||d.message||d.value)
for this piece of code
> if(!d||!(d.secret||d.message||d.value))return;
(be carefull, the first one hasn’t got semicolon and the second one has got semicolon)
However, I do not recommend changing the WP core code in any way.
Disable Embeds in WordPress With Code
You can add the following to your WordPress theme’s functions.php file.
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;
}
Or you could also use the wp_dequeue_script function.
function my_deregister_scripts(){
wp_dequeue_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
Try to use this code. It's Working...
Thanks !