Let's say I want to monitor all the editor blocks. In the standard editor (5.2.2) I can just select the blocks with e.g. $("div.wp-block"). Will this work across plugins etc or will some plugins alter the editor blocks class/id?
In other words, are there plugins/page builders, etc that alter the DOM structure so that the blocks do not have the "wp-block" class?
I am worried that if the user, for example, uses a plugin that alters how the editor looks/works will break this jQuery select for me?
If using jQuery selectors to get the editor block will not work in some cases, what would be a better approach to do this? I just need to monitor all text users enter in the editor blocks and match to certain keywords.
Let's say I want to monitor all the editor blocks. In the standard editor (5.2.2) I can just select the blocks with e.g. $("div.wp-block"). Will this work across plugins etc or will some plugins alter the editor blocks class/id?
In other words, are there plugins/page builders, etc that alter the DOM structure so that the blocks do not have the "wp-block" class?
I am worried that if the user, for example, uses a plugin that alters how the editor looks/works will break this jQuery select for me?
If using jQuery selectors to get the editor block will not work in some cases, what would be a better approach to do this? I just need to monitor all text users enter in the editor blocks and match to certain keywords.
Share Improve this question edited Jul 19, 2019 at 10:48 Andreas Toresäter asked Jul 17, 2019 at 14:47 Andreas ToresäterAndreas Toresäter 636 bronze badges 4 |1 Answer
Reset to default 0You probably shouldn't use jQuery
with gutenberg block-editor. Instead, use api access like:
wp.data.select("core").XXXXXXX()
wp.data.select("core/editor").XXXXXXX()
where you should replace xxx
with desired functions. You can list them with console.log(wp.blocks.getBlockTypes());
while on block-editor page.
wp-block
class so that might not be reliable – Welcher Commented Jul 19, 2019 at 16:56