Adding a plugin-more-menu-item
-
Hi everyone.
I am trying to add a plugin-more-menu-item entry to the more-menu/settings menu ⋮ in the upper right corner of the editor.
I have read this guide (as well as the rest of the block-editor handbook): https://developer.ww.wp.xz.cn/block-editor/reference-guides/slotfills/plugin-more-menu-item/
However, I keep getting a minified React error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
But as the stack-trace refers to minified code, it is rather hard to know why the React Component is not available.
I am writing my code in TypeScript and transpiling it to ES5 JS. I have tried turning minification off in my Webpack configuration – but I still get a minified error back. The error is thrown as soon as I click the three red dots in the upper right corner. I have also tried the PluginSidebar component and that actually works, but I get the same error (and a breaking editor) as soon as I click the menu/settings menu ⋮.
I have a suspicion that I am registering the item wrong in my plugin-code. I use the ‘enqueue_block_editor_assets’ hook like this:add_action('enqueue_block_editor_assets', [$this, 'add_darkmode_toggle']);
and then:public function add_darkmode_toggle() { $dir = dirname(__FILE__); $script_asset_path = "$dir/public/add_darkmode_toggle.asset.php"; if (!file_exists($script_asset_path)) { throw new \Exception( 'You need to runnpm startornpm run buildinside the headless-plugin to transpile the necessary asset file' ); } $script_asset = require($script_asset_path); if (is_admin()) { //Enqueue script with dependencies and version wp_enqueue_script( 'add_darkmode_toggle', untrailingslashit(plugin_dir_url(__FILE__)) . '/public/add_darkmode_toggle.js', $script_asset['dependencies'], $script_asset['version'], ); } }I use a class for my plugin – so this is why I refer to the function using the “this” keyword. Any tips on debugging?
Is it correctly understood that all WordPress dependencies are accessible inside WordPress? I use the packages:@wordpress/plugins,@wordpress/edit-postand@wordpress/element
I am a bit lost on how to continue from here…
The topic ‘Adding a plugin-more-menu-item’ is closed to new replies.