cf7-blocks
cf7-blocks copied to clipboard
Missing script dependency `wpcf7-admin-taggenerator` in block editor
cf7-blocks-integrate is missing the dependency wpcf7-admin-taggenerator which leads to the following error in the console (both in regular and isolated block editor):
Uncaught TypeError: Cannot set properties of undefined (setting 'insert')
at cf7-blocks-integrate.js?ver=080408f486f493f8b1e7:1:513
(anonymous) @ cf7-blocks-integrate.js?ver=080408f486f493f8b1e7:1
load (async)
(anonymous) @ cf7-blocks-integrate.js?ver=080408f486f493f8b1e7:1
WordPress: 6.1.1
Contact Form 7: 5.7.2
CF7 Blocks: 1.0.1
PHP: 8.0
Temporary fixed with this snippet:
add_action('init', function () {
wp_append_dependencies_to_script('cf7-blocks-integrate', [ 'wpcf7-admin-taggenerator' ]);
}, 11);
/**
* Add $deps (script handles) to the array of dependencies for $handle
* @see http://wordpress.stackexchange.com/questions/100709/add-a-script-as-a-dependency-to-a-registered-script
*
* @param string $handle Script handle for which you want to add a dependency
* @param string $deps Script handle - the dependencies you wish to add
*/
function wp_append_dependencies_to_script( $handle, $deps ) {
global $wp_scripts;
$script = $wp_scripts->query( $handle, 'registered' );
if ( ! $script ) {
return false;
}
foreach ( (array) $deps as $dep ) {
if ( ! in_array( $dep, $script->deps, true ) ) {
$script->deps[] = $dep;
}
}
return true;
}
Awesome plugin by the way, is there any chance to edit the forms directly in the regular block editor in the future?