Missing Block ID and Input ID, Incorrect ID.
-
Hi,
There are 2 issues with ID’s.
First:
Copy block is really cool feature in Gutenberg, and clients/users are using this really often.
The copied block is having the exactly same ID as the original block – which is an issue ofc. The new block won’t open, won’t work.I’d suggest to generate ID based on the content and add timestamp during block creation or smth.
Second:
Missing ID, This one I’m not sure how my client was able to do. But many blocks are missing the ID so they are not working.
I’d suggest to check if the ID exists during block render (backend) and re-generate it if it is missing. And during frontend render it would be nice to have this too checked – It is really annoying now for me to go throughout tens of pages and checking each FAQ.
I did for example to cover all block on frontend:
/**
* Fix the issue with plugin, some time plugin fails to add the id attribute to the FAQ block.
*
* @param string $block_content
* @param array $block
* @param \WP_Block $instance
* @return string
*/
function filter_faq_meow_block_items_id( string $block_content, array $block, \WP_Block $instance ) {
$random_id = \substr( \md5( \uniqid() ), 0, 8 );
$block_content = \str_replace(
[ 'id=""', '<input ', '<input id="" ', '<input id= ', '<input id=' ],
[ 'id="' . $random_id . '"', '<input id="' . $random_id . '" ', '<input id="' . $random_id . '" ', '<input id="' . $random_id . '" ', '<input id="' . $random_id . '" ' ],
$block_content
);
$block_content = \str_replace(
[ 'for=""', '<label ', '<label for="" ', '<label for= ', '<label for='],
[ 'for="' . $random_id . '"', '<label for="' . $random_id . '" ', '<label for="' . $random_id . '" ', '<label for="' . $random_id . '" ', '<label for="' . $random_id . '" ' ],
$block_content
);
return $block_content;
}
\add_filter( 'render_block_meowapps/faq', __NAMESPACE__ . '\\filter_faq_meow_block_items_id', 10, 3 );
- You must be logged in to reply to this topic.