Search code examples
javascriptwordpressreactjspluginswordpress-gutenberg

Wordpress plugin access method in UI


How can I trigger particular method in React component of Wordpress plugin. E.g. Gutenberg?

Say, we have a wordpress plugin with React UI (e.g. Gutenberg) It has a component. I need somehow to access/import this component and trigger it's method. How can I do that?


Solution

  • in UI of a wordpress editor I have a namespace which can be accessible with a short

    wp.

    syntax and allows to work with multiple method described in official documentation. In my case I did need to access it like so:

    wp.data.select('core/block-editor').getBlockAttributes

    This is also described in official docs: https://developer.wordpress.org/block-editor/data/data-core-block-editor/