List All Blocks in the Console


You can get an array of all the blocks used in your editor by going to the inspector console and using this bit of code.

wp.data.select("core/block-editor").getBlocks()
-> (7) [ {...}, {...}, {...}, {...}, {...}, {...}, {...}, ]

In this array, you can see all the attributes for each!

So, if you need to approach the editor as a whole, as in, all the blocks and not just an individual one, you can use this to traverse all the blocks currently being used.

Let us say we have a plugin that needs to make sure at least one list item has been checked on every one of its block instances.

function ourStartFunction() {
  // WP calles the subscribe function any time anything changes. 
  wp.data.subscribe(function() {
    // get all the blocks and just look at ours.
    const results = wp.data.select("core/block-editor").getBLocks().filter(function(block) {
// if you return true, the curent item will be included.
      return block.name === "ourplugin/are-you-paying-attention" && block.attributes.correctAnswer == undefined
      // The new array that filter will return will be empty, unless there's a problem.  
    })
  })
}

ourStartFunction();